Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker!mit-eddie!bbn!gateway!BBN.COM!jr From: jr@BBN.COM (John Robinson) Newsgroups: comp.emacs Subject: Re: Filling of paragraphs in GNU emacs. Message-ID: <49028@bbn.COM> Date: 1 Dec 89 17:00:53 GMT References: <5074@nigel.udel.EDU> Sender: news@bbn.COM Organization: BBN news/mail gateway Lines: 57 > Maybe someone can gently point out a more reasonable approach. I'm > new at this stuff. Also, why is it that auto-fill-hook can only be > set from within auto-fill-mode, or so it seems? What you have is perfectly reasonable, though cascading hooks in that way seems a bit bizarre. If you look up the definition of (auto-fill-mode), it turns out that turning on auto-fill-mode is simply a matter of hanging the right function on the hook. So what we want is a new minor mode (this is simply auto-fill-mode, modified): (defun auto-justify-mode (arg) "Toggle auto-justify mode. With arg, turn auto-justify mode on iff arg is positive. In auto-justify mode, inserting a space at a column beyond fill-column automatically breaks the line at a previous space, and the line up to that point is filled out with spaces to fill-column." (interactive "P") (prog1 (setq auto-fill-hook (if (if (null arg) (not auto-fill-hook) (> (prefix-numeric-value arg) 0)) 'do-auto-justify nil)) ;; update mode-line (set-buffer-modified-p (buffer-modified-p)))) Then you could: (setq text-mode-hook '(lambda () (auto-justify-mode 1))) The only further problem here is that the modeline will still say "Fill" even though you are now in "Justify" minor mode. The way minor-mode-alist is set up isn't quite right. You could add the pair ('auto-just-flag " Justify") to the minor-mode-alist, say right after the pair ('auto-fill-hook " Fill"), and then set this flag in the function above by (setq auto-just-flag auto-fill-hook) just before the mode-line hack. Then you would see both minor modes on the modeline. You would also need a (make-variable-buffer-local 'auto-just-flag). Or modify auto-fill-mode to set a separate auto-fill-flag for the minor-mode-alist to watch, and modify minor-mode-alist accordingly. To me "Justify" would imply "Fill", so this would save some mode-line space. Remainder left as an exercise to the readership. 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. /jr, nee John Robinson Life did not take over the globe by combat, jr@bbn.com or bbn!jr but by networking -- Lynn Margulis Brought to you by Super Global Mega Corp .com