aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorJoao Tavora2014-12-14 11:22:46 +0000
committerJoao Tavora2014-12-14 11:22:46 +0000
commitbb57c94d5f047cde106ffa71bf59f24b2b3027b8 (patch)
tree90bcb89e16d1fef22bd06d8035ac0797b11def88 /lisp
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.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/textmodes/tex-mode.el50
2 files changed, 45 insertions, 10 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.