emacs-devel
[Top][All Lists]
Advanced

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

Re: [patch] make electric-pair-mode smarter/more useful


From: Stefan Monnier
Subject: Re: [patch] make electric-pair-mode smarter/more useful
Date: Sat, 07 Dec 2013 18:07:21 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

> In a recent cleanup I did of my autopair.el library [1], I decided to
> try and add one of its core features to emacs's built-in
> `electric-pair-mode' and make it the default behaviour.

Thank you, very appreciated.

> The feature was surprisingly easy to implement using the existing
> `electric-pair-inhibit-predicate' customization variable and only
> slightly changing the semantics of the existing
> `electric-pair-skip-self` variable.

Overall, the integration looks very good, indeed.

> +(defun electric-pair--pair-of (char)
> +  "Return pair of CHAR if it has parenthesis or delimiter syntax."
> +  (and (memq (char-syntax char) '(?\( ?\) ?\" ?\$))
> +       (cdr (aref (syntax-table) char))))

Hmmm... the existing code already has such a functionality.  Can you try
and use your new function in that code, or somehow merge the two?

> +(defun electric-pair--up-list (&optional n)
> +  "Try to up-list forward as much as N lists.
> +
> +With negative N, up-list backward. N default to `point-max'.
> +
> +Return a cons of two descritions (MATCHED START END) for the
> +innermost and outermost lists that enclose point. The outermost
> +list enclosing point is either the first top-level or mismatched
> +list found by uplisting."

Could you try and use up-list, instead?
Also, you can find the START of all enclosing lists in (nth
9 (syntax-ppss)), which seems like it might be helpful here.

It would be good to try and avoid moving all the way to the START or END
of the outermost list, since that may require scanning the whole buffer,
which in pathological cases will make the feature slow.  Maybe using
syntax-ppss could help us avoid those pathological cases (since
syntax-ppss uses a cache to avoid re-scanning).


        Stefan



reply via email to

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