From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: CC Mode and electric-pair "problem". Date: Tue, 26 Jun 2018 18:23:48 +0000 Message-ID: <20180626182348.GB4464@ACM> References: <20180531123747.GA24752@ACM> <20180617201351.GA4580@ACM> <20180618103654.GA9771@ACM> <20180618154227.GB3973@ACM> <20180619050244.GA3946@ACM> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1530037918 20703 195.159.176.226 (26 Jun 2018 18:31:58 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 26 Jun 2018 18:31:58 +0000 (UTC) User-Agent: Mutt/1.9.4 (2018-02-28) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 26 20:31:54 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fXskr-0005GU-1i for ged-emacs-devel@m.gmane.org; Tue, 26 Jun 2018 20:31:53 +0200 Original-Received: from localhost ([::1]:54514 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXsmy-0005am-D9 for ged-emacs-devel@m.gmane.org; Tue, 26 Jun 2018 14:34:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57715) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXslO-0005ZH-54 for emacs-devel@gnu.org; Tue, 26 Jun 2018 14:32:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fXslK-0007Dm-30 for emacs-devel@gnu.org; Tue, 26 Jun 2018 14:32:26 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:55392 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1fXslJ-0007CR-Ml for emacs-devel@gnu.org; Tue, 26 Jun 2018 14:32:22 -0400 Original-Received: (qmail 57538 invoked by uid 3782); 26 Jun 2018 18:32:19 -0000 Original-Received: from acm.muc.de (p5B1471C9.dip0.t-ipconnect.de [91.20.113.201]) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 26 Jun 2018 20:32:19 +0200 Original-Received: (qmail 28462 invoked by uid 1000); 26 Jun 2018 18:23:48 -0000 Content-Disposition: inline In-Reply-To: X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 193.149.48.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:226748 Archived-At: Hello, Stefan. On Wed, Jun 20, 2018 at 10:16:05 -0400, Stefan Monnier wrote: [ .... ] > If the purpose of the change is to address use cases such as Clément's: > > Sorry for jumping in a bit late. Does that mean that after the changed an > > unclosed quote will only cause refontification up to the end of the line? > > That would be a very nice improvement. I don't use electric-pair-mode, and > > as things currently stand inserting an unmatched quote applies > > font-lock-string-face to the entire buffer, which is a bit annoying. > How 'bout taking an approach that will have much fewer side-effects: > Instead of adding the complexity at the low-level of syntax-tables > to make strings "magically" terminate at EOL, hook into > self-insert-command: > when inserting a ", add a matching " at EOL if needed, or remove > the " that we added at EOL earlier. > Something like (guaranteed 100% tested, of course. No animals were harmed): > (add-hook 'post-self-insert-hook > (lambda () > (when (memq last-command-event '(?\" ?\')) > (save-excursion > (let ((pos (point)) > (ppss (syntax-ppss (line-end-position)))) > (when (and (nth 3 ppss) ;; EOL within a string > (not (nth 5 ppss))) ;; EOL not escaped > (if (and (> (point) pos) > (eq last-command-event (char-before))) > ;; Remove extraneous unmatched " at EOL. > (delete-region (1- (point)) (point)) > (insert last-command-event))))))) > 'append 'local) This is effectively electric-pair-mode, which if enabled, already inserts two "s when you type ". Not everybody likes electric-pair-mode. I don't think your suggestion is any better than mine (snipped) to which you replied. > I used `append` to try and make it interact better with electric-pair-mode. > Stefan -- Alan Mackenzie (Nuremberg, Germany).