GNU bug report logs - #53446
29.0.50; Issues with awk-mode and electric-pair-mode

Previous Next

Package: emacs;

Reported by: Philip Kaludercic <philipk <at> posteo.net>

Date: Sat, 22 Jan 2022 13:24:02 UTC

Severity: normal

Found in version 29.0.50

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Philip Kaludercic <philipk <at> posteo.net>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 53446 <at> debbugs.gnu.org
Subject: bug#53446: 29.0.50; Issues with awk-mode and electric-pair-mode
Date: Fri, 23 Sep 2022 18:57:31 +0000
Alan Mackenzie <acm <at> muc.de> writes:

> Hello, Philip.
>
> Sorry I missed this bug in January.

No problem.

> On Fri, Sep 23, 2022 at 07:24:34 +0000, Philip Kaludercic wrote:
>> Philip Kaludercic <philipk <at> posteo.net> writes:
>
>> > Open an AWK file, and ensure that electric-pair-mode is enabled.  It
>> > seems that some character pairs like braces or parentheses are
>> > automatically paired, while others like apostrophes or double quotes are
>> > not.
>
> The reason apostrophes don't work with electric-pair-mode is that they
> are not quote characters in AWK.  :-)
>
>> I have managed to narrow this bug to the function 
>> `c-electric-pair-inhibit-predicate' that is used as
>> `electric-pair-inhibit-predicate' by cc-mode.  Specifically this check
>
>>     (not (equal (c-get-char-property last-quote 'c-fl-syn-tab) '(15)))
>
>> fails, because the macro
>
>>     (c-get-char-property last-quote 'c-fl-syn-tab)
>
>> that expands to
>
>>     (get-text-property last-quote 'c-fl-syn-tab)
>
>> where `last-quote' is the position of the last quotation mark in a
>> "logical line", evaluates to nil, not (15).  I do not understand why
>> this happens, or what the text property `c-fl-syn-tab' is supposed to
>> indicate.
>
> It happens because AWK Mode doesn't use the unterminated string
> detection code the other CC Mode modes use.  (It doesn't need to, being
> simpler.)  So, rather than temporarily storing its "working"
> syntax-table text properties, AWK just lets them be.  So, we can just
> test the syntax-table text property for being '(15) (string fence) in
> AWK Mode.
>
>> I have CC'ed Alan to see if he can help.
>
> Would you please try out the following patch, and let me know how it
> goes.  Thanks!

Yes, this does the job.

>
> diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
> index 9309a546db..679690b33c 100644
> --- a/lisp/progmodes/cc-mode.el
> +++ b/lisp/progmodes/cc-mode.el
> @@ -2714,7 +2714,10 @@ c-electric-pair-inhibit-predicate
>  			  (save-excursion
>  			    (goto-char (c-point 'eoll))
>  			    (search-backward "\"")))))
> -	(not (equal (c-get-char-property last-quote 'c-fl-syn-tab) '(15))))
> +	(not (equal
> +	      (or (c-get-char-property last-quote 'c-fl-syn-tab)
> +		  (c-get-char-property last-quote 'syntax-table)) ; for AWK
> +	      '(15))))
>      (funcall (default-value 'electric-pair-inhibit-predicate) char)))
>  
>  




This bug report was last modified 2 years and 236 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.