From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= Newsgroups: gmane.emacs.devel Subject: Re: CC Mode and electric-pair "problem". Date: Tue, 19 Jun 2018 02:35:03 +0100 Message-ID: References: <20180531123747.GA24752@ACM> <20180617201351.GA4580@ACM> <20180618103654.GA9771@ACM> <20180618154227.GB3973@ACM> <20180618180846.GC3973@ACM> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1529371999 856 195.159.176.226 (19 Jun 2018 01:33:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 19 Jun 2018 01:33:19 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (darwin) Cc: Glenn Morris , Emacs developers , Tino Calancha To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 19 03:33:15 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 1fV5WE-00006P-Oo for ged-emacs-devel@m.gmane.org; Tue, 19 Jun 2018 03:33:14 +0200 Original-Received: from localhost ([::1]:38330 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV5YM-0007KD-4C for ged-emacs-devel@m.gmane.org; Mon, 18 Jun 2018 21:35:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43189) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV5YF-0007Jw-Gv for emacs-devel@gnu.org; Mon, 18 Jun 2018 21:35:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fV5Y6-0003To-80 for emacs-devel@gnu.org; Mon, 18 Jun 2018 21:35:19 -0400 Original-Received: from mail-wr0-x22f.google.com ([2a00:1450:400c:c0c::22f]:33904) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fV5Y6-0003TU-11; Mon, 18 Jun 2018 21:35:10 -0400 Original-Received: by mail-wr0-x22f.google.com with SMTP id a12-v6so18745049wro.1; Mon, 18 Jun 2018 18:35:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=5zobpYAhNi2CB0fBTZnEV/msn4EtXKcgpKN6y8wczrE=; b=IwDEspD6FaQgaR4XWXY05BoG5dEj+5O7cdsMomfAwOzWi19fh18pStPUmCmnXPVVbh lRaWzlamUnJnsMIUa4N/PPUwSgXrBLvuS2S96VqEJmsUn3guwnW09KDdTR5UyA5YiIGu ERD823U/0YpepPQnFsNDvArQvMIQyd9ROUINWG0qx/SghG3PFtFVEdv+LHdcjMYQIMSW WLe1+L5qkkKg9ZBfHrT22mmKt9C39XccN6KoBu39IIBAaP2NzfHnd+tRbukl8XwUPZgz PzB/65HKtLegSaUXz1puucY9WR47+96cHW8hCUuiQaNMvaaaeajUfoRYb3SdiOBBXVZb FRAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=5zobpYAhNi2CB0fBTZnEV/msn4EtXKcgpKN6y8wczrE=; b=nrrYgC0qOaD+uyR5/QUnAXPITGNilBJbR1sDqBVUs8mx7Nyay8otZIfevb4j1PJh61 4bbxxZ4yEndk2iBMUEvKuwMmXl61fT+UyN1Cq35GqPiRt+BNLx9ILA8qmiCmsZ+HVlKF Mgp6iCHR+rBpHRsw6GM2cZVy1/JB4atJM52AofRbn5EFnyo3dX493HtSQ6xq0I3SGfno EaKEDwvEQYJBmWgr29culWvl5TGoVjyUhwObN3cRBRv2UYhWnMZBVm5SwS6vVOflgKXp zeJ/QyABjemHzz899Uhx7V/ddVs7m8RSj3e0nZE0E88qx2zsxrXw2x3GZlS2SKB9HHzw qDMg== X-Gm-Message-State: APt69E2rFhTUrDk/CtLqY9qvQCqdVOKUzmVcJd8TkBejIJBFKQpLU7LC rGE3IGEF5y+VB+cWer0UltAt76hy X-Google-Smtp-Source: ADUXVKKNzq5s9ZuEcNRdEuhbJF65bVoJ89/DggIUagwYhHn4PTMoXKQXstVeo3883+I0o+Nyqn3OUw== X-Received: by 2002:adf:c444:: with SMTP id a4-v6mr12791655wrg.20.1529372108675; Mon, 18 Jun 2018 18:35:08 -0700 (PDT) Original-Received: from kitaj.yourcompany.com (178.110.103.87.rev.vodafone.pt. [87.103.110.178]) by smtp.gmail.com with ESMTPSA id 63-v6sm11503953wmv.48.2018.06.18.18.35.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Jun 2018 18:35:07 -0700 (PDT) In-Reply-To: (=?utf-8?Q?=22Jo=C3=A3o_T=C3=A1vor?= =?utf-8?Q?a=22's?= message of "Tue, 19 Jun 2018 00:43:05 +0100") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22f 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:226486 Archived-At: Jo=C3=A3o T=C3=A1vora writes: >> It is what I said at the end of my previous post. e-p-m assumes that >> whitespace has "neutral" syntax. When it doesn't (like here, with a >> string-fence property), the scan-sexps doesn't work as desired. I'm >> convinced this could be changed. > OK. I'll have a look (I admit to not having looked at that code in depth > since I wrote it 5 years ago). I was pretty much convinced it was > flawless :-) I looked at this code and decided its better to leave it. I don't need it to fix the problem at hand. I may change this opinion, so I started by pushing this change that we need regardless: commit 6353387835f6cb34765ac525ac3e9edf3239e589 =20=20=20=20 Electric-pair-mode lets modes choose how to skip whitespace =20=20=20=20=20=20=20 * lisp/elec-pair.el (electric-pair-skip-whitespace-function): New bu= ffer-local variable. (electric-pair-post-self-insert-function): Call it. Then, I defined this function (defun c-mode-electric-skip-whitespace () "CC-mode's way of skipping whitespace." (let ((saved (point)) (in-comment (nth 4 (syntax-ppss)))) ;; actually if you also skip backslash here, you'll skip/chomp ;; over newline escapes, which may be nice. (skip-chars-forward (apply #'string electric-pair-skip-whitespace-c= hars)) (unless (or (not in-comment) (nth 4 (syntax-ppss))) (goto-char saved)))) And added this to c-mode-common-hook: (add-hook 'c-mode-common-hook (lambda () (setq-local electric-pair-skip-whitespace-function #'c-mode-electric-skip-whitespace) (add-function :around (local 'electric-pair-skip-self) (lambda (&rest r) (let (terminator) (if (and (setq terminator (nth 3 (syntax-ppss))) (save-excursion (goto-char (1- (line-end-positi= on))) (and (eq terminator (nth 3 (syntax-ppss))) (not (eq terminator (char-after)))))) t (apply r))))))) All e-p-m tests pass, though the detection of NL-terminated string is very shady (but you probably have much better ways inside CC-mode to detect them). If your "fix-scan-sexps" idea above works (I don't understand it) then the add-function won't be needed at all. Let me know what you think, Jo=C3=A3o