Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!wuarchive!udel!gmiller From: gmiller@udel.edu (Gregory Miller) Newsgroups: comp.emacs Subject: Re: Filling of paragraphs in GNU emacs. Message-ID: <5074@nigel.udel.EDU> Date: 30 Nov 89 21:49:21 GMT References: <1989Nov28.222213.3721@hcr.uucp> <48910@bbn.COM> Sender: usenet@udel.EDU Reply-To: gmiller@udel.edu (Gregory Miller) Organization: University of Delaware Lines: 60 In article <48910@bbn.COM> jr@BBN.COM (John Robinson) writes: >I couldn't resist rising to this one. > >auto-fill-mode works, basically, by calling the value of >auto-fill-hook when you type a space. In text auto-fill mode (and >perhaps others), this is bound to the function do-auto-fill, which is >defined in simple.el. What is needed is a do-auto-justify, which we >attempt to define here. It makes use of the function >justify-current-line, in fill.el: > > (defun do-auto-justify () > (let ((ocol (current-column))) > (do-auto-fill) > (or (= ocol (current-column)) > (save-excursion > (forward-line -1) > (justify-current-line))))) > >Then, hang it onto auto-fill-hook: > > (setq auto-fill-hook 'do-auto-justify) > >Now if I type a bunch of stuff I should get my lines all nicely >justified with lots of snappy extra spaces inserted each time it goes >to a new line. There, does that look okay to you all? I thought so. >Nothing like interpretive systems to check out new things fast (ahem, This is great! It's exactly what I've been trying to do; and I won't even go into the ridiculous things I've tried in my vain attempts. However, it works fine interactively as John says, but when I put it in my .emacs file, it has no effect. Perhaps someone could point out where I was stupid. What I did was put the above code into my .emacs file and then invoke auto-fill-mode with M-x auto-fill-mode. Auto-fill worked fine, but the text was not justified. After wrestling with it for a while I discovered that auto-fill-hook seems to forget its value unless it's set within the scope of auto-fill-mode. This is just a guess, though. I came up with the following code, and it works, but I have a feeling that I'm going to more trouble than is necessary. By the way, I want auto-fill-mode with justification to come on by default. (setq default-major-mode 'text-mode) (defun do-auto-justify () (let ((ocol (current-column))) (do-auto-fill) (or (= ocol (current-column)) (save-excursion (forward-line -1) (justify-current-line))))) (setq text-mode-hook '(lambda () (auto-fill-mode 1) (setq auto-fill-hook 'do-auto-justify))) 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? Greg Brought to you by Super Global Mega Corp .com