From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tom Tromey Newsgroups: gmane.emacs.devel Subject: Re: Smie-auto-fill =?utf-8?Q?doesn=E2=80=99t?= respect comment-auto-fill-only-comments Date: Sun, 21 May 2017 10:43:53 -0600 Message-ID: <87r2zidut2.fsf@bapiya> References: <87o9vdj0s5.fsf@tromey.com> <87mvavw0h5.fsf@pokyo> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1495385073 13228 195.159.176.226 (21 May 2017 16:44:33 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 21 May 2017 16:44:33 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun May 21 18:44:30 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dCTy0-0003Id-V1 for ged-emacs-devel@m.gmane.org; Sun, 21 May 2017 18:44:29 +0200 Original-Received: from localhost ([::1]:38742 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dCTy4-0002Ru-Nw for ged-emacs-devel@m.gmane.org; Sun, 21 May 2017 12:44:32 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dCTxp-0002R5-BA for emacs-devel@gnu.org; Sun, 21 May 2017 12:44:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dCTxl-0003GG-VM for emacs-devel@gnu.org; Sun, 21 May 2017 12:44:17 -0400 Original-Received: from gproxy1-pub.mail.unifiedlayer.com ([69.89.25.95]:54357 helo=outbound-ss-1812.hostmonster.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dCTxl-0003Db-Ic for emacs-devel@gnu.org; Sun, 21 May 2017 12:44:13 -0400 Original-Received: from cmgw2 (cmgw3 [10.0.90.83]) by gproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id 3424F175BB9 for ; Sun, 21 May 2017 10:43:59 -0600 (MDT) Original-Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id P4jv1v00E2f2jeq014jynQ; Sun, 21 May 2017 10:43:59 -0600 X-Authority-Analysis: v=2.2 cv=Ibz3YSia c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=tJ8p9aeEuA8A:10 a=NktFDEUEzs4_IF-oTuwA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=6VrKg6qD8E4FmOaXQRPvhf5GGdStSCZFI5mTVSmDsqM=; b=kpiKeroCF6RktMta+tje6M0YBa sGCFz3IrNdE7WExqsKuV3lUC5rUC5j33cb7g7NhJYCv4yGpfkMsMC+bNqwTcnkMaWkQ4m27bFwjoy 6+kzGsZO6/T3KGQXKyvPuOdMw; Original-Received: from c-67-176-62-53.hsd1.co.comcast.net ([67.176.62.53]:52238 helo=bapiya) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dCTxT-00080H-D4; Sun, 21 May 2017 10:43:55 -0600 In-Reply-To: (Stefan Monnier's message of "Tue, 02 May 2017 15:18:43 -0400") X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box522.bluehost.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 67.176.62.53 X-Exim-ID: 1dCTxT-00080H-D4 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: c-67-176-62-53.hsd1.co.comcast.net (bapiya) [67.176.62.53]:52238 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 69.89.25.95 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:215058 Archived-At: Stefan> Not sure what you mean: "a function that wraps (the captured value of) Stefan> normal-auto-fill-function" is exactly what add-function creates. Yeah, not sure what I was thinking either. Stefan> But maybe a cleaner patch would change the C code so it doesn't (funcall Stefan> auto-fill-function) directly but instead it calls a fixed Elisp function Stefan> which does the comment-auto-fill-only-comments check and then funcalls Stefan> auto-fill-function. This would probably make it desirable to Stefan> move auto-fill-function from buffer.c to simple.el or fill.el. Here's a patch to do this. I kept auto-fill-function in the C code because internal_self_insert checks its value, which seems like it could possibly still be a relevant optimization. It's easy enough to remove, though, if you think that's safe. Another question is whether prog-mode should set comment-auto-fill-only-comments. I tend to think so, but of course I'm already doing that in my .emacs... Let me know what you think. I'd like to push this, or one of these patches, because this is the main bug I run into in ordinary Emacs use. Tom diff --git a/lisp/simple.el b/lisp/simple.el index ea3a495..971be6b 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -7191,6 +7191,12 @@ default-indent-new-line ;; If we're not inside a comment, just try to indent. (t (indent-according-to-mode)))))) +(defun internal-auto-fill () + "The function called by `self-insert-command' to perform auto-filling." + (when (or (not comment-auto-fill-only-comments) + (nth 4 (syntax-ppss))) + (do-auto-fill))) + (defvar normal-auto-fill-function 'do-auto-fill "The function to use for `auto-fill-function' if Auto Fill mode is turned on. Some major modes set this.") diff --git a/src/cmds.c b/src/cmds.c index 51652d5..6f2db86 100644 --- a/src/cmds.c +++ b/src/cmds.c @@ -268,9 +268,10 @@ Whichever character you type to run this command is inserted. The numeric prefix argument N says how many times to repeat the insertion. Before insertion, `expand-abbrev' is executed if the inserted character does not have word syntax and the previous character in the buffer does. -After insertion, the value of `auto-fill-function' is called if the -`auto-fill-chars' table has a non-nil value for the inserted character. -At the end, it runs `post-self-insert-hook'. */) +After insertion, `internal-auto-fill' is called if +`auto-fill-function' is non-nil and if the `auto-fill-chars' table has +a non-nil value for the inserted character. At the end, it runs +`post-self-insert-hook'. */) (Lisp_Object n) { CHECK_NUMBER (n); @@ -475,7 +476,7 @@ internal_self_insert (int c, EMACS_INT n) that. Must have the newline in place already so filling and justification, if any, know where the end is going to be. */ SET_PT_BOTH (PT - 1, PT_BYTE - 1); - auto_fill_result = call0 (BVAR (current_buffer, auto_fill_function)); + auto_fill_result = call0 (Qinternal_auto_fill); /* Test PT < ZV in case the auto-fill-function is strange. */ if (c == '\n' && PT < ZV) SET_PT_BOTH (PT + 1, PT_BYTE + 1); @@ -494,6 +495,8 @@ internal_self_insert (int c, EMACS_INT n) void syms_of_cmds (void) { + DEFSYM (Qinternal_auto_fill, "internal-auto-fill"); + DEFSYM (Qundo_auto_amalgamate, "undo-auto-amalgamate"); DEFSYM (Qundo_auto__this_command_amalgamating, "undo-auto--this-command-amalgamating");