aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoao Tavora2014-12-14 11:22:46 +0000
committerJoao Tavora2014-12-14 11:22:46 +0000
commitbb57c94d5f047cde106ffa71bf59f24b2b3027b8 (patch)
tree90bcb89e16d1fef22bd06d8035ac0797b11def88
parent7b945728d3db91732ace3d3a1cb1c4bdea444b2c (diff)
downloademacs-bb57c94d5f047cde106ffa71bf59f24b2b3027b8.tar.gz
emacs-bb57c94d5f047cde106ffa71bf59f24b2b3027b8.zip
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.
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/textmodes/tex-mode.el50
-rw-r--r--test/ChangeLog5
-rw-r--r--test/automated/electric-tests.el11
4 files changed, 60 insertions, 11 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 4be07b5921c..204283ea705 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
12014-12-14 João Távora <joaotavora@gmail.com>
2
3 * textmodes/tex-mode.el (tex-insert-quote): Consider and respect
4 `electric-pair-mode' (bug#19356).
5
12014-12-12 Michael Albinus <michael.albinus@gmx.de> 62014-12-12 Michael Albinus <michael.albinus@gmx.de>
2 7
3 * simple.el (password-word-equivalents): Add "passcode", used for 8 * simple.el (password-word-equivalents): Add "passcode", used for
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el
index 18843bcd15a..cb8f2ee4357 100644
--- a/lisp/textmodes/tex-mode.el
+++ b/lisp/textmodes/tex-mode.el
@@ -1277,18 +1277,48 @@ Inserts the value of `tex-open-quote' (normally ``) or `tex-close-quote'
1277\(normally '') depending on the context. With prefix argument, always 1277\(normally '') depending on the context. With prefix argument, always
1278inserts \" characters." 1278inserts \" characters."
1279 (interactive "*P") 1279 (interactive "*P")
1280 ;; Discover if we'll be inserting normal double quotes.
1281 ;;
1280 (if (or arg (memq (char-syntax (preceding-char)) '(?/ ?\\)) 1282 (if (or arg (memq (char-syntax (preceding-char)) '(?/ ?\\))
1281 (eq (get-text-property (point) 'face) 'tex-verbatim) 1283 (eq (get-text-property (point) 'face) 'tex-verbatim)
1282 (save-excursion 1284 ;; Discover if a preceding occurance of `tex-open-quote'
1283 (backward-char (length tex-open-quote)) 1285 ;; should be morphed to a normal double quote.
1284 (when (or (looking-at (regexp-quote tex-open-quote)) 1286 ;;
1285 (looking-at (regexp-quote tex-close-quote))) 1287 (and (>= (point) (+ (point-min) (length tex-open-quote)))
1286 (delete-char (length tex-open-quote)) 1288 (save-excursion
1287 t))) 1289 (backward-char (length tex-open-quote))
1290 (when (or (looking-at (regexp-quote tex-open-quote))
1291 (looking-at (regexp-quote tex-close-quote)))
1292 (delete-char (length tex-open-quote))
1293 (when (looking-at (regexp-quote tex-close-quote))
1294 (delete-char (length tex-close-quote)))
1295 t))))
1296 ;; Insert the normal quote (eventually letting
1297 ;; `electric-pair-mode' do its thing).
1298 ;;
1288 (self-insert-command (prefix-numeric-value arg)) 1299 (self-insert-command (prefix-numeric-value arg))
1289 (insert (if (or (memq (char-syntax (preceding-char)) '(?\( ?> ?\s)) 1300 ;; We'll be inserting fancy TeX quotes, but consider and imitate
1290 (memq (preceding-char) '(?~))) 1301 ;; `electric-pair-mode''s two behaviours: pair-insertion and
1291 tex-open-quote tex-close-quote)))) 1302 ;; region wrapping.
1303 ;;
1304 (if (and electric-pair-mode (use-region-p))
1305 (let* ((saved (point-marker)))
1306 (goto-char (mark))
1307 (insert (if (> saved (mark)) tex-open-quote tex-close-quote))
1308 (goto-char saved)
1309 (insert (if (> saved (mark)) tex-close-quote tex-open-quote)))
1310 (if (or (memq (char-syntax (preceding-char)) '(?\( ?> ?\s))
1311 (memq (preceding-char) '(?~)))
1312 (if electric-pair-mode
1313 (if (looking-at (regexp-quote tex-close-quote))
1314 (forward-char (length tex-close-quote))
1315 (insert tex-open-quote)
1316 (insert tex-close-quote)
1317 (backward-char (length tex-close-quote)))
1318 (insert tex-open-quote))
1319 (if (looking-at (regexp-quote tex-close-quote))
1320 (forward-char (length tex-close-quote))
1321 (insert tex-close-quote))))))
1292 1322
1293(defun tex-validate-buffer () 1323(defun tex-validate-buffer ()
1294 "Check current buffer for paragraphs containing mismatched braces or $s. 1324 "Check current buffer for paragraphs containing mismatched braces or $s.
diff --git a/test/ChangeLog b/test/ChangeLog
index 442e802a1bb..a117834cd34 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
12014-12-14 João Távora <joaotavora@gmail.com>
2
3 * automated/electric-tests.el (autowrapping-7): Tests for
4 tex-mode.
5
12014-12-13 Glenn Morris <rgm@gnu.org> 62014-12-13 Glenn Morris <rgm@gnu.org>
2 7
3 * automated/flymake/warnpred/test.pl: Tweak format, since the 8 * automated/flymake/warnpred/test.pl: Tweak format, since the
diff --git a/test/automated/electric-tests.el b/test/automated/electric-tests.el
index b1908e6bb32..cd07213bf20 100644
--- a/test/automated/electric-tests.el
+++ b/test/automated/electric-tests.el
@@ -60,7 +60,7 @@
60 (cl-progv 60 (cl-progv
61 (mapcar #'car bindings) 61 (mapcar #'car bindings)
62 (mapcar #'cdr bindings) 62 (mapcar #'cdr bindings)
63 (self-insert-command 1)))) 63 (call-interactively (key-binding `[,last-command-event])))))
64 (should (equal (buffer-substring-no-properties (point-min) (point-max)) 64 (should (equal (buffer-substring-no-properties (point-min) (point-max))
65 expected-string)) 65 expected-string))
66 (should (equal (point) 66 (should (equal (point)
@@ -575,5 +575,14 @@ baz\"\""
575 (skip-chars-backward "\"") 575 (skip-chars-backward "\"")
576 (mark-sexp -1))) 576 (mark-sexp -1)))
577 577
578(define-electric-pair-test autowrapping-7
579 "foo" "\"" :expected-string "``foo''" :expected-point 8
580 :modes '(tex-mode)
581 :fixture-fn #'(lambda ()
582 (electric-pair-mode 1)
583 (goto-char (point-max))
584 (skip-chars-backward "\"")
585 (mark-sexp -1)))
586
578(provide 'electric-tests) 587(provide 'electric-tests)
579;;; electric-tests.el ends here 588;;; electric-tests.el ends here