bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#50538: [PATCH v3] 28.0.50; electric-pair-mode fails to pair double q


From: Alan Mackenzie
Subject: bug#50538: [PATCH v3] 28.0.50; electric-pair-mode fails to pair double quotes in some cases in CC mode
Date: Sun, 26 Sep 2021 20:58:36 +0000

Hello, Jim.

There's one thing I'm a bit uncertain about in the patch for cc-mode.el.

On Wed, Sep 22, 2021 at 19:01:11 -0700, Jim Porter wrote:
> Ok, I've attached an updated patch that should apply cleanly on top of 
> the patches for bug#49518. The tests still pass locally for me. If 
> there's anything else that needs fixed/adjusted, just let me know.

[ .... ]

> diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
> index 8b30241449..80137590c7 100644
> --- a/lisp/progmodes/cc-mode.el
> +++ b/lisp/progmodes/cc-mode.el
> @@ -2549,18 +2549,26 @@ c-electric-pair-inhibit-predicate
 
>  At the time of call, point is just after the newly inserted CHAR.
 
> -When CHAR is \", t will be returned unless the \" is marked with
> -a string fence syntax-table text property.  For other characters,
> -the default value of `electric-pair-inhibit-predicate' is called
> -and its value returned.
> +When CHAR is \" and not within a comment, t will be returned if
> +the quotes on the current line are already balanced (i.e. if the
> +last \" is not marked with a string fence syntax-table text
> +property).  For other cases, the default value of
> +`electric-pair-inhibit-predicate' is called and its value
> +returned.
 
>  This function is the appropriate value of
>  `electric-pair-inhibit-predicate' for CC Mode modes, which mark
>  invalid strings with such a syntax table text property on the
>  opening \" and the next unescaped end of line."
> -  (if (eq char ?\")
> -      (not (equal (get-text-property (1- (point)) 'c-fl-syn-tab) '(15)))
> -    (funcall (default-value 'electric-pair-inhibit-predicate) char)))
> +  (or (and (eq char ?\")
> +        (not (memq (cadr (c-semi-pp-to-literal (1- (point)))) '(c c++)))
> +        (let ((last-quote (save-match-data
> +                            (save-excursion
> +                              (goto-char (c-point 'eoll))
> +                              (search-backward "\"")))))
> +          (not (equal (c-get-char-property last-quote 'c-fl-syn-tab)
> +                      '(15)))))
> +      (funcall (default-value 'electric-pair-inhibit-predicate) char)))
 
In the line starting (or (and (eq char ?\"), don't we still need an `if'
form?  I think that otherwise, if any of the sub-forms of the `and'
return nil, we will call (default-value
'electric-pair-inhibit-predicate), which surely isn't what we want.  If
we have a ", we want the CC Mode function to do all the work, only
delegating to the standard function when we don't have a ".

Or have I missed something?

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).





reply via email to

[Prev in Thread] Current Thread [Next in Thread]