From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: CC Mode and electric-pair "problem". Date: Wed, 20 Jun 2018 10:16:05 -0400 Message-ID: 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 1529504073 31058 195.159.176.226 (20 Jun 2018 14:14:33 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 20 Jun 2018 14:14:33 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jun 20 16:14:29 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 1fVdsS-0007y3-AU for ged-emacs-devel@m.gmane.org; Wed, 20 Jun 2018 16:14:28 +0200 Original-Received: from localhost ([::1]:49976 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVduZ-0004FK-IN for ged-emacs-devel@m.gmane.org; Wed, 20 Jun 2018 10:16:39 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40900) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVduI-0004BP-3f for emacs-devel@gnu.org; Wed, 20 Jun 2018 10:16:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVduD-0001a7-43 for emacs-devel@gnu.org; Wed, 20 Jun 2018 10:16:22 -0400 Original-Received: from [195.159.176.226] (port=55532 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fVduC-0001Zt-St for emacs-devel@gnu.org; Wed, 20 Jun 2018 10:16:17 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1fVds2-0007Xc-K9 for emacs-devel@gnu.org; Wed, 20 Jun 2018 16:14:02 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 54 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:cJJ7IvAQY8fjE9hVSgrBPiDsp90= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 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:226551 Archived-At: > How about this idea: we add a new syntax flag to Emacs, ", which > terminates any open string, the same way the syntax > terminates any > open comment. We could then set this syntax flag on newline. To me this looks like adding a hack to patch over another. I don't think the new behavior of unclosed strings in CC-mode is worse than the old one, but I don't think it's really better either: it's just different (in some cases it's better in others it's worse). So the problem I see with it is that it brings complexity in the code with no real improvement in terms of behavior. The bad-interaction with electric-pair shows that this complexity has a real immediate cost. The suggestion above suggests that this complexity may bring in yet more complexity. Me not happy. 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) I used `append` to try and make it interact better with electric-pair-mode. Stefan