From 1a4d0ada2450f22246ad22d25e7c15d8da3c5249 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Sun, 2 Jul 2017 18:14:21 +0200 Subject: [PATCH 3/3] 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. --- lisp/electric.el | 34 +++++++++++++++++----------------- test/lisp/electric-tests.el | 8 ++++++-- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/lisp/electric.el b/lisp/electric.el index a1e9079cb1..c335ae5d72 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -461,23 +461,23 @@ electric-quote-post-self-insert-function (or (eq last-command-event ?\') (and (not electric-quote-context-sensitive) (eq last-command-event ?\`))) - (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) - ;; FIXME: There should be a ‘cl-disjoint’ function. - (null (cl-intersection (face-at-point nil 'multiple) - electric-quote-code-faces - :test #'eq))))) + (if (derived-mode-p 'text-mode) + (and electric-quote-paragraph + ;; FIXME: There should be a ‘cl-disjoint’ function. + (null (cl-intersection (face-at-point nil 'multiple) + electric-quote-code-faces + :test #'eq))) + (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 diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el index 6f63d30e75..4212198b0a 100644 --- a/test/lisp/electric-tests.el +++ b/test/lisp/electric-tests.el @@ -694,11 +694,14 @@ electric-quote-context-sensitive-after-paren-double :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) :fixture-fn #'electric-quote-local-mode - :bindings '((electric-quote-code-faces font-lock-constant-face)) + :bindings '((electric-quote-code-faces font-lock-constant-face) + (comment-start "