home *** CD-ROM | disk | FTP | other *** search
- ; @(#) TAGS - microEmacs v3.9i+ macro file to emulate vi tags cmd
- ;
- ; Uses tags file from either "ctags" or "ctags -x ... > tags"
- ; MJH Oct 1989 v1.0
- ; Bound to C-X T.....
- ; CTAGS fmt
- ; tag file vi-search-cmd
- ; CTAGS -x fmt
- ; tag lnno file search-string
- ;
- ; uses !return rightout xtnsion so can treat uargs value as flag
- ; ( since counted iterations of this macro isn't sensible )
- ;
- ; Variables :
- ; %tag - tag string
- ; %line - line containg tag in tags file
- ; %i - start pos of field in line
- ; %len - len of field in line
- ; %lnno - lineno from tags file
- ; %filename - filename field from tags line
- ; %pattern - pattern field from tags line
-
- set $discmd FALSE
- 25 store-macro
-
- ; Default uargs val - look under cursor
- !if &equal $uarg 1
- !if &or &equal $curchar 20 &equal $curchar 9
- next-word
- !else
- !while &equal 0 &sindex " (},*!~t~n=" $char
- backward-character
- !endwhile
- forward-character
- ; previous-word
- !endif
- set %tag &chr $curchar
- forward-character
- !while &equal 0 &sindex " (},~t~n" $char
- set %tag &cat %tag $char
- forward-character
- !endwhile
- !else ; prompt for tagname
- set %tag @"Enter tag:"
- !if &sequal %tag ""
- write-message "%%No tag - aborted"
- !return rightout
- !endif
- !endif
-
- set %tag &cat "^" %tag
-
- ; write-message &cat &cat "tag [" %tag "]"
- ; set %wait >k
-
- set-nmark "t"
- !force find-file "tags" ; load tags file
- !if &seq $status FALSE
- write-message "%%Cannot load tags file"
- !return rightout
- !endif
- add-mode "magic" ; now search it
- beginning-of-file
- !force search-forward %tag
- !if &seq $status FALSE
- write-message &cat "%% cannot find tag" %tag
- !return rightout
- !endif
-
- set %line $line
-
- ; break sections for tag, linenumber and pattern from tags file
- next-word
- set %lnno 0
- !if ¬ &equal 0 &sindex "0123456789" $char ; ctags -x file
- set %i &add $curcol 1
- !while &equal 0 &sindex " ~t" $char ; space and tab
- forward-character
- !endwhile
- set %len &add &sub $curcol %i 1
- set %lnno &mid %line %i %len
- ;write-message &cat &cat "DBG: lnno [" %lnno "]"
- ;set %wait >k
- next-word
- set %i &add $curofs 1 ; filename
- !else
- set %i &add $curofs 1 ; filename
- !endif
-
- !while &equal 0 &sindex " ~t" $char ; not space/tab
- forward-character
- !endwhile
- ; set %len &add &sub $curcol %i 1
- set %len &add &sub $curofs %i 1
- set %filename &mid %line %i %len
- ;write-message &cat &cat "DBG: file [" %filename "]"
- ;set %wait >k
-
- next-word ; search string
- ; set %i &add $curcol 1
- set %i &add $curofs 1
- set %pattern &right %line %i
- set %i &len %pattern
- !if ¬ &equal 0 &sindex "/?" &right %pattern %i ; std tags file ??
- set %i &sub %i 1
- set %pattern &left %pattern %i
- !endif
- ;write-message &cat &cat "DBG: pattern [" %pattern "]"
- ;set %wait >k
- !if &greater &len %pattern 30
- set %pattern &left %pattern 30
- !endif
-
- ;++once have or as loading pattern need to quote any regexp metachars
-
- ; Now load file and search through it
- !force find-file %filename
- !if &seq $status FALSE
- write-message &cat "%% Cannot find file " %filename
- !return rightout
- !endif
-
- beginning-of-file
- !if &greater %lnno 0
- goto-line &sub %lnno 20
- !else
- add-mode "magic"
- !endif
-
- !force search-forward %pattern
- !if &seq $status FALSE
- write-message &cat "%%Cannot find pattern in file"
- !return rightout
- !endif
- beginning-of-line
- write-message "Tag Successful"
- set-nmark "T"
- !return rightout
- !endm
- set $discmd TRUE
- bind-to-key execute-macro-25 ^XT
-
-