diff options
author | João Távora <joaotavora@gmail.com> | 2014-04-07 08:24:03 +0100 |
---|---|---|
committer | João Távora <joaotavora@gmail.com> | 2014-04-07 08:24:03 +0100 |
commit | 528c33b52868be1d01353f00996d8c63804f74e0 (patch) | |
tree | b45b765b3e2fc9ba2b88da2a2be3763e953d71f3 /lisp/elec-pair.el | |
parent | a9c921e66b68c4bdc699171d467be09ca327acb2 (diff) | |
download | emacs-528c33b52868be1d01353f00996d8c63804f74e0.tar.gz |
Inhibit quote autopairing more frequently
Backported from trunk 2014-04-02T09:59:06Z!joaotavora@gmail.com
* lisp/elec-pair.el (electric-pair-inhibit-if-helps-balance): Inhibit
quote pairing if point-max is inside an unterminated string.
(electric-pair--looking-at-unterminated-string-p):
Delete.
(electric-pair--in-unterminated-string-p): New function.
* test/automated/electric-tests.el (inhibit-if-strings-mismatched):
New test, change from `inhibit-only-of-next-is-mismatched'.
Diffstat (limited to 'lisp/elec-pair.el')
-rw-r--r-- | lisp/elec-pair.el | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el index 32afcd88380..2a3e4008269 100644 --- a/lisp/elec-pair.el +++ b/lisp/elec-pair.el @@ -334,18 +334,17 @@ If point is not enclosed by any lists, return ((t) . (t))." (funcall ended-prematurely-fn))))))) (cons innermost outermost))) -(defun electric-pair--looking-at-unterminated-string-p (char) - "Return non-nil if following string starts with CHAR and is unterminated." - ;; FIXME: ugly/naive - (save-excursion - (skip-chars-forward (format "^%c" char)) - (while (not (zerop (% (save-excursion (skip-syntax-backward "\\")) 2))) - (unless (eobp) - (forward-char 1) - (skip-chars-forward (format "^%c" char)))) - (and (not (eobp)) - (condition-case nil - (progn (forward-sexp) nil) +(defun electric-pair--in-unterminated-string-p (char) + "Return non-nil if inside unterminated string started by CHAR" + (let* ((ppss (syntax-ppss)) + (relevant-ppss (if (nth 4 ppss) ; in comment + (electric-pair--syntax-ppss) + ppss)) + (string-delim (nth 3 relevant-ppss))) + (and (or (eq t string-delim) + (eq char string-delim)) + (condition-case nil (progn (scan-sexps (nth 8 relevant-ppss) 1) + nil) (scan-error t))))) (defun electric-pair--inside-string-p (char) @@ -379,7 +378,9 @@ happened." (t (eq (cdr outermost) pair))))) ((eq syntax ?\") - (electric-pair--looking-at-unterminated-string-p char)))) + (save-excursion + (goto-char (point-max)) + (electric-pair--in-unterminated-string-p char))))) (insert-char char))))) (defun electric-pair-skip-if-helps-balance (char) |