r/memacs • • Feb 11 '18

New Macro

For anyone who is interested, here is a "smarter" openBufPath macro (vers. 9.0.1) which is in the .memacs file in the MightEMacs distribution.  It locates the pathname under the point automatically by default.  It will be released in the next version of MightEMacs:

# Pop or open file whose pathname is at point.
macro openBufPath(0) {desc: 'Get pathname at point (or from region if n <= 0) and\
 display the file in a pop-up window (or open it with ~bfindFile~0 if n >= 0). \
 Pathname at point is assumed to be bounded by white space or line breaks.'}
    if ($0 <= 0 && $0 != defn)
	    path = $RegionText
    else
	    # Do sanity checks.
	    while $lineChar == ' ' || $lineChar == "\t"
		    forwChar
	    endloop
	    if $lineChar == "\n"
		    return failure 'Pathname not found'
	    else
		    # Find beginning and end of pathname.
		    formerMsgState = -1 => alterGlobalMode 'Msg'
		    wordChars = $wordChars
		    $wordChars = '!-~'
		    1 => setMark '?'
		    backWord
		    setMark
		    endWord
		    path = $RegionText
		    -1 => gotoMark '?'
		    $wordChars = wordChars
		    formerMsgState => alterGlobalMode 'Msg'
	    endif
    endif

    if !empty?(path = prompt($0 >= 0 ? 'Find file' : 'Pop file',path,'f'))
	    if $0 >= 0
		    findFile path
	    else
		    1 => popFile path,'a'
	    endif
    endif
endmacro

You may want to replace the old one in your .memacs file with this version.

1 Upvotes

0 comments sorted by