[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Fixing post-self-insert-hook.
From: |
João Távora |
Subject: |
Re: Fixing post-self-insert-hook. |
Date: |
Sat, 18 Sep 2021 23:55:10 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
João Távora <joaotavora@gmail.com> writes:
> it's just done. I've asked João about such an interface over the last
> few years, now and then, but such has not yet been forthcoming.
I've made my opinion clear now and then, over the years. But here I go
again:
'electric-pair-post-self-insert-function' (aka e-p-p-s-i-f) existed
before I have laid my programmer eyes on it. It's not an internal
function, it has a defined protocol and exists to be a member of
'post-self-insert-hook'. Its purpose is -- and has always been -- to
insert aditional delimiters related to the one just typed or,
alternatively, to delete the character just inserted when it happens to
skip a closing delimiter. In Emacs, as you know, a delimiter is a well
defined thing, thanks to syntax tables. e-p-m's functionality, known
sometimes as auto-pairing, is implemented in numerous editors. I first
saw it in TextMate around 2008. In Emacs, apart from e-p-m, extensions
such as autopair, smartparens, paredit (and probably others) do the
same.
The only significant thing I did in e-p-m -- besides a boring code
refactor coordinated with then-maintainer Stefan -- was add the ability
to choose which action to take based on the information conveyed by
syntax-ppss, so that a degree of delimiter balance is maintained. As
you known, syntax-ppss, relies again on that fundamental Emacs
abstraction -- the syntax-table -- that buffers have. This works very
well in practice and is a testament to how useful simple syntax tables
are.
Nevertheless, if you want to extract things from e-p-p-s-i-f and use
them in your function, you can refactor its innards. As long as you
don't break anything (fortunately there are good tests) or convolute
elec-pair.el's code beyond recognition. Don't expect me to spend my
time any time in this effort: I won't. I think it would be a very gross
waste of time. _My_ time, at least. You may convince someone else of
that idea.
My alternative suggestion, which I've offered now and then, over the
years, is for you to study how cc-mode behaves when you bind the
delimiter keys simply to 'self-insert-command' and refrain from
re-inventing 'electric-pair-mode' inside cc-mode. I do this in my
.emacs, and I see that other users have settled on the same practice.
If you were to try that, you could theoretically arrive at the
conclusion that it is possible to do everything cc-mode does today
w.r.t. electricity via the existing interfaces of 'electric-pair-mode',
'electric-layout-mode' and 'electric-indent-mode'.
I must be honest. I don't really expect you arrive at that conclusion
or even try that experiment. That's OK, I can't force anyone to reason
the way I do. My personal hopes for C/C++/Java editing in Emacs are a
completely new major mode where syntax is handled by TreeSitter and all
the keys are bound to 'self-insert-command'. I'd bet good money that
'electric-pair-mode' is going to work there fine and with 0
configuration, like it does in all other major modes.
With best regards,
João
- Fixing post-self-insert-hook., Alan Mackenzie, 2021/09/17
- Re: Fixing post-self-insert-hook., Stefan Monnier, 2021/09/17
- Re: Fixing post-self-insert-hook., Stefan Monnier, 2021/09/18
- Re: Fixing post-self-insert-hook., Alan Mackenzie, 2021/09/18
- Re: Fixing post-self-insert-hook., Stefan Monnier, 2021/09/18
- Message not available
- Re: Fixing post-self-insert-hook.,
João Távora <=
- Re: Fixing post-self-insert-hook., Alan Mackenzie, 2021/09/19
- Re: Fixing post-self-insert-hook., João Távora, 2021/09/19
- Re: Fixing post-self-insert-hook., Stefan Monnier, 2021/09/19
- Re: Fixing post-self-insert-hook., Alan Mackenzie, 2021/09/19
- Re: Fixing post-self-insert-hook., Stefan Monnier, 2021/09/19
Re: Fixing post-self-insert-hook., João Távora, 2021/09/17