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: Thu, 12 Dec 2013 15:12:57 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

> +(defvar electric-layout-rules `((?\n . 
> ,#'electric-pair-newline-between-pairs-rule))

Not sure if it belongs in the default.  At least it probably shouldn't
apply to Lisp modes.

> +Each rule has the form (CHAR . WHERE) where CHAR is the char that
> +was just inserted and WHERE specifies where to insert newlines
> +and can be: nil, `before', `after', `around', `after-stay', or a
> +function of no arguments that returns one of those symbols.")

Oh, I thought the desired feature was to go from "{ }" to "{ \n } \n",
but I see now that it's indeed much simpler and `after-stay' would work
fine, yes.  But please explain in the docstring what `after-stay' means.

> +          ;; FIXME: indenting here is a no-no, but see the beginning
> +          ;; note in `electric-indent-post-self-insert-function'. We
> +          ;; have to find someway to notify that function that we
> +          ;; affected more text than just the one between `pos' and
> +          ;; `end'.
> +          (`after-stay (save-excursion
> +                         (insert "\n")
> +                         (if electric-indent-mode
> +                             (indent-according-to-mode))))

How 'bout using (let ((electric-layout-rules nil)) (newline 1 t))?

> +(defun electric-pair-newline-between-pairs-rule ()
> +  (when (and electric-pair-mode
> +             (not (eobp))
> +             (eq (save-excursion
> +                   (skip-chars-backward "\n\t ")
> +                   (char-before))
> +                 (electric-pair--pair-of (char-after))))
> +    'after-stay))

I'd rather remove the \n from skip-chars-backward, so as to be a bit
more conservative w.r.t when we use after-stay.


        Stefan



reply via email to

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