From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: joaotavora@gmail.com (=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?=) Newsgroups: gmane.emacs.bugs Subject: bug#19356: electric-pair-mode painful quotes in latex-mode Date: Sat, 13 Dec 2014 15:47:32 +0000 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1418485711 19751 80.91.229.3 (13 Dec 2014 15:48:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 13 Dec 2014 15:48:31 +0000 (UTC) Cc: 19356@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Dec 13 16:48:24 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1Xzovc-0007zz-6j for geb-bug-gnu-emacs@m.gmane.org; Sat, 13 Dec 2014 16:48:20 +0100 Original-Received: from localhost ([::1]:33491 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xzovb-00059e-MP for geb-bug-gnu-emacs@m.gmane.org; Sat, 13 Dec 2014 10:48:19 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzovR-00059G-N2 for bug-gnu-emacs@gnu.org; Sat, 13 Dec 2014 10:48:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XzovK-00049b-6h for bug-gnu-emacs@gnu.org; Sat, 13 Dec 2014 10:48:09 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:35584) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzovK-00049X-2e for bug-gnu-emacs@gnu.org; Sat, 13 Dec 2014 10:48:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XzovJ-000346-PA for bug-gnu-emacs@gnu.org; Sat, 13 Dec 2014 10:48:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: joaotavora@gmail.com (=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?=) Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 13 Dec 2014 15:48:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19356 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 19356-submit@debbugs.gnu.org id=B19356.141848566411758 (code B ref 19356); Sat, 13 Dec 2014 15:48:01 +0000 Original-Received: (at 19356) by debbugs.gnu.org; 13 Dec 2014 15:47:44 +0000 Original-Received: from localhost ([127.0.0.1]:44950 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Xzov2-00033a-39 for submit@debbugs.gnu.org; Sat, 13 Dec 2014 10:47:44 -0500 Original-Received: from mail-wi0-f180.google.com ([209.85.212.180]:35981) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Xzouz-00033L-Ob for 19356@debbugs.gnu.org; Sat, 13 Dec 2014 10:47:42 -0500 Original-Received: by mail-wi0-f180.google.com with SMTP id n3so5226933wiv.7 for <19356@debbugs.gnu.org>; Sat, 13 Dec 2014 07:47:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type:content-transfer-encoding; bh=cuY2r0v+glloZCv1cnl69SHeHm0u8kkMZMLD0LWPt+Q=; b=Wj+iTtghLTpwvD00UmE4fCrinEgxjdQ85u2mt9FYvHte4zHSx8Bbxgatbvek7pLH/Z xrFSAY/qQC//5MG9UcUiKSp0RnCyhSo/9iFU4y3SH4VSphqYf9md71nt+r/muRBsAFxx Fh4+B3NuSekl49gFe8vxHrk2yChxUZ9ZzJhFlk8sduuifqKUKRjgvPc49Slx7HA0Bcqi 4d2tW5WLhHvavDX2wrDKG0WGF5PVvnxaXvC3jthHxcZjgXDhZVQGvoqACrPTiEaBQuuK OkWvkHV7Cy0dYcIGkBOPdy1jxbqZPYiatsgoTYOZc05uO8VG9YpICsQkLt+QpVDrfmK9 +qDg== X-Received: by 10.194.57.43 with SMTP id f11mr35934147wjq.6.1418485656010; Sat, 13 Dec 2014 07:47:36 -0800 (PST) Original-Received: from king.lan.yourcompany.com (31.57.37.188.rev.vodafone.pt. [188.37.57.31]) by mx.google.com with ESMTPSA id e7sm4208699wjf.18.2014.12.13.07.47.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Dec 2014 07:47:35 -0800 (PST) In-Reply-To: ("=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?="'s message of "Sat, 13 Dec 2014 14:54:02 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (darwin) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:97293 Archived-At: joaotavora@gmail.com (Jo=C3=A3o T=C3=A1vora) writes: >> Package: Emacs >> Version: 24.4 >> >> >> ./src/emacs -Q -f electric-pair-mode ~/tmp/foo.tex >> >> then type a word, go back to before this word and try: >> >> C-M-SPC " >> >> this will not surround the word in quotes as electric-pair-mode should. > > What kind of surrounding should take place? Should it be > > ``wordityped'' I went with this option, seemed the most sane. Here's my proposed fix (for the two issues). Let me know if you find the nested ifs ugly and I'll make a cond out of it. If it seems OK, I'll add some tests and commit it to the emacs-24 branch (someone else will cherry-pick it to the master, right?). Jo=C3=A3o diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index 1993ff1..f2d8e66 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el @@ -1300,18 +1300,40 @@ Inserts the value of `tex-open-quote' (normally ``)= or `tex-close-quote' \(normally '') depending on the context. With prefix argument, always inserts \" characters." (interactive "*P") - (if (or arg (memq (char-syntax (preceding-char)) '(?/ ?\\)) - (eq (get-text-property (point) 'face) 'tex-verbatim) - (save-excursion - (backward-char (length tex-open-quote)) - (when (or (looking-at (regexp-quote tex-open-quote)) - (looking-at (regexp-quote tex-close-quote))) - (delete-char (length tex-open-quote)) - t))) - (self-insert-command (prefix-numeric-value arg)) - (insert (if (or (memq (char-syntax (preceding-char)) '(?\( ?> ?\s)) - (memq (preceding-char) '(?~))) - tex-open-quote tex-close-quote)))) + (let ((morph-to-normal-p nil)) + ;; Discover if we'll be inserting normal double quotes. + ;; + (if (or arg (memq (char-syntax (preceding-char)) '(?/ ?\\)) + (eq (get-text-property (point) 'face) 'tex-verbatim) + ;; Discover if a preceding occurance of `tex-open-quote' + ;; should be morphed to a normal double quote.=20 + ;; + (and (>=3D (point) (+ (point-min) (length tex-open-quote))) + (save-excursion + (backward-char (length tex-open-quote)) + (when (or (looking-at (regexp-quote tex-open-quote)) + (looking-at (regexp-quote tex-close-quote))) + (delete-char (length tex-open-quote)) + (setq morph-to-normal-p t))))) + ;; In case morphing occured, be sure to turn off + ;; `electric-pair-mode' iff it was on. Otherwise let it do + ;; its thing. + ;; + (let ((electric-pair-mode (and electric-pair-mode + (not morph-to-normal-p)))) + (self-insert-command (prefix-numeric-value arg))) + ;; We'll be inserting fancy TeX quotes, but consider and + ;; imitate `electric-pair-mode''s region wrapping. + ;; + (if (and electric-pair-mode (use-region-p)) + (let* ((saved (point-marker))) + (goto-char (mark)) + (insert (if (> saved (mark)) tex-open-quote tex-close-quote)) + (goto-char saved) + (insert (if (> saved (mark)) tex-close-quote tex-open-quote))) + (insert (if (or (memq (char-syntax (preceding-char)) '(?\( ?> ?\s)) + (memq (preceding-char) '(?~))) + tex-open-quote tex-close-quote)))))) =20 (defun tex-validate-buffer () "Check current buffer for paragraphs containing mismatched braces or $s.