all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: joaotavora@gmail.com (João Távora)
Cc: emacs-devel@gnu.org
Subject: Re: [patch] make electric-pair-mode smarter/more useful
Date: Sun, 15 Dec 2013 22:22:31 -0500	[thread overview]
Message-ID: <jwvfvptv7ka.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87ppoxepfj.fsf@gmail.com> ("João Távora"'s message of "Sun, 15 Dec 2013 22:10:08 +0000")

>> On which part (the quoted text has at least 2 separate arguments)?
> Sorry, the second one. I like comments and strings to have prog-mode
> syntax, so I can get half-assed quote balancing there. So in my config
> I'll set `electric-pair-text-syntax-table'to `prog-mode-syntax-table'.

I'm not completely set on using text-mode-syntax-table.  I think I can
be convinced to try prog-mode-syntax-table.

> The buffer situation "())", for example, has too many closers. But, to
> help balance, you want it to *not* autopair at the beginning and *do*
> autopair at the end.

Maybe you could handle this by considering

   (- (car (syntax-ppss))
      (save-excursion (car (syntax-ppss (point-max))))

But that doesn't solve the mixed-parens issue.
      
> Your simplification for `electric-pair--looking-at-mismatched-string-p'
> was also found to fail some tests, so I kept my previous naive
> version.

It'd be useful to keep track of which ones.

>> You might give this obvious example somewhere in a comment.
> I added a section there in the middle explaining the gist of it.

Great, thanks.

>>>> So I think we need a "electric-pair-preserve-balance" flag to control
>>>> those features.
>>> OK, but I would set it to t.
>> Yes, it should default to t (unless too many people complain).
> Here too, I've kind of changed my mind :-) Balancing can already be
> turned off by customizing two variables:
>   electric-pair-inhibit-predicate
>   electric-pair-skip-self

The thing is that the two kinda go together.  Having to tweak both
together sounds like "coding" rather than "configuring".

> Lastly, if you insist, then do create `electric-pair-preserve-balance'
> variable and set the above two vars to 2 new "default" functions that
> check it and delegate to the "balance" functions appropriately. However
> i think that defeats the kind simplicity of the defcustom (though I
> don't much use `custom').

We could have the two functions check a new defcustom
electric-pair-preserve-balance and if nil fallback on the old default.

>>>>> +(defvar electric-pair-non-code-syntax-table prog-mode-syntax-table
>>>> Why prog-mode-syntax-table, rather than (say) text-mode-syntax-table?
>>> Explained above, but I don't object to text-mode-syntax-table.
>> Can you give more concrete examples?
> Explained above again.  Using prog-mode-syntax-table allows me to get
> some quote balancing in comments and strings.

This is not really an example, let alone example*S*.  Which quotes?
Why are they there?  Is it only for quotes?

> It also does when it detects it's in c-mode or c++-mode, since in my
> testing syntax-ppss is sometimes broken there (tried in in
> src/syntax.c)

I'm not really surprised, sadly, but please report it as a bug (the fix
is probably to make cc-mode use syntax-propertize-function, which is
not a quick&easy fix since cc-mode currently sets the syntax-table in
a very contorted way spread over various places and times).

>>> shoudn't newline-and-indent also call the post-self-insertion hooks?
>> I guess so, yes.
> OK.  And is the `(not (or executing-kbd-macro noninteractive))' valid?

I don't understand why you'd want (not (or executing-kbd-macro
noninteractive)) rather than any non-nil constant.  Where does this (not
(or executing-kbd-macro noninteractive)) come from?

> +(put 'electric-pair-post-self-insert-function   'priority  20)
> +(put 'electric-layout-post-self-insert-function 'priority  40)
> +(put 'electric-indent-post-self-insert-function 'priority  60)
> +(put 'blink-paren-post-self-insert-function     'priority 100)

These belong next to the corresponding functions.

Also, if you know why the order is this way, please add comments
explaining it (I do know for blink-paren-post-self-insert-function and
electric-indent-post-self-insert-function, but not sure why
electric-layout-post-self-insert-function should come after
electric-pair-post-self-insert-function rather than the opposite).

> +(defcustom electric-pair-skip-whitespace t
> +  "If non-nil skip whitespace when skipping over closing parens.
> +
> +The symbol `chomp' specifies that the skipped-over whitespace
> +should be deleted.
> +
> +Can also be a function of no arguments, in which case that function's
> +return value is considered instead."

This docstring still needs to be improved, because it still doesn't
explain what really happens.  More specifically, which whitespace
is skipped (before or after the skipped paren?).

Other than those nitpicks, feel free to install those changes,


        Stefan



  reply	other threads:[~2013-12-16  3:22 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-06 23:31 [patch] make electric-pair-mode smarter/more useful João Távora
2013-12-07  2:09 ` Leo Liu
2013-12-07  2:36 ` Dmitry Gutov
2013-12-07 21:01   ` João Távora
2013-12-07 23:16     ` Stefan Monnier
2013-12-12  3:05       ` João Távora
2013-12-12  4:29         ` Dmitry Gutov
2013-12-12 11:26           ` João Távora
2013-12-12 16:30           ` Stefan Monnier
2013-12-12 17:06             ` João Távora
2013-12-12 20:12               ` Stefan Monnier
2013-12-13  2:55               ` Dmitry Gutov
2013-12-14 15:18                 ` Stefan Monnier
2013-12-14 16:56                   ` Dmitry Gutov
2013-12-15  1:39                     ` Stefan Monnier
2013-12-16  0:35                       ` João Távora
2013-12-16  3:34                         ` Stefan Monnier
2013-12-16 19:26                           ` João Távora
2013-12-17  1:54                             ` Stefan Monnier
2013-12-18  2:43                               ` João Távora
2013-12-18 15:32                                 ` João Távora
2013-12-23 14:41                                   ` João Távora
2013-12-24 14:29                                     ` Bozhidar Batsov
2013-12-07 23:07 ` Stefan Monnier
2013-12-12  3:01   ` João Távora
2013-12-12 18:08     ` Stefan Monnier
2013-12-13  1:02       ` João Távora
2013-12-13  2:32         ` Stefan Monnier
2013-12-15 22:10           ` João Távora
2013-12-16  3:22             ` Stefan Monnier [this message]
2013-12-16 14:21               ` João Távora
2013-12-16 15:30                 ` Stefan Monnier
2013-12-16 18:40                   ` Stefan Monnier
2013-12-16 19:06                     ` João Távora
2013-12-17  1:42                       ` Stefan Monnier
     [not found]                   ` <CALDnm52AoShN891-L9=Cbng98UtYPEntzO+n_XDMmEL+UV0r-A@mail.gmail.com>
2013-12-16 19:02                     ` Fwd: " João Távora

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

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

  git send-email \
    --in-reply-to=jwvfvptv7ka.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=joaotavora@gmail.com \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.