[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Emacs-diffs] scratch/fix-33794-extend-electric-layout-mode 41a9132:
From: |
Stefan Monnier |
Subject: |
Re: [Emacs-diffs] scratch/fix-33794-extend-electric-layout-mode 41a9132: Extend electric-layout-mode to handle more complex layouts |
Date: |
Fri, 28 Dec 2018 12:51:41 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
The new API looks good to me, thanks.
> (defvar electric-layout-rules nil
> "List of rules saying where to automatically insert newlines.
>
> Each rule has the form (MATCHER . WHERE) where MATCHER examines
> the state of the buffer after a certain character was inserted
> and WHERE specifies where to insert newlines.
>
> MATCHER can be a character CHAR or a boolean function of no
> arguments.
Could we pass the inserted char to the function, so the function doesn't
need to choose between looking at last-command-event, char-before, or
yet something else?
> The rule matches if the character just inserted was
> CHAR or if the function return non-nil.
^^^^^^
returns
> WHERE and can be:
^^^
> * one of the symbols `before', `after', `around', `after-stay' or
> nil;
nil doesn't need to be mentioned here, since it's a special case of
"list of the preceding symbols".
> * a list of the preceding symbols, processed in order of
> appearance to insert multiple newlines;
Great: much better than the previous approach of processing all matches.
> Instead of the (MATCHER . WHERE) form, a rule can also be just a
> function of no arguments. It should return a value compatible
> with WHERE if the rule matches, or nil if it doesn't match.
I think I'm fine with allowing MATCHER to be a function, and I'm fine with
allowing (MATCHER . WHERE) to be a function, but I don't like the idea
of allowing both, which seem a bit redundant (actually, allowing
WHERE to be a function is also somewhat redundant with those, but it's
part of the current API, so we're kind of stuck with it).
[ BTW, the one user I know of the "WHERE is a function" (sml-mode) uses
this function as a kind of predicate (it either returns `after` or
nil) so it could get the same result with a MATCHER function (or
a separate PREDICATE function).
Stefan