home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / misc / comm-align.el < prev    next >
Encoding:
Text File  |  1990-03-21  |  1.9 KB  |  52 lines

  1. ;From: jcgs@jung.harlqn.uucp (John Sturdy)
  2. ;Newsgroups: comp.emacs
  3. ;Subject: more formatting stuff
  4. ;Message-ID: <JCGS.89Sep11084258@jung.harlqn.uucp>
  5. ;Date: 11 Sep 89 07:42:58 GMT
  6. ;Organization: Harlequin Ltd, Cambridge, England
  7. ;Lines: 42
  8. ;
  9. ;
  10. ;Once you've got your comment paragraphs filled, with this function you
  11. ;can give them tidy box borders:
  12. ;
  13. (defun comment-straighten-right-edge ()
  14.   "Align the right-hand edges of a comment
  15. of the form (example in C):
  16. /* Here is the first line */
  17. /* of a multiple          */
  18. /* comment in your code.  */
  19. The alignment is made on the longest line of a sequence of
  20. consecutive comment lines, starting with the current line."  
  21.   (interactive)
  22.   (save-excursion
  23.     (beginning-of-line 1)
  24.     (let ((start-of-area (point))
  25.       (c-e-len (length comment-end)))
  26.       (end-of-line 1)
  27.       (let ((end-of-line (point))
  28.         (longest-line -1))
  29.     (beginning-of-line 1)
  30.     (while (search-forward comment-end end-of-line 1)
  31.       (setq longest-line (max longest-line (current-column)))
  32.       (end-of-line 2)
  33.       (setq end-of-line (point))
  34.       (beginning-of-line 1))
  35.     (beginning-of-line 0)
  36.     (setq longest-line (- longest-line c-e-len))
  37.     (while (>= (point) start-of-area)
  38.       (search-forward comment-end end-of-line 1)
  39.       (backward-char c-e-len)
  40.       (while (< (current-column) longest-line)
  41.         (insert " "))
  42.       (beginning-of-line 0))))))
  43. ;--
  44. ;__John            When asked to attend a court case, Father Moses took with him
  45. ;          a leaking jug of water. Asked about it, he said: "You ask me to judge
  46. ;               the faults of another, while mine run out like water behind me."
  47. ;
  48. ;                jcgs@uk.co.harlqn (UK notation) jcgs@harlqn.co.uk (most places)
  49. ;    ...!mcvax!ukc!harlqn!jcgs (uucp - really has more stages, but ukc knows us)
  50. ;John Sturdy                                            Telephone +44-223-872522
  51. ;                      Harlequin Ltd, Barrington Hall, Barrington, Cambridge, UK
  52.