]> git.eshelyaron.com Git - emacs.git/commitdiff
Further improve electric quote support for Markdown (Bug#24709)
authorPhilipp Stephani <phst@google.com>
Sun, 2 Jul 2017 16:14:21 +0000 (18:14 +0200)
committerPhilipp Stephani <phst@google.com>
Sun, 9 Jul 2017 19:55:31 +0000 (21:55 +0200)
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.

lisp/electric.el
test/lisp/electric-tests.el

index 96c805bb5fbba5365fb0171112a885705bda9fb4..a71e79ff78a4abf7b06b73e8a83f05939c64f419 100644 (file)
@@ -469,20 +469,20 @@ This requotes when a quoting key is typed."
                  (and (not electric-quote-context-sensitive)
                       (eq last-command-event ?\`)))
              (not (run-hook-with-args-until-success
-                   'electric-quote-inhibit-functions)))
-             (if (and comment-start comment-use-syntax)
-                 (when (or electric-quote-comment electric-quote-string)
-                   (let* ((syntax (syntax-ppss))
-                          (beg (nth 8 syntax)))
-                     (and beg
-                          (or (and electric-quote-comment (nth 4 syntax))
-                              (and electric-quote-string (nth 3 syntax)))
-                          ;; Do not requote a quote that starts or ends
-                          ;; a comment or string.
-                          (eq beg (nth 8 (save-excursion
-                                           (syntax-ppss (1- (point)))))))))
-               (and electric-quote-paragraph
-                    (derived-mode-p 'text-mode))))
+                   'electric-quote-inhibit-functions))
+             (if (derived-mode-p 'text-mode)
+                 electric-quote-paragraph
+               (and comment-start comment-use-syntax
+                    (or electric-quote-comment electric-quote-string)
+                    (let* ((syntax (syntax-ppss))
+                           (beg (nth 8 syntax)))
+                      (and beg
+                           (or (and electric-quote-comment (nth 4 syntax))
+                               (and electric-quote-string (nth 3 syntax)))
+                           ;; Do not requote a quote that starts or ends
+                           ;; a comment or string.
+                           (eq beg (nth 8 (save-excursion
+                                            (syntax-ppss (1- (point)))))))))))
     (pcase electric-quote-chars
       (`(,q< ,q> ,q<< ,q>>)
        (save-excursion
index c4ccec7a0d828720a51c3b952a0e4dd9534f01a6..c6ffccc0794858e793087d97a150597e65750805 100644 (file)
@@ -694,6 +694,8 @@ baz\"\""
   :bindings '((electric-quote-context-sensitive . t))
   :test-in-comments nil :test-in-strings nil)
 
+;; Simulate ‘markdown-mode’: it sets both ‘comment-start’ and
+;; ‘comment-use-syntax’, but derives from ‘text-mode’.
 (define-electric-pair-test electric-quote-markdown-in-text
   "" "'" :expected-string "’" :expected-point 2
   :modes '(text-mode)
@@ -703,6 +705,7 @@ baz\"\""
                           (lambda ()
                             (save-excursion (search-backward "`" nil t)))
                           nil :local))
+  :bindings '((comment-start . "<!--") (comment-use-syntax . t))
   :test-in-comments nil :test-in-strings nil)
 
 (define-electric-pair-test electric-quote-markdown-in-code
@@ -714,6 +717,7 @@ baz\"\""
                           (lambda ()
                             (save-excursion (search-backward "`" nil t)))
                           nil :local))
+  :bindings '((comment-start . "<!--") (comment-use-syntax . t))
   :test-in-comments nil :test-in-strings nil)
 
 (provide 'electric-tests)