[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Filling and one-letter words at end of line
From: |
Stefan Monnier |
Subject: |
Re: Filling and one-letter words at end of line |
Date: |
Mon, 08 Nov 2004 23:32:35 GMT |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux) |
> Well, I thought it was true; maybe it was some time ago, on another
> distribution with changed defaults or some add-ons; now I'm not even
> sure if it wasn't in vim long, long ago... after testing I found emacs
> isn't as smart as I thought (at least by default).
I use the code below:
(defun fill-french-nobreak-p ()
"Return nil if French style allows breaking the line at point.
This is used in `fill-nobreak-predicate' to prevent breaking lines just
after an opening paren or just before a closing paren or a punctuation
mark such as `?' or `:'. It is common in French writing to put a space
at such places, which would normally allow breaking the line at those
places."
(or (looking-at "[ \t]*[])}»?!;:-]")
(save-excursion
(skip-chars-backward " \t")
(unless (bolp)
(backward-char 1)
(or (looking-at "[([{«]")
;; Don't cut right after a single-letter word.
(and (memq (preceding-char) '(?\t ?\ ))
(eq (char-syntax (following-char)) ?w)))))))
(add-hook 'fill-nobreak-predicate 'fill-french-nobreak-p)
Stefan
PS: Another one I use is:
(defun fill-single-word-nobreak-p ()
"Don't break a line after the first or before the last word of a sentence."
(or (looking-at "[ \t]*\\sw+[ \t]*[.?!:][ \t]*$")
(save-excursion
(skip-chars-backward " \t")
(and (/= (skip-syntax-backward "w") 0)
(/= (skip-chars-backward " \t") 0)
(/= (skip-chars-backward ".?!:") 0)))))
(add-hook 'fill-nobreak-predicate 'fill-single-word-nobreak-p)