aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Stephani2017-07-02 18:14:21 +0200
committerPhilipp Stephani2017-07-09 21:55:31 +0200
commitbb2ea81bc569bdc51e1c9af1c503a22fb95e4384 (patch)
tree6daac769532574d017f24fe386d23f136072bd56
parent633db417fc3e905b28b017facdf596b36914b44d (diff)
downloademacs-bb2ea81bc569bdc51e1c9af1c503a22fb95e4384.tar.gz
emacs-bb2ea81bc569bdc51e1c9af1c503a22fb95e4384.zip
Further improve electric quote support for Markdown (Bug#24709)
Markdown sets both 'comment-start' and 'comment-use-syntax' to non-nil values. Therefore 'electric-quote-mode' recognized it as a programming mode. Fix this by first checking whether the current major mode is derived from 'text-mode'. * lisp/electric.el (electric-quote-post-self-insert-function): Treat 'text-mode' as stronger signal than comment syntax. * test/lisp/electric-tests.el (electric-quote-markdown-in-text) (electric-quote-markdown-in-code): Adapt unit tests.
-rw-r--r--lisp/electric.el28
-rw-r--r--test/lisp/electric-tests.el4
2 files changed, 18 insertions, 14 deletions
diff --git a/lisp/electric.el b/lisp/electric.el
index 96c805bb5fb..a71e79ff78a 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -469,20 +469,20 @@ This requotes when a quoting key is typed."
469 (and (not electric-quote-context-sensitive) 469 (and (not electric-quote-context-sensitive)
470 (eq last-command-event ?\`))) 470 (eq last-command-event ?\`)))
471 (not (run-hook-with-args-until-success 471 (not (run-hook-with-args-until-success
472 'electric-quote-inhibit-functions))) 472 'electric-quote-inhibit-functions))
473 (if (and comment-start comment-use-syntax) 473 (if (derived-mode-p 'text-mode)
474 (when (or electric-quote-comment electric-quote-string) 474 electric-quote-paragraph
475 (let* ((syntax (syntax-ppss)) 475 (and comment-start comment-use-syntax
476 (beg (nth 8 syntax))) 476 (or electric-quote-comment electric-quote-string)
477 (and beg 477 (let* ((syntax (syntax-ppss))
478 (or (and electric-quote-comment (nth 4 syntax)) 478 (beg (nth 8 syntax)))
479 (and electric-quote-string (nth 3 syntax))) 479 (and beg
480 ;; Do not requote a quote that starts or ends 480 (or (and electric-quote-comment (nth 4 syntax))
481 ;; a comment or string. 481 (and electric-quote-string (nth 3 syntax)))
482 (eq beg (nth 8 (save-excursion 482 ;; Do not requote a quote that starts or ends
483 (syntax-ppss (1- (point))))))))) 483 ;; a comment or string.
484 (and electric-quote-paragraph 484 (eq beg (nth 8 (save-excursion
485 (derived-mode-p 'text-mode)))) 485 (syntax-ppss (1- (point)))))))))))
486 (pcase electric-quote-chars 486 (pcase electric-quote-chars
487 (`(,q< ,q> ,q<< ,q>>) 487 (`(,q< ,q> ,q<< ,q>>)
488 (save-excursion 488 (save-excursion
diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el
index c4ccec7a0d8..c6ffccc0794 100644
--- a/test/lisp/electric-tests.el
+++ b/test/lisp/electric-tests.el
@@ -694,6 +694,8 @@ baz\"\""
694 :bindings '((electric-quote-context-sensitive . t)) 694 :bindings '((electric-quote-context-sensitive . t))
695 :test-in-comments nil :test-in-strings nil) 695 :test-in-comments nil :test-in-strings nil)
696 696
697;; Simulate ‘markdown-mode’: it sets both ‘comment-start’ and
698;; ‘comment-use-syntax’, but derives from ‘text-mode’.
697(define-electric-pair-test electric-quote-markdown-in-text 699(define-electric-pair-test electric-quote-markdown-in-text
698 "" "'" :expected-string "’" :expected-point 2 700 "" "'" :expected-string "’" :expected-point 2
699 :modes '(text-mode) 701 :modes '(text-mode)
@@ -703,6 +705,7 @@ baz\"\""
703 (lambda () 705 (lambda ()
704 (save-excursion (search-backward "`" nil t))) 706 (save-excursion (search-backward "`" nil t)))
705 nil :local)) 707 nil :local))
708 :bindings '((comment-start . "<!--") (comment-use-syntax . t))
706 :test-in-comments nil :test-in-strings nil) 709 :test-in-comments nil :test-in-strings nil)
707 710
708(define-electric-pair-test electric-quote-markdown-in-code 711(define-electric-pair-test electric-quote-markdown-in-code
@@ -714,6 +717,7 @@ baz\"\""
714 (lambda () 717 (lambda ()
715 (save-excursion (search-backward "`" nil t))) 718 (save-excursion (search-backward "`" nil t)))
716 nil :local)) 719 nil :local))
720 :bindings '((comment-start . "<!--") (comment-use-syntax . t))
717 :test-in-comments nil :test-in-strings nil) 721 :test-in-comments nil :test-in-strings nil)
718 722
719(provide 'electric-tests) 723(provide 'electric-tests)