Consider electric-pair-mode in tex-mode.
Fixes: debbugs:19356 * lisp/textmodes/tex-mode.el (tex-insert-quote): Consider and respect `electric-pair-mode'. * test/automated/electric-tests.el (autowrapping-7): New test for tex-mode's autowrapping. (electric-pair-test-for): Call the actual key-binding interactively.
This commit is contained in:
parent
7b945728d3
commit
bb57c94d5f
4 changed files with 60 additions and 11 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2014-12-14 João Távora <joaotavora@gmail.com>
|
||||||
|
|
||||||
|
* textmodes/tex-mode.el (tex-insert-quote): Consider and respect
|
||||||
|
`electric-pair-mode' (bug#19356).
|
||||||
|
|
||||||
2014-12-12 Michael Albinus <michael.albinus@gmx.de>
|
2014-12-12 Michael Albinus <michael.albinus@gmx.de>
|
||||||
|
|
||||||
* simple.el (password-word-equivalents): Add "passcode", used for
|
* simple.el (password-word-equivalents): Add "passcode", used for
|
||||||
|
|
|
@ -1277,18 +1277,48 @@ Inserts the value of `tex-open-quote' (normally ``) or `tex-close-quote'
|
||||||
\(normally '') depending on the context. With prefix argument, always
|
\(normally '') depending on the context. With prefix argument, always
|
||||||
inserts \" characters."
|
inserts \" characters."
|
||||||
(interactive "*P")
|
(interactive "*P")
|
||||||
|
;; Discover if we'll be inserting normal double quotes.
|
||||||
|
;;
|
||||||
(if (or arg (memq (char-syntax (preceding-char)) '(?/ ?\\))
|
(if (or arg (memq (char-syntax (preceding-char)) '(?/ ?\\))
|
||||||
(eq (get-text-property (point) 'face) 'tex-verbatim)
|
(eq (get-text-property (point) 'face) 'tex-verbatim)
|
||||||
(save-excursion
|
;; Discover if a preceding occurance of `tex-open-quote'
|
||||||
(backward-char (length tex-open-quote))
|
;; should be morphed to a normal double quote.
|
||||||
(when (or (looking-at (regexp-quote tex-open-quote))
|
;;
|
||||||
(looking-at (regexp-quote tex-close-quote)))
|
(and (>= (point) (+ (point-min) (length tex-open-quote)))
|
||||||
(delete-char (length tex-open-quote))
|
(save-excursion
|
||||||
t)))
|
(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 (eventually letting
|
||||||
|
;; `electric-pair-mode' do its thing).
|
||||||
|
;;
|
||||||
(self-insert-command (prefix-numeric-value arg))
|
(self-insert-command (prefix-numeric-value arg))
|
||||||
(insert (if (or (memq (char-syntax (preceding-char)) '(?\( ?> ?\s))
|
;; We'll be inserting fancy TeX quotes, but consider and imitate
|
||||||
(memq (preceding-char) '(?~)))
|
;; `electric-pair-mode''s two behaviours: pair-insertion and
|
||||||
tex-open-quote tex-close-quote))))
|
;; 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 (length tex-close-quote)))
|
||||||
|
(insert tex-open-quote))
|
||||||
|
(if (looking-at (regexp-quote tex-close-quote))
|
||||||
|
(forward-char (length tex-close-quote))
|
||||||
|
(insert tex-close-quote))))))
|
||||||
|
|
||||||
(defun tex-validate-buffer ()
|
(defun tex-validate-buffer ()
|
||||||
"Check current buffer for paragraphs containing mismatched braces or $s.
|
"Check current buffer for paragraphs containing mismatched braces or $s.
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
2014-12-14 João Távora <joaotavora@gmail.com>
|
||||||
|
|
||||||
|
* automated/electric-tests.el (autowrapping-7): Tests for
|
||||||
|
tex-mode.
|
||||||
|
|
||||||
2014-12-13 Glenn Morris <rgm@gnu.org>
|
2014-12-13 Glenn Morris <rgm@gnu.org>
|
||||||
|
|
||||||
* automated/flymake/warnpred/test.pl: Tweak format, since the
|
* automated/flymake/warnpred/test.pl: Tweak format, since the
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
(cl-progv
|
(cl-progv
|
||||||
(mapcar #'car bindings)
|
(mapcar #'car bindings)
|
||||||
(mapcar #'cdr bindings)
|
(mapcar #'cdr bindings)
|
||||||
(self-insert-command 1))))
|
(call-interactively (key-binding `[,last-command-event])))))
|
||||||
(should (equal (buffer-substring-no-properties (point-min) (point-max))
|
(should (equal (buffer-substring-no-properties (point-min) (point-max))
|
||||||
expected-string))
|
expected-string))
|
||||||
(should (equal (point)
|
(should (equal (point)
|
||||||
|
@ -575,5 +575,14 @@ baz\"\""
|
||||||
(skip-chars-backward "\"")
|
(skip-chars-backward "\"")
|
||||||
(mark-sexp -1)))
|
(mark-sexp -1)))
|
||||||
|
|
||||||
|
(define-electric-pair-test autowrapping-7
|
||||||
|
"foo" "\"" :expected-string "``foo''" :expected-point 8
|
||||||
|
:modes '(tex-mode)
|
||||||
|
:fixture-fn #'(lambda ()
|
||||||
|
(electric-pair-mode 1)
|
||||||
|
(goto-char (point-max))
|
||||||
|
(skip-chars-backward "\"")
|
||||||
|
(mark-sexp -1)))
|
||||||
|
|
||||||
(provide 'electric-tests)
|
(provide 'electric-tests)
|
||||||
;;; electric-tests.el ends here
|
;;; electric-tests.el ends here
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue