From 6735df4443fe0aa60862a95c38746edf2b053862 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Sun, 31 Dec 2017 17:43:43 +0100 Subject: [PATCH] Ignore escape characters for context-sensitive quotes (Bug#29812) * lisp/electric.el (electric-quote-post-self-insert-function): Skip over escape characters when determining whether a context-sensitive quote should be opening or closing. * test/lisp/electric-tests.el (electric-quote-replace-double-escaped-open) (electric-quote-replace-double-escaped-close): New unit tests. --- lisp/electric.el | 1 + test/lisp/electric-tests.el | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lisp/electric.el b/lisp/electric.el index 8343d8c1b13..c00e7c00a59 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -505,6 +505,7 @@ This requotes when a quoting key is typed." (eq last-command-event ?\"))) (save-excursion (backward-char) + (skip-syntax-backward "\\") (or (bobp) (bolp) (memq (char-before) (list q< q<<)) (memq (char-syntax (char-before)) diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el index 44bdbc7b8c8..60191bfbbaa 100644 --- a/test/lisp/electric-tests.el +++ b/test/lisp/electric-tests.el @@ -742,6 +742,24 @@ baz\"\"" :bindings '((electric-quote-replace-double . t)) :test-in-comments nil :test-in-strings nil) +(define-electric-pair-test electric-quote-replace-double-escaped-open + "foo \\" "-----\"" :expected-string "foo \\“" + :expected-point 7 :modes '(emacs-lisp-mode c-mode) + :fixture-fn #'electric-quote-local-mode + :bindings '((electric-quote-replace-double . t) + (electric-quote-comment . t) + (electric-quote-string . t)) + :test-in-comments t :test-in-strings t :test-in-code nil) + +(define-electric-pair-test electric-quote-replace-double-escaped-close + "foo \\“foo\\" "----------\"" :expected-string "foo \\“foo\\”" + :expected-point 12 :modes '(emacs-lisp-mode c-mode) + :fixture-fn #'electric-quote-local-mode + :bindings '((electric-quote-replace-double . t) + (electric-quote-comment . t) + (electric-quote-string . t)) + :test-in-comments t :test-in-strings t :test-in-code 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 -- 2.39.5