Article View: comp.emacs
Article #7929Fn. to line up assigment ops.
From: Paul
Date: Fri, 18 Nov 1988 10:55
Date: Fri, 18 Nov 1988 10:55
76 lines
2422 bytes
2422 bytes
The following little bit of lisp will ensure the first assignment operators
on each of the lines line up. This is part of our local formatting style
'cos it looks nice ;-)
The style of the lisp however, is atrocious. All the problems come from ==,
which looks too much like 'op='.
Enjoy.
Paul Hudson
Snail mail: Monotype ADG Email: ...!ukc!acorn!moncam!paul
Science Park, paul@moncam.co.uk
Milton Road, "Sun Microsysytems:
Cambridge, The Company is Arrogant (TM)"
CB4 4FQ
(defun align-equals (start end)
"make the first assignment operator on each line line up vertically"
(interactive "*r")
(save-excursion
(let ((indent 0))
(narrow-to-region start end)
(beginning-of-buffer)
(while (not (eobp))
(if (find-assignment)
(progn
(exchange-point-and-mark)
(setq indent (max indent (current-column)))
(delete-horizontal-space)
(insert " ")))
(forward-line 1))
(beginning-of-buffer)
(while (not (eobp))
(if (find-assignment)
(indent-to-column (1+ (- indent (- (mark) (point))))))
(forward-line 1)))
(widen)))
(defun find-assignment ()
(if (re-search-forward
"[^<>=!]=\\|\\+=\\|-=\\|\\*=\\|/=\\|&=\\||=\\|\\^=\\|<<=\\|>>="
(save-excursion (end-of-line) (point)) t)
(progn
(goto-char (match-beginning 0))
(if (looking-at ".==")
nil
(if (looking-at "\\+=\\|-=\\|\\*=\\|/=\\|&=\\||=\\|\\^=\\|<<=\\|>>=")
(set-mark (match-end 0))
(forward-char 1)
(set-mark (1+ (point))))
(delete-horizontal-space)
t))
nil))
Paul Hudson
Snail mail: Monotype ADG Email: ...!ukc!acorn!moncam!paul
Science Park, paul@moncam.co.uk
Milton Road, "Sun Microsysytems:
Cambridge, The Company is Arrogant (TM)"
CB4 4FQ
Paul Hudson
Snail mail: Monotype ADG Email: ...!ukc!acorn!moncam!paul
Science Park, paul@moncam.co.uk
Milton Road, "Sun Microsysytems:
Cambridge, The Company is Arrogant (TM)"
CB4 4FQ
Technical Details
Message-ID:
<8811181055.AA09267@marvin.moncam.uucp>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!husc6!mit-eddie!EDDIE.MIT.EDU!"PaulShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!husc6!mit-eddie!EDDIE.MIT.EDU!"Paul From: "Paul@EDDIE.MIT.EDU Newsgroups: comp.emacs Subject: Fn. to line up assigment ops. Message-ID: <8811181055.AA09267@marvin.moncam.uucp> Date: 18 Nov 88 10:55:11 GMT Sender: nessus@eddie.MIT.EDU Lines: 76