Re: utility to replace "end" with "end subroutine foo"



Rich Townsend wrote:

Beliavsky wrote:
Has anyone written a utility to replace "end" statements with "end
program/subroutine/function" statements as appropriate?
[...]
The f90-mode in emacs does this when you hit 'tab' over the statement.
Being emacs, I'm sure there's an (arcane, lisp) way to call the
function that does this, for the entire file.

Being Emacs, if there isn't already a way, there can be:


(defun f90-match-all-ends (beg end)
"Qualify all ENDs in the region."
(interactive "*r")
(save-excursion
(goto-char end)
(setq end (point-marker))
(goto-char beg)
(let ((f90-smart-end 'noblink))
(while (re-search-forward "^[ \t0-9]*end" end t)
(goto-char (line-beginning-position))
(skip-chars-forward " \t0-9")
(when (f90-looking-at-program-block-end)
(f90-match-end))))))

Interactively:

C-x h
M-x f90-match-all-ends


Batch-mode:

Save the above definition to a file foo.el, then

emacs -batch --no-site-file -l f90 -l ./foo.el \
--eval '(progn (find-file "code.f90")
(f90-match-all-ends (point-min) (point-max))
(write-file "code_end.f90"))'
.



Relevant Pages

  • Re: How To Learn Lisp
    ... HOW TO LEARN LISP ... it's built on a beast of a text editor called ... Emacs which is supposed to be all-powerful. ... I guess the nightmare learning curve you imply that makes it such a beast ...
    (comp.lang.lisp)
  • My interests are converging onto emacs - my emacs office, no, OS!
    ... editor, but I got interested in lisp, and what do you know, I got ... led me to be recommended ESS (Emacs Speaks Statistics) for R, ... I'm also getting again into chess and that found me Emacs Chess. ... emacs :-) - and regular expressions already anyway so perl, ...
    (comp.unix.programmer)
  • Re: Why Lisp instead of Scheme?
    ... > I think many Lisp users are blinded to how hard Emacs is. ... from teaching all kinds of people to use Emacs over the ... Today, people have many more preconceptions of what an editor is, ... IDE functionality (eg. accessing the compiler and debugger) ...
    (comp.lang.lisp)
  • Re: IDE for Windows
    ... I'm very new to Lisp too, and while I don't have any really ... no free editor I found so far passes both tests. ... If all you think is good about Emacs is that it "indents Lisp ... In fact many Windows programmers put in more time learning editors ...
    (comp.lang.lisp)
  • NYC LOCAL: Wednesday 10 December 2003 GNUbies: Bruce Ingalls will introduce Emacs and Jay Sulzberger
    ... first Lisp interpreter, and how Elisp is more like first interpreter Lisp ... 2003 Bruce Ingalls and Jay Sulzberger: ... Editing with Emacs ... meeting jointly speaking on the the editor Emacs: ...
    (comp.lang.lisp)