unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "João Távora" <joaotavora@gmail.com>
To: Alan Mackenzie <acm@muc.de>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>, emacs-devel@gnu.org
Subject: Re: Fixing post-self-insert-hook.
Date: Sat, 18 Sep 2021 23:55:10 +0100	[thread overview]
Message-ID: <874kahcx4h.fsf_-_@gmail.com> (raw)
In-Reply-To: <CALDnm52z_8HyqdC92nrMgzOMOOq48h2MQ4pjbROBOsdm5N_cJg@mail.gmail.com> ("João Távora"'s message of "Sat, 18 Sep 2021 22:59:13 +0100")

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



  parent reply	other threads:[~2021-09-18 22:55 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-17 19:37 Fixing post-self-insert-hook Alan Mackenzie
2021-09-17 20:04 ` Stefan Monnier
2021-09-17 20:53   ` Alan Mackenzie
2021-09-17 21:45     ` João Távora
2021-09-18  6:08       ` tomas
2021-09-18  8:44         ` João Távora
2021-09-18 14:15     ` Stefan Monnier
2021-09-18 15:56       ` Alan Mackenzie
2021-09-18 18:03         ` Stefan Monnier
     [not found]         ` <CALDnm52z_8HyqdC92nrMgzOMOOq48h2MQ4pjbROBOsdm5N_cJg@mail.gmail.com>
2021-09-18 22:55           ` João Távora [this message]
2021-09-19 12:14             ` Alan Mackenzie
2021-09-19 12:36               ` João Távora
2021-09-19 12:59               ` Stefan Monnier
2021-09-19 14:57                 ` Alan Mackenzie
2021-09-19 20:20                   ` Stefan Monnier
2021-09-17 20:15 ` João Távora
2021-09-17 20:35   ` Alan Mackenzie
2021-09-17 20:48     ` João Távora
2021-09-18  5:59     ` Eli Zaretskii
2021-09-18  9:41       ` Alan Mackenzie
2021-09-18  5:50 ` Eli Zaretskii
2021-09-18  9:57   ` Alan Mackenzie
2021-09-18 11:04     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874kahcx4h.fsf_-_@gmail.com \
    --to=joaotavora@gmail.com \
    --cc=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).