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 16:42:07 +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 1418489004 3259 80.91.229.3 (13 Dec 2014 16:43:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 13 Dec 2014 16:43:24 +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 17:43:18 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 1Xzpmn-0001cw-Dn for geb-bug-gnu-emacs@m.gmane.org; Sat, 13 Dec 2014 17:43:17 +0100 Original-Received: from localhost ([::1]:33594 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xzpmn-0005TY-1m for geb-bug-gnu-emacs@m.gmane.org; Sat, 13 Dec 2014 11:43:17 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35175) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xzpme-0005TS-Sx for bug-gnu-emacs@gnu.org; Sat, 13 Dec 2014 11:43:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XzpmY-0005DH-VT for bug-gnu-emacs@gnu.org; Sat, 13 Dec 2014 11:43:08 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:35605) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzpmY-0005DB-S7 for bug-gnu-emacs@gnu.org; Sat, 13 Dec 2014 11:43:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XzpmY-0005k1-FI for bug-gnu-emacs@gnu.org; Sat, 13 Dec 2014 11:43:02 -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 16:43:02 +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.141848894122008 (code B ref 19356); Sat, 13 Dec 2014 16:43:02 +0000 Original-Received: (at 19356) by debbugs.gnu.org; 13 Dec 2014 16:42:21 +0000 Original-Received: from localhost ([127.0.0.1]:44971 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Xzpls-0005it-Ld for submit@debbugs.gnu.org; Sat, 13 Dec 2014 11:42:21 -0500 Original-Received: from mail-wi0-f176.google.com ([209.85.212.176]:39738) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Xzplp-0005ia-Qx for 19356@debbugs.gnu.org; Sat, 13 Dec 2014 11:42:18 -0500 Original-Received: by mail-wi0-f176.google.com with SMTP id ex7so5220724wid.3 for <19356@debbugs.gnu.org>; Sat, 13 Dec 2014 08:42:12 -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=tSceVY78LzLQ7xr5nZxH+UVjuwt4gax8G7wwHMf3Gbo=; b=rnp9N4yHjYKcLgoDGmsw3Vve/50bmDUq2TerQe4gxCYoaU1CzGaSFCaXHB/SZB8VGF QdVkaWg/M/PzwLMsKaQDSyurUW3EWRxoxFgjPPXu1UH9gF5SGmJop+xLvSVbHq95nd0r uL4DStOPSq02fO/4pafELIk9qP0xT4ATXjTbvD9Rk6SXSYEge1CUCuBCEUkGBlJZncPF OWrgTiNW+of2+3Aum5dTw90UiRL8AI42fXTg1FV77IZcEG9janohw20CrQ8kwczIQkvq e1HvdvXWlYccHIAARFCfyFlIRwASV8s45a6yPfmtfllGOu04QLepQu5vAanw5n+YEiz9 wqmw== X-Received: by 10.180.85.34 with SMTP id e2mr17663537wiz.0.1418488932260; Sat, 13 Dec 2014 08:42:12 -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 cp4sm6118215wjb.16.2014.12.13.08.42.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Dec 2014 08:42:11 -0800 (PST) In-Reply-To: ("=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?="'s message of "Sat, 13 Dec 2014 15:47:32 +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:97295 Archived-At: joaotavora@gmail.com (Jo=C3=A3o T=C3=A1vora) writes: > 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?). Actually, and since I need tex-mode for writing a paper right now (nice timing on the bug report btw), the fix can be enhanced to imitate more of `electric-pair-mode'. Patch to current emacs master attached, or find two commits in the master branch of my github mirror https://github.com/capitaomorte/emacs 84ecd2c Improve on previous commit for tex-mode quotes 84f5eec Consider electric-pair-mode in tex-mode quotes Jo=C3=A3o diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index 1993ff1..3eca70b 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el @@ -1300,18 +1300,48 @@ 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") + ;; 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) - (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))) + (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. + ;; + (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)) + (when (looking-at (regexp-quote tex-close-quote)) + (delete-char (length tex-close-quote))) + t)))) + ;; Insert the normal quote (maybe letting + ;; `electric-pair-mode' do its thing). + ;;=20 (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)))) + ;; We'll be inserting fancy TeX quotes, but consider and imitate + ;; `electric-pair-mode''s two behaviours: pair-insertion and + ;; 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))) + (if (or (memq (char-syntax (preceding-char)) '(?\( ?> ?\s)) + (memq (preceding-char) '(?~))) + (if electric-pair-mode + (if (looking-at (regexp-quote tex-close-quote)) + (forward-char (length tex-close-quote)) + (insert tex-open-quote) + (insert tex-close-quote) + (backward-char 2)) + (insert tex-open-quote)) + (if (looking-at (regexp-quote tex-close-quote)) + (forward-char 2) + (insert tex-close-quote)))))) =20 (defun tex-validate-buffer () "Check current buffer for paragraphs containing mismatched braces or $s.