From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [patch] make electric-pair-mode smarter/more useful Date: Sun, 15 Dec 2013 22:22:31 -0500 Message-ID: References: <87haalh806.fsf@gmail.com> <87ppp2ydqf.fsf@gmail.com> <87r49h7eby.fsf@gmail.com> <87ppoxepfj.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1387164169 8178 80.91.229.3 (16 Dec 2013 03:22:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 16 Dec 2013 03:22:49 +0000 (UTC) Cc: emacs-devel@gnu.org To: joaotavora@gmail.com (=?windows-1252?B?Sm/jbyBU4XZvcmE=?=) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Dec 16 04:22:54 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VsOlh-0000Z5-PT for ged-emacs-devel@m.gmane.org; Mon, 16 Dec 2013 04:22:54 +0100 Original-Received: from localhost ([::1]:53554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsOlg-0002GM-NN for ged-emacs-devel@m.gmane.org; Sun, 15 Dec 2013 22:22:52 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:32923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsOlX-0002Fz-0U for emacs-devel@gnu.org; Sun, 15 Dec 2013 22:22:50 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VsOlP-0005q7-LN for emacs-devel@gnu.org; Sun, 15 Dec 2013 22:22:42 -0500 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:35537) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsOlP-0005px-G0 for emacs-devel@gnu.org; Sun, 15 Dec 2013 22:22:35 -0500 Original-Received: from fmsmemgm.homelinux.net (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.DIT.UMontreal.CA (8.14.1/8.14.1) with ESMTP id rBG3MVkq032732; Sun, 15 Dec 2013 22:22:31 -0500 Original-Received: by fmsmemgm.homelinux.net (Postfix, from userid 20848) id F18D2AE1D7; Sun, 15 Dec 2013 22:22:31 -0500 (EST) In-Reply-To: <87ppoxepfj.fsf@gmail.com> (=?windows-1252?Q?=22Jo=E3o_T=E1vo?= =?windows-1252?Q?ra=22's?= message of "Sun, 15 Dec 2013 22:10:08 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV4793=0 X-NAI-Spam-Version: 2.3.0.9362 : core <4793> : inlines <324> : streams <1091390> : uri <1624989> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.204.246.22 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:166457 Archived-At: >> 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