From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.devel Subject: Re: fill-paragraph ill designed Date: Tue, 25 Aug 2015 14:18:06 +0200 Message-ID: <87r3mrh88x.fsf@gnu.org> References: <55DC2621.4030905@online.de> <87bndvivq6.fsf@gnu.org> <55DC3A4B.6040708@online.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1440505109 15745 80.91.229.3 (25 Aug 2015 12:18:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 25 Aug 2015 12:18:29 +0000 (UTC) Cc: emacs-devel To: Andreas =?utf-8?Q?R=C3=B6hler?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Aug 25 14:18:21 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZUDBB-0004EE-EF for ged-emacs-devel@m.gmane.org; Tue, 25 Aug 2015 14:18:17 +0200 Original-Received: from localhost ([::1]:59632 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUDBA-0005nx-P5 for ged-emacs-devel@m.gmane.org; Tue, 25 Aug 2015 08:18:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:32952) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUDB6-0005np-ST for emacs-devel@gnu.org; Tue, 25 Aug 2015 08:18:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUDB1-0007wR-Sc for emacs-devel@gnu.org; Tue, 25 Aug 2015 08:18:12 -0400 Original-Received: from deliver.uni-koblenz.de ([141.26.64.15]:40490) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUDB1-0007w6-J8 for emacs-devel@gnu.org; Tue, 25 Aug 2015 08:18:07 -0400 Original-Received: from thinkpad-t440p (dhcp185.uni-koblenz.de [141.26.71.185]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by deliver.uni-koblenz.de (Postfix) with ESMTPSA id C98071A831F; Tue, 25 Aug 2015 14:18:06 +0200 (CEST) Mail-Followup-To: Andreas =?utf-8?Q?R=C3=B6hler?= , emacs-devel In-Reply-To: <55DC3A4B.6040708@online.de> ("Andreas \=\?utf-8\?Q\?R\=C3\=B6hler\?\= \=\?utf-8\?Q\?\=22's\?\= message of "Tue, 25 Aug 2015 11:50:03 +0200") User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 141.26.64.15 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:189152 Archived-At: Andreas R=C3=B6hler writes: >> So if there is an active region, `fill-paragraph' just calls >> `fill-region', and then the `fill-paragraph-function' is irrelevant. > > Yeah, but that's unhappy. Where the global fill-paragraph should know > from, what's needed in a special mode, what special modes want to do > with strings? Indeed, I had also expected that `fill-region' would call `fill-paragraph-function' on each paragraph in the region which it doesn't. But its docstring says that modes might want to use some other hook instead, e.g., `fill-forward-paragraph-function'. ,----[ C-h v fill-paragraph-function RET ] | fill-paragraph-function is a variable defined in =E2=80=98fill.el=E2=80= =99. | Its value is message-fill-paragraph | Local in buffer *unsent wide reply to Andreas R=C3=B6hler*; global value = is nil |=20 | This variable may be risky if used as a file-local variable. |=20 | Documentation: | Mode-specific function to fill a paragraph, or nil if there is none. | If the function returns nil, then =E2=80=98fill-paragraph=E2=80=99 does i= ts normal work. | A value of t means explicitly "do nothing special". | Note: This only affects =E2=80=98fill-paragraph=E2=80=99 and not =E2=80= =98fill-region=E2=80=99 | nor =E2=80=98auto-fill-mode=E2=80=99, so it is often better to use some o= ther hook, | such as =E2=80=98fill-forward-paragraph-function=E2=80=99. `---- That's its docstring: ,----[ C-h v nil RET ] | fill-forward-paragraph-function is a variable defined in =E2=80=98fill.el= =E2=80=99. | Its value is forward-paragraph |=20 | This variable may be risky if used as a file-local variable. |=20 | Documentation: | Function to move over paragraphs used by the filling code. | It is called with a single argument specifying the number of paragraphs t= o move. | Just like =E2=80=98forward-paragraph=E2=80=99, it should return the numbe= r of paragraphs | left to move. `---- Well, that actually only speaks of moving over paragraphs, not about filling while doing so. But let's try it out anyway since I could also use that in GNU AUCTeX. AUCTeX has a custom `fill-paragraph-function' named `LaTeX-fill-paragraph'. In contrast to the normal `fill-paragraph', it ensures that verbatim macros will never be wrapped, e.g., \verb|foo bar| will always stay on one line which is very important. A wrapped verbatim macro is an error. And indeed, when I mark multiple paragraphs and do M-q, I get normal filling which also wrapps inside \verb stuff and thus breaks my LaTeX code. :-( Ok, so then I tried setting `fill-forward-paragraph-function' buffer-locally to a new function: --8<---------------cut here---------------start------------->8--- (defun LaTeX-fill-forward-paragraph (arg) (LaTeX-fill-paragraph) (forward-paragraph arg)) --8<---------------cut here---------------end--------------->8--- However, that doesn't change anything. Or concretely, `fill-region' first formats the paragraphs in the region as I'd like to have it using `LaTeX-fill-paragraph' on each paragraph, but finally the (and ...) in the condition --8<---------------cut here---------------start------------->8--- (if (and (>=3D (point) initial) (< (point) end)) (setq fill-pfx (fill-region-as-paragraph (point) end justify nosqueeze)) (goto-char end)))) --8<---------------cut here---------------end--------------->8--- is true and thus `fill-region-as-paragraph' is called which messes up my correctly filled region. I can work around that by moving point out of the current paragraph after filling: --8<---------------cut here---------------start------------->8--- (defun LaTeX-fill-forward-paragraph (arg) (LaTeX-fill-paragraph) (let ((x (forward-paragraph arg))) (forward-char (if (> arg 0) 1 -1)) x)) --8<---------------cut here---------------end--------------->8--- This seems to do the trick but is really not too obvious. So now I'm curious, too. What's the right way for a mode to define its own filling rules? Bye, Tassilo