TIP: Click on subject to list as thread! ANSI
echo: qedit
to: ALL
from: SAM MITCHELL
date: 1997-11-15 00:01:00
subject: CTags

From: Sam Mitchell 
Enclosed is a simple "ctags" macro.  It features a GotoTag at cursor, and=
a GotoTag that prompts if the tag is empty.  Feel free to change the =
key assignments to whatever you like.
/************************************************************************=
**
  Tag file should be generated with:
  ctags --excmd=3Dp *.c
 ************************************************************************=
**/
string tag_fn[] =3D "tags"
integer tag_hist, tag_buffer
/************************************************************************=
**
  quote special regx char's except ^ and $ (used by ctags)
 ************************************************************************=
**/
string proc QuoteSpecial(string st)
    string s[255]
    integer i, j
    j =3D 1
    s =3D ""
    for i =3D 1 to Length(st)
        if st[i] in '.', '|', '?', '[', ']', '*', '+', '@', '#', '{', '}'=
            s[j] =3D '\'
            j =3D j + 1
        endif
        s[j] =3D st[i]
        j =3D j + 1
    endfor
    return (s)
end
/************************************************************************=
**
  Go to the specified tag.  If tag is empty, prompt.
 ************************************************************************=
**/
proc GotoTag(string tag)
    string tag_str[255], fn[_MAXPATH_], target[255]
    if tag_buffer =3D=3D 0
        Warn("Can't find tag file:", tag_fn)
        return ()
    endif
    if tag  ""
        tag_str =3D tag
    elseif not Ask("Find tag:", tag_str, tag_hist)
        return ()
    endif
    tag_str =3D Trim(tag_str)     // don't allow empty tags
    if tag_str =3D=3D ""
        return ()
    endif
    PushPosition()
    GotoBufferId(tag_buffer)
    if not lFind(tag_str + Chr(9), "^gi")
        Warn("Tag '", tag_str, "' not found!")
        goto error_return
    endif
    if not lFind(Chr(9) + "{.*}" + Chr(9), "xc")
        Warn("Corrupt tag file - Tab after tag not found on line ", CurrL=
ine(), " in tag file.")
        goto error_return
    endif
    fn =3D GetFoundText(1)
    if not lFind("{" + Chr(9) + "/}{.*}{/}", "xc")
        Warn("Corrupt tag file - /.*/ text not found on line ", CurrLine(=
), " in tag file.")
        goto error_return
    endif
    target =3D QuoteSpecial(GetFoundText(2))
    PopPosition()
    if not EditFile(fn)
        Warn("Can't load ", fn)
        return ()
    endif
    if NumLines() =3D=3D 0
        AbandonFile()
        Warn("File ", fn, " not found!")
        return ()
    endif
    if lFind(target, "xg")
        if lFind(tag_str, "ic")
            AddHistoryStr(tag_str, tag_hist)
        endif
        ScrollToRow(5)
        return ()
    endif
    Warn("Target not found:", target)
    return ()
    error_return:
    PopPosition()
    return ()
end
proc GotoTagAtCursor()
    string s[255]
    s =3D ""
    PushBlock()
    if MarkWord()
        s =3D GetMarkedText()
    endif
    PopBlock()
    GotoTag(s)
end
/************************************************************************=
**
  Setup the history list for 'Tag:' prompt.
  Load the tags file
 ************************************************************************=
**/
proc WhenLoaded()
    integer num_tags
    if tag_hist =3D=3D 0
        tag_hist =3D GetFreeHistory("CTAGS:tag")
    endif
    if tag_buffer =3D=3D 0
        PushPosition()
        tag_buffer =3D EditBuffer(tag_fn, _HIDDEN_)
        num_tags =3D NumLines()
        PopPosition()
        if num_tags =3D=3D 0
            AbandonFile(tag_buffer)
            tag_buffer =3D 0
            Warn("Can't find tag file:", tag_fn)
        endif
    endif
end
proc WhenPurged()
    AbandonFile(tag_buffer)
end
proc main()
    GotoTag("")
end
   GotoTagAtCursor()
   GotoTag("")
---
---------------
* Origin: apana>>>>>fidonet [sawasdi.apana.org.au] (3:800/846.13)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.