* bug#19356: electric-pair-mode painful quotes in latex-mode
@ 2014-12-12 2:57 Stefan Monnier
2014-12-13 14:54 ` João Távora
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2014-12-12 2:57 UTC (permalink / raw
To: 19356; +Cc: João Távora
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.
<C-drag-mouse-2> 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))
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#19356: electric-pair-mode painful quotes in latex-mode
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-14 4:53 ` Stefan Monnier
0 siblings, 2 replies; 7+ messages in thread
From: João Távora @ 2014-12-13 14:54 UTC (permalink / raw
To: Stefan Monnier; +Cc: 19356
> 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ão
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#19356: electric-pair-mode painful quotes in latex-mode
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
2014-12-14 4:53 ` Stefan Monnier
1 sibling, 1 reply; 7+ messages in thread
From: João Távora @ 2014-12-13 15:47 UTC (permalink / raw
To: Stefan Monnier; +Cc: 19356
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?).
João
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.
+ ;;
+ (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))
+ (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))))))
(defun tex-validate-buffer ()
"Check current buffer for paragraphs containing mismatched braces or $s.
^ permalink raw reply related [flat|nested] 7+ messages in thread
* bug#19356: electric-pair-mode painful quotes in latex-mode
2014-12-13 15:47 ` João Távora
@ 2014-12-13 16:42 ` João Távora
0 siblings, 0 replies; 7+ messages in thread
From: João Távora @ 2014-12-13 16:42 UTC (permalink / raw
To: Stefan Monnier; +Cc: 19356
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.
^ permalink raw reply related [flat|nested] 7+ messages in thread
* bug#19356: electric-pair-mode painful quotes in latex-mode
2014-12-13 14:54 ` João Távora
2014-12-13 15:47 ` João Távora
@ 2014-12-14 4:53 ` Stefan Monnier
2014-12-14 11:43 ` João Távora
1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2014-12-14 4:53 UTC (permalink / raw
To: João Távora; +Cc: 19356
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#19356: electric-pair-mode painful quotes in latex-mode
2014-12-14 4:53 ` Stefan Monnier
@ 2014-12-14 11:43 ` João Távora
2014-12-14 13:56 ` Stefan Monnier
0 siblings, 1 reply; 7+ messages in thread
From: João Távora @ 2014-12-14 11:43 UTC (permalink / raw
To: Stefan Monnier; +Cc: 19356-done
Stefan Monnier <monnier@iro.umontreal.ca> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#19356: electric-pair-mode painful quotes in latex-mode
2014-12-14 11:43 ` João Távora
@ 2014-12-14 13:56 ` Stefan Monnier
0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2014-12-14 13:56 UTC (permalink / raw
To: João Távora; +Cc: 19356-done
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-12-14 13:56 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2014-12-14 4:53 ` Stefan Monnier
2014-12-14 11:43 ` João Távora
2014-12-14 13:56 ` Stefan Monnier
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.