From: joaotavora@gmail.com (João Távora)
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 19356@debbugs.gnu.org
Subject: bug#19356: electric-pair-mode painful quotes in latex-mode
Date: Sat, 13 Dec 2014 16:42:07 +0000 [thread overview]
Message-ID: <m2wq5vsdr4.fsf@king.lan> (raw)
In-Reply-To: <m21to3tuuj.fsf@king.lan> ("João Távora"'s message of "Sat, 13 Dec 2014 15:47:32 +0000")
joaotavora@gmail.com (João Távora) writes:
> joaotavora@gmail.com (João Távora) 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ão
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 (>= (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).
+ ;;
(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))))))
(defun tex-validate-buffer ()
"Check current buffer for paragraphs containing mismatched braces or $s.
next prev parent reply other threads:[~2014-12-13 16:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-12 2:57 bug#19356: electric-pair-mode painful quotes in latex-mode Stefan Monnier
2014-12-13 14:54 ` João Távora
2014-12-13 15:47 ` João Távora
2014-12-13 16:42 ` João Távora [this message]
2014-12-14 4:53 ` Stefan Monnier
2014-12-14 11:43 ` João Távora
2014-12-14 13:56 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2wq5vsdr4.fsf@king.lan \
--to=joaotavora@gmail.com \
--cc=19356@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).