From unknown Sat Jun 21 03:07:41 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#19356 <19356@debbugs.gnu.org> To: bug#19356 <19356@debbugs.gnu.org> Subject: Status: electric-pair-mode painful quotes in latex-mode Reply-To: bug#19356 <19356@debbugs.gnu.org> Date: Sat, 21 Jun 2025 10:07:41 +0000 retitle 19356 electric-pair-mode painful quotes in latex-mode reassign 19356 emacs submitter 19356 Stefan Monnier severity 19356 minor thanks From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 11 23:20:26 2014 Received: (at submit) by debbugs.gnu.org; 12 Dec 2014 04:20:26 +0000 Received: from localhost ([127.0.0.1]:43430 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XzHiL-0000n0-Cg for submit@debbugs.gnu.org; Thu, 11 Dec 2014 23:20:25 -0500 Received: from eggs.gnu.org ([208.118.235.92]:58988) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XzHiH-0000mi-W6 for submit@debbugs.gnu.org; Thu, 11 Dec 2014 23:20:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XzHi5-00010D-Ae for submit@debbugs.gnu.org; Thu, 11 Dec 2014 23:20:16 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:49761) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzHi5-000100-8L for submit@debbugs.gnu.org; Thu, 11 Dec 2014 23:20:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzHhy-0007fh-Ln for bug-gnu-emacs@gnu.org; Thu, 11 Dec 2014 23:20:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XzHhs-0000UP-B4 for bug-gnu-emacs@gnu.org; Thu, 11 Dec 2014 23:20:02 -0500 Received: from ironport2-out.teksavvy.com ([206.248.154.181]:8024) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzGPk-0005hk-Ak for bug-gnu-emacs@gnu.org; Thu, 11 Dec 2014 21:57:08 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsQOAOwQflTO+ILA/2dsb2JhbABbgwcBITBZgjW0UwGPYxgFAoYhBIEoFwEBAQEBAXyEXxMBSw8EIQEcDVWIIrBBpkSQHgEBboIcD0SBQQWLAYU6iQyDe5FtgXiCAgQcgXchMIENgToBAQE X-IPAS-Result: AsQOAOwQflTO+ILA/2dsb2JhbABbgwcBITBZgjW0UwGPYxgFAoYhBIEoFwEBAQEBAXyEXxMBSw8EIQEcDVWIIrBBpkSQHgEBboIcD0SBQQWLAYU6iQyDe5FtgXiCAgQcgXchMIENgToBAQE X-IronPort-AV: E=Sophos;i="5.07,502,1413259200"; d="scan'208";a="100245740" Received: from 206-248-130-192.dsl.teksavvy.com (HELO pastel.home) ([206.248.130.192]) by ironport2-out.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 11 Dec 2014 21:57:06 -0500 Received: by pastel.home (Postfix, from userid 20848) id 82A072ED4; Thu, 11 Dec 2014 21:57:06 -0500 (EST) From: Stefan Monnier To: bug-gnu-emacs@gnu.org Subject: electric-pair-mode painful quotes in latex-mode X-debbugs-cc: =?iso-8859-1?Q?Jo=E3o_T=E1vora?= Date: Thu, 11 Dec 2014 21:57:05 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) 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. Similarly, type hello " " Notice how the second " inserts `""' instead of just modifying the '' into a single ". This same problem happens before a word. Stefan In GNU Emacs 25.0.50.1 (x86_64-unknown-linux-gnu, X toolkit, Xaw3d scroll bars) of 2014-12-10 on pastel Repository revision: 30075cf7025c17542f23610de1b54d84bbde192b Windowing system distributor `The X.Org Foundation', version 11.0.11601901 System Description: Debian GNU/Linux 8.0 (jessie) Configured using: `configure -C --enable-checking --enable-check-lisp-object-type 'CFLAGS=-Wall -g3 -Og -Wno-pointer-sign' PKG_CONFIG_PATH=/home/monnier/lib/pkgconfig' Configured features: XAW3D XPM JPEG TIFF GIF PNG SOUND GPM DBUS NOTIFY GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB Important settings: value of $LANG: fr_CH.UTF-8 locale-coding-system: utf-8-unix Major mode: InactiveMinibuffer Minor modes in effect: electric-pair-mode: t url-handler-mode: t global-reveal-mode: t reveal-mode: t auto-insert-mode: t savehist-mode: t minibuffer-electric-default-mode: t global-eldoc-mode: t electric-indent-mode: t mouse-wheel-mode: t global-prettify-symbols-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t line-number-mode: t Recent messages: Loading /home/monnier/src/elisp/ProofGeneral/generic/proof-site.el (source)...done Loading /home/monnier/etc/emacs/X11.el (source)...done Loading /home/monnier/etc/emacs/custom.el (source)...done Warning: turn-on-eldoc-mode is obsolete! Ispell-kill: nil american Starting new Ispell process /usr/bin/aspell with american dictionary... For information about GNU Emacs and the GNU system, type C-h C-a. is undefined [2 times] Quit funcall-interactively: End of buffer Load-path shadows: /home/monnier/src/emacs/elpa/packages/ada-mode/ada-ref-man hides /home/monnier/src/emacs/elpa/packages/ada-ref-man/ada-ref-man /home/monnier/src/emacs/elpa/packages/ada-mode/ada-prj hides /home/monnier/src/emacs/work/lisp/progmodes/ada-prj /home/monnier/src/emacs/elpa/packages/ada-mode/ada-stmt hides /home/monnier/src/emacs/work/lisp/progmodes/ada-stmt /home/monnier/src/emacs/elpa/packages/ada-mode/ada-mode hides /home/monnier/src/emacs/work/lisp/progmodes/ada-mode /home/monnier/src/emacs/elpa/packages/ada-mode/ada-xref hides /home/monnier/src/emacs/work/lisp/progmodes/ada-xref /home/monnier/src/emacs/elpa/packages/crisp/crisp hides /home/monnier/src/emacs/work/lisp/obsolete/crisp Features: (shadow sort mail-extr emacsbug message dired format-spec rfc822 mml mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mail-utils server noutline outline easy-mmode flyspell ispell checkdoc thingatpt help-mode load-dir elec-pair url-handlers url-parse auth-source eieio byte-opt bytecomp byte-compile cl-extra cconv eieio-core gnus-util time-date mm-util mail-prsvr password-cache url-vars reveal autoinsert proof-site proof-autoloads cl-macs cl gv pg-vars savehist minibuf-eldef disp-table finder-inf edmacro kmacro cl-loaddefs cl-lib advice help-fns info easymenu package epg-config bbdb-autoloads agda2 vm-autoloads tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment elisp-mode lisp-mode prog-mode register page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock syntax font-core frame cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer nadvice loaddefs button faces cus-face macroexp files text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote make-network-process dbusbind inotify dynamic-setting font-render-setting x-toolkit x multi-tty emacs) Memory information: ((conses 8 127506 20873) (symbols 24 21454 0) (miscs 20 1455 173) (strings 16 36084 3039) (string-bytes 1 1186490) (vectors 8 17258) (vector-slots 4 478789 3036) (floats 8 107 266) (intervals 28 285 0) (buffers 520 11) (heap 1024 8693 640)) From debbugs-submit-bounces@debbugs.gnu.org Sat Dec 13 09:54:20 2014 Received: (at 19356) by debbugs.gnu.org; 13 Dec 2014 14:54:20 +0000 Received: from localhost ([127.0.0.1]:44482 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Xzo5L-0000I1-Ea for submit@debbugs.gnu.org; Sat, 13 Dec 2014 09:54:19 -0500 Received: from mail-wi0-f173.google.com ([209.85.212.173]:45891) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Xzo5J-0000Hj-M6 for 19356@debbugs.gnu.org; Sat, 13 Dec 2014 09:54:18 -0500 Received: by mail-wi0-f173.google.com with SMTP id r20so5075076wiv.0 for <19356@debbugs.gnu.org>; Sat, 13 Dec 2014 06:54:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:user-agent:date:message-id :mime-version:content-type:content-transfer-encoding; bh=XD6Rkmx4OZxBHITO8lGY79xI8JJPWtAEZnxpvhziSpg=; b=MXXQjPw5rIpJLGZgURk+ZurE40FryL5Xv2DOpCDwsQLwzLt5KGM4/AT9C3fyXpwZVZ 6hIqkSFJ+oiHIeH/12jin4rRtYX7FGodDoinpcPJLWnkCYA1JRDq5le5P+RGPLm3YeVb J3miY3jc9H5k+A2bPbp1+sWlzsOkJSu0r20aqVzkgTSVlJUc2lVknJMVdHULTKo+Tqr7 dtqqNifB9ozKt44w23qfGlrL5vZmrwXCwY5TSHzbeh1Q2CIkWYFDBYDK2pq36+SISAGl XbQZ90iaorjtO5GM4eDtpIaPYWMNLl/3TcRq7Ur67vGjS7BLJh4Uaz/wY8bcerQJqW4E DuUQ== X-Received: by 10.180.11.98 with SMTP id p2mr17069477wib.22.1418482451983; Sat, 13 Dec 2014 06:54:11 -0800 (PST) Received: from king.lan.yourcompany.com (31.57.37.188.rev.vodafone.pt. [188.37.57.31]) by mx.google.com with ESMTPSA id gy8sm5909223wib.23.2014.12.13.06.54.10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Dec 2014 06:54:11 -0800 (PST) From: joaotavora@gmail.com (=?utf-8?B?Sm/Do28gVMOhdm9yYQ==?=) To: Stefan Monnier Subject: Re: bug#19356: electric-pair-mode painful quotes in latex-mode References: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (darwin) Date: Sat, 13 Dec 2014 14:54:02 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 19356 Cc: 19356@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) > 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'' or should it be "wordityped" ? Anyway, without having anlysed the problem thoroughly, I lean towards making tex-mode.el's `tex-insert-quote' aware of `electric-pair-mode', possibly downgrading and/or not respecting stuff like `electric-pair-preserve-balance', instead of overloading the latter with abstractions to deal with multi-character metamorphosing quotes. Do you agree? Or do you have any other solution in mind? Also, independent of `electric-pair-mode', typing a double quote (`tex-insert-quote') with only whitespace preceding point gives me a "Beginning of buffer" error. Should I also fix it? > > Similarly, type > > hello " " > > Notice how the second " inserts `""' instead of just modifying the '' > into a single ". This same problem happens before a word. Reproduced. `electric-pair-mode' does affect this. Jo=C3=A3o From debbugs-submit-bounces@debbugs.gnu.org Sat Dec 13 10:47:44 2014 Received: (at 19356) by debbugs.gnu.org; 13 Dec 2014 15:47:44 +0000 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 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 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) 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) From: joaotavora@gmail.com (=?utf-8?B?Sm/Do28gVMOhdm9yYQ==?=) To: Stefan Monnier Subject: Re: bug#19356: electric-pair-mode painful quotes in latex-mode References: Date: Sat, 13 Dec 2014 15:47:32 +0000 In-Reply-To: (=?utf-8?Q?=22Jo=C3=A3o_T=C3=A1vora?= =?utf-8?Q?=22's?= message of "Sat, 13 Dec 2014 14:54:02 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (darwin) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 19356 Cc: 19356@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) 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. From debbugs-submit-bounces@debbugs.gnu.org Sat Dec 13 11:42:21 2014 Received: (at 19356) by debbugs.gnu.org; 13 Dec 2014 16:42:21 +0000 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 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 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) 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) From: joaotavora@gmail.com (=?utf-8?B?Sm/Do28gVMOhdm9yYQ==?=) To: Stefan Monnier Subject: Re: bug#19356: electric-pair-mode painful quotes in latex-mode References: Date: Sat, 13 Dec 2014 16:42:07 +0000 In-Reply-To: (=?utf-8?Q?=22Jo=C3=A3o_T=C3=A1vora?= =?utf-8?Q?=22's?= message of "Sat, 13 Dec 2014 15:47:32 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (darwin) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 19356 Cc: 19356@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) 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. From debbugs-submit-bounces@debbugs.gnu.org Sat Dec 13 23:53:14 2014 Received: (at 19356) by debbugs.gnu.org; 14 Dec 2014 04:53:14 +0000 Received: from localhost ([127.0.0.1]:45178 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y01BC-0007i6-D8 for submit@debbugs.gnu.org; Sat, 13 Dec 2014 23:53:14 -0500 Received: from ironport2-out.teksavvy.com ([206.248.154.181]:1180) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y01BA-0007hs-NZ for 19356@debbugs.gnu.org; Sat, 13 Dec 2014 23:53:13 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjwPAOwQflTO+ILA/2dsb2JhbABbgweDYIVaxR0EAgKBJBcBAQEBAQF8hAMBAQMBDkgPFAULCzQSFBgNUogcCdZZAQEBAQYBAQEBHpBvB4RIBYsBpC6BeIQZIYJ3AQEB X-IPAS-Result: AjwPAOwQflTO+ILA/2dsb2JhbABbgweDYIVaxR0EAgKBJBcBAQEBAQF8hAMBAQMBDkgPFAULCzQSFBgNUogcCdZZAQEBAQYBAQEBHpBvB4RIBYsBpC6BeIQZIYJ3AQEB X-IronPort-AV: E=Sophos;i="5.07,502,1413259200"; d="scan'208";a="101000801" Received: from 206-248-130-192.dsl.teksavvy.com (HELO ceviche.home) ([206.248.130.192]) by ironport2-out.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 13 Dec 2014 23:53:07 -0500 Received: by ceviche.home (Postfix, from userid 20848) id E418D660D3; Sat, 13 Dec 2014 23:53:06 -0500 (EST) From: Stefan Monnier To: joaotavora@gmail.com (=?windows-1252?B?Sm/jbyBU4XZvcmE=?=) Subject: Re: bug#19356: electric-pair-mode painful quotes in latex-mode Message-ID: References: Date: Sat, 13 Dec 2014 23:53:06 -0500 In-Reply-To: (=?windows-1252?Q?=22Jo=E3o_T=E1vor?= =?windows-1252?Q?a=22's?= message of "Sat, 13 Dec 2014 14:54:02 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.3 (/) X-Debbugs-Envelope-To: 19356 Cc: 19356@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.3 (/) > What kind of surrounding should take place? Should it be > ``wordityped'' > or should it be > "wordityped" > ? I think either way would be OK. I guess ideally C-M-SPC " should do ``wordityped'' and C-M-SPC " " should do "wordityped" but it's OK if we don't reach this ideal. > Anyway, without having anlysed the problem thoroughly, I lean towards > making tex-mode.el's `tex-insert-quote' aware of `electric-pair-mode', > possibly downgrading and/or not respecting stuff like > `electric-pair-preserve-balance', instead of overloading the latter with > abstractions to deal with multi-character metamorphosing quotes. Do you > agree? Or do you have any other solution in mind? I don't see the need to extend electric-pair's code for this use case, indeed, except if it can be done with a well-placed hook. > Also, independent of `electric-pair-mode', typing a double quote > (`tex-insert-quote') with only whitespace preceding point gives me a > "Beginning of buffer" error. Should I also fix it? I wouldn't punish you for 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?). The patch looks OK. Installing it on emacs-24 sounds good, thank you (and no, it won't be cherry picked: it'll be merged instead). Stefan From debbugs-submit-bounces@debbugs.gnu.org Sun Dec 14 06:43:22 2014 Received: (at 19356-done) by debbugs.gnu.org; 14 Dec 2014 11:43:22 +0000 Received: from localhost ([127.0.0.1]:45270 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y07a5-000105-MN for submit@debbugs.gnu.org; Sun, 14 Dec 2014 06:43:22 -0500 Received: from mail-wi0-f180.google.com ([209.85.212.180]:40436) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y07a2-0000zq-Lj for 19356-done@debbugs.gnu.org; Sun, 14 Dec 2014 06:43:19 -0500 Received: by mail-wi0-f180.google.com with SMTP id n3so6499200wiv.1 for <19356-done@debbugs.gnu.org>; Sun, 14 Dec 2014 03:43:13 -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; bh=AhGmeqLDNbgQBMvHnvixy3uvL+X6VZ/sAR/gM7gy5Lo=; b=vRWNJvd941dSjcZNv1gNlWPt0QHKgWsfa6KqOwHAxwQM49qfiraeg0kzGT0on/SJoo Nw9yjqeQpSeUwkaeGUJqqvfsHxMk9+5Kk5x8hZxOvg/lP2CVEmDIgjLsx/YgQZT4uPKe 1iLy+EedUIGcY0v0QIIaRBj5+ET5BThDZRniPV/rAwOULh0sNgZI1p0KtPvJV1JXYZx/ aSrG5jCa3zmY9abHCyMQGkPt6u9baUcdGJGOfnuilTvQ4FCVUHpDyU1J1121PZ/UvHfJ aOmeyQPxzV9k7CHoS5/SREZqHviQYfMizqkiTA602S0O8af9V8Qx3kaMPvli+kc0KfM3 2q5A== X-Received: by 10.194.201.137 with SMTP id ka9mr44194712wjc.66.1418557392923; Sun, 14 Dec 2014 03:43:12 -0800 (PST) Received: from holy.lan.yourcompany.com (31.57.37.188.rev.vodafone.pt. [188.37.57.31]) by mx.google.com with ESMTPSA id hn2sm8896494wjc.5.2014.12.14.03.43.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Dec 2014 03:43:11 -0800 (PST) From: joaotavora@gmail.com (=?utf-8?B?Sm/Do28gVMOhdm9yYQ==?=) To: Stefan Monnier Subject: Re: bug#19356: electric-pair-mode painful quotes in latex-mode References: Date: Sun, 14 Dec 2014 11:43:09 +0000 In-Reply-To: (Stefan Monnier's message of "Sat, 13 Dec 2014 23:53:06 -0500") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.92 (darwin) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 19356-done Cc: 19356-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Stefan Monnier writes: >> What kind of surrounding should take place? Should it be >> ``wordityped'' >> or should it be >> "wordityped" >> ? > > I think either way would be OK. > I guess ideally > > C-M-SPC " > > should do > > ``wordityped'' > > and > > C-M-SPC " " > > should do > > "wordityped" > > but it's OK if we don't reach this ideal. Not sure If I agree that's ideal, but I'll try to implement it for and use in my tex-mode this week. > I don't see the need to extend electric-pair's code for this use > case, indeed, except if it can be done with a well-placed hook. I don't think it can. Not without heroic sophistication. > The patch looks OK. Installing it on emacs-24 sounds good, thank you Done. Hope I haven't forgotten anything... > (and no, it won't be cherry picked: it'll be merged instead). So this very same commit to emacs-24 (and all other commits) will be an ancestor of master. OK, that works, I suppose. I hear talk (and misunderstandings) of rebasing in emacs-devel, which is basically cherry-picking, and that's why I asked. I probably misunderstood (and sure as hell don't want to fuel that discusssion). J From debbugs-submit-bounces@debbugs.gnu.org Sun Dec 14 09:05:56 2014 Received: (at 19356-done) by debbugs.gnu.org; 14 Dec 2014 14:05:56 +0000 Received: from localhost ([127.0.0.1]:45378 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y09o3-00006y-Uj for submit@debbugs.gnu.org; Sun, 14 Dec 2014 09:05:56 -0500 Received: from ironport2-out.teksavvy.com ([206.248.154.181]:39164) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y09o2-00006m-68 for 19356-done@debbugs.gnu.org; Sun, 14 Dec 2014 09:05:54 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjsPAOwQflTO+ILA/2dsb2JhbABbgweDYIVaxR0EAgKBJBcBAQEBAQF8hAMBAQMBViMFCws0EhQYDYhuCdZZAQEBAQEFAQEBAQEdkG8HhEgFiwGkLoF4hBkhgncBAQE X-IPAS-Result: AjsPAOwQflTO+ILA/2dsb2JhbABbgweDYIVaxR0EAgKBJBcBAQEBAQF8hAMBAQMBViMFCws0EhQYDYhuCdZZAQEBAQEFAQEBAQEdkG8HhEgFiwGkLoF4hBkhgncBAQE X-IronPort-AV: E=Sophos;i="5.07,502,1413259200"; d="scan'208";a="101334678" Received: from 206-248-130-192.dsl.teksavvy.com (HELO pastel.home) ([206.248.130.192]) by ironport2-out.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 14 Dec 2014 09:05:47 -0500 Received: by pastel.home (Postfix, from userid 20848) id 3F8DF175E; Sun, 14 Dec 2014 08:56:51 -0500 (EST) From: Stefan Monnier To: joaotavora@gmail.com (=?windows-1252?B?Sm/jbyBU4XZvcmE=?=) Subject: Re: bug#19356: electric-pair-mode painful quotes in latex-mode Message-ID: References: Date: Sun, 14 Dec 2014 08:56:51 -0500 In-Reply-To: (=?windows-1252?Q?=22Jo=E3o_T=E1vor?= =?windows-1252?Q?a=22's?= message of "Sun, 14 Dec 2014 11:43:09 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.3 (/) X-Debbugs-Envelope-To: 19356-done Cc: 19356-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.3 (/) > So this very same commit to emacs-24 (and all other commits) will be an > ancestor of master. Yes. Cherry-picking is used when going in the other direction (when backporting changes from master to emacs-24). Stefan From unknown Sat Jun 21 03:07:41 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Mon, 12 Jan 2015 12:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator