[Top][All Lists]

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

Re: CC Mode and electric-pair "problem".

From: Alan Mackenzie
Subject: Re: CC Mode and electric-pair "problem".
Date: Tue, 26 Jun 2018 18:23:48 +0000
User-agent: Mutt/1.9.4 (2018-02-28)

Hello, Stefan.

On Wed, Jun 20, 2018 at 10:16:05 -0400, Stefan Monnier wrote:

[ .... ]

> If the purpose of the change is to address use cases such as Clément's:
> > Sorry for jumping in a bit late.  Does that mean that after the changed an
> > unclosed quote will only cause refontification up to the end of the line?
> > That would be a very nice improvement.  I don't use electric-pair-mode, and
> > as things currently stand inserting an unmatched quote applies
> > font-lock-string-face to the entire buffer, which is a bit annoying.

> How 'bout taking an approach that will have much fewer side-effects:
> Instead of adding the complexity at the low-level of syntax-tables
> to make strings "magically" terminate at EOL, hook into
> self-insert-command:

>     when inserting a ", add a matching " at EOL if needed, or remove
>     the " that we added at EOL earlier.

> Something like (guaranteed 100% tested, of course.  No animals were harmed):

>     (add-hook 'post-self-insert-hook
>         (lambda ()
>           (when (memq last-command-event '(?\" ?\'))
>             (save-excursion
>               (let ((pos (point))
>                     (ppss (syntax-ppss (line-end-position))))
>                 (when (and (nth 3 ppss)        ;; EOL within a string
>                            (not (nth 5 ppss))) ;; EOL not escaped
>                   (if (and (> (point) pos)
>                            (eq last-command-event (char-before)))
>                       ;; Remove extraneous unmatched " at EOL.
>                       (delete-region (1- (point)) (point))
>                     (insert last-command-event)))))))
>         'append 'local)

This is effectively electric-pair-mode, which if enabled, already
inserts two "s when you type ".

Not everybody likes electric-pair-mode.  I don't think your suggestion
is any better than mine (snipped) to which you replied.

> I used `append` to try and make it interact better with electric-pair-mode.

>         Stefan

Alan Mackenzie (Nuremberg, Germany).

reply via email to

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