From:	CRDGW2::CRDGW2::MRGATE::"SMTP::PREP.AI.MIT.EDU::INFO-GNU-EMACS-REQUEST"  5-DEC-1989 12:56
To:	MRGATE::"ARISIA::EVERHART"
Subj:	Re: Filling of paragraphs in GNU emacs.

Received: by life.ai.mit.edu (4.0/AI-4.10) id AA00568; Tue, 5 Dec 89 11:05:30 EST
Return-Path: <info-gnu-emacs-request@prep.ai.mit.edu>
Received: from tut.cis.ohio-state.edu by life.ai.mit.edu (4.0/AI-4.10) id AA00478; Tue, 5 Dec 89 11:00:20 EST
Received: by tut.cis.ohio-state.edu (5.61/4.891204)
	id AA10714; Tue, 5 Dec 89 10:56:34 -0500
Received: from USENET by tut.cis.ohio-state.edu with netnews
	for info-gnu-emacs@prep.ai.mit.edu (info-gnu-emacs@prep.ai.mit.edu)
	(contact usenet@tut.cis.ohio-state.edu if you have questions)
Date: 5 Dec 89 15:45:26 GMT
From: ashwin@hydra.gatech.edu  (Ashwin Ram)
Organization: Georgia Tech, School of ICS
Subject: Re: Filling of paragraphs in GNU emacs.
Message-Id: <ASHWIN.89Dec5104526@pravda.gatech.edu>
References: <5074@nigel.udel.EDU>, <49028@bbn.COM>
Sender: info-gnu-emacs-request@prep.ai.mit.edu
To: info-gnu-emacs@prep.ai.mit.edu

In article <49028@bbn.COM> John Robinson writes:
>   Ashwin Ram has a much improved version of justify-current-line, which
>   is due to get into the distribution some day.  He sent it to me but I
>   didn't keep a copy.  Perhaps he will post it here.

I've gotten a couple of requests for this, so here goes:
------------------------------------------------------------------------------
; Rewrote to spread blanks evenly across inter-word spaces in line.  Randomly
; decide whether to put extra spaces from the right or the left, to avoid
; "rivers" as far as possible.  Don't modify original interword spaces.
; Ashwin Ram, 11/16/87.
(defun justify-current-line ()
   "Add spaces to line point is in, so it ends at fill-column."
   (interactive)
   (save-excursion
      (save-restriction
         (beginning-of-line)
         (skip-chars-forward " \t")
         (let ((begin (point)))
            (end-of-line)
            (narrow-to-region begin (point))
            (let ((blanks (- fill-column (current-column))))
               (if (<= blanks 0)
                   nil
                   (goto-char begin)
                   (let ((holes 0))
                      (while (re-search-forward "[ \t][^ \t]" nil t)
                         (setq holes (+ holes 1)))
                      (let ((each (/ blanks holes))
                            (extra (% blanks holes))
                            (dir (> (random) 0))
                            (count 1))
                         (end-of-line)
                         (while (<= count holes)
                            (re-search-backward "[ \t][^ \t]")
                            (let ((n 1))
                               (while (<= n each)
                                  (insert ? )
                                  (setq n (+ n 1))))
                            (if dir
                                (if (<= count extra) (insert ? ))
                                (if (>= count (- holes (- extra 1))) (insert ? )))
                            (setq count (+ count 1)))))))))))
------------------------------------------------------------------------------

-- Ashwin (ashwin@gatech.edu)
--
Ashwin Ram
Georgia Institute of Technology, Atlanta, Georgia 30332-0280
UUCP:	  ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!ar17
Internet: ashwin@gatech.edu, ashwin@pravda.gatech.edu, ar17@prism.gatech.edu
