home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / functions / just-curln.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  3.0 KB  |  70 lines

  1. ;From ark1!uakari.primate.wisc.edu!uflorida!mephisto!prism!hydra.gatech.edu!ashwin Wed Dec  6 08:01:23 1989
  2. ;Article 990 of comp.emacs:
  3. ;Xref: ark1 comp.emacs:990 gnu.emacs:821
  4. ;Path: ark1!uakari.primate.wisc.edu!uflorida!mephisto!prism!hydra.gatech.edu!ashwin
  5. ;>From ashwin@gatech.edu (Ashwin Ram)
  6. ;Newsgroups: comp.emacs,gnu.emacs
  7. ;Subject: Re: Filling of paragraphs in GNU emacs.
  8. ;Message-ID: <ASHWIN.89Dec5104526@pravda.gatech.edu>
  9. ;Date: 5 Dec 89 15:45:26 GMT
  10. ;References: <5074@nigel.udel.EDU> <49028@bbn.COM>
  11. ;Sender: news@prism.gatech.EDU
  12. ;Reply-To: ashwin@pravda.gatech.edu (Ashwin Ram)
  13. ;Followup-To: comp.emacs
  14. ;Organization: Georgia Tech, School of ICS
  15. ;Lines: 51
  16. ;
  17. ;In article <49028@bbn.COM> John Robinson writes:
  18. ;>   Ashwin Ram has a much improved version of justify-current-line, which
  19. ;>   is due to get into the distribution some day.  He sent it to me but I
  20. ;>   didn't keep a copy.  Perhaps he will post it here.
  21. ;
  22. ;I've gotten a couple of requests for this, so here goes:
  23. ;------------------------------------------------------------------------------
  24. ; Rewrote to spread blanks evenly across inter-word spaces in line.  Randomly
  25. ; decide whether to put extra spaces from the right or the left, to avoid
  26. ; "rivers" as far as possible.  Don't modify original interword spaces.
  27. ; Ashwin Ram, 11/16/87.
  28. (defun justify-current-line ()
  29.    "Add spaces to line point is in, so it ends at fill-column."
  30.    (interactive)
  31.    (save-excursion
  32.       (save-restriction
  33.          (beginning-of-line)
  34.          (skip-chars-forward " \t")
  35.          (let ((begin (point)))
  36.             (end-of-line)
  37.             (narrow-to-region begin (point))
  38.             (let ((blanks (- fill-column (current-column))))
  39.                (if (<= blanks 0)
  40.                    nil
  41.                    (goto-char begin)
  42.                    (let ((holes 0))
  43.                       (while (re-search-forward "[ \t][^ \t]" nil t)
  44.                          (setq holes (+ holes 1)))
  45.                       (let ((each (/ blanks holes))
  46.                             (extra (% blanks holes))
  47.                             (dir (> (random) 0))
  48.                             (count 1))
  49.                          (end-of-line)
  50.                          (while (<= count holes)
  51.                             (re-search-backward "[ \t][^ \t]")
  52.                             (let ((n 1))
  53.                                (while (<= n each)
  54.                                   (insert ? )
  55.                                   (setq n (+ n 1))))
  56.                             (if dir
  57.                                 (if (<= count extra) (insert ? ))
  58.                                 (if (>= count (- holes (- extra 1))) (insert ? )))
  59.                             (setq count (+ count 1)))))))))))
  60. ;------------------------------------------------------------------------------
  61. ;
  62. ;-- Ashwin (ashwin@gatech.edu)
  63. ;--
  64. ;Ashwin Ram
  65. ;Georgia Institute of Technology, Atlanta, Georgia 30332-0280
  66. ;UUCP:      ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!ar17
  67. ;Internet: ashwin@gatech.edu, ashwin@pravda.gatech.edu, ar17@prism.gatech.edu
  68.  
  69.  
  70.