]> git.eshelyaron.com Git - emacs.git/commitdiff
Inhibit quote autopairing more frequently
authorJoão Távora <joaotavora@gmail.com>
Mon, 7 Apr 2014 07:24:03 +0000 (08:24 +0100)
committerJoão Távora <joaotavora@gmail.com>
Mon, 7 Apr 2014 07:24:03 +0000 (08:24 +0100)
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'.

lisp/ChangeLog
lisp/elec-pair.el
test/ChangeLog
test/automated/electric-tests.el

index 26004f8d6e2e86c1661f9ac2a7f84f71a9685cfb..9d2fd9854e84534935a3afbacb7e8926ee43b4a8 100644 (file)
@@ -1,3 +1,11 @@
+2014-04-07  João Távora  <joaotavora@gmail.com>
+
+       * 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.
+
 2014-04-07  Glenn Morris  <rgm@gnu.org>
 
        * shell.el (shell-directory-tracker):
index 32afcd88380d76cc91d93f53596efeaaa345b2e1..2a3e4008269e83c34c5c7ca818a9c464add2bbc3 100644 (file)
@@ -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)
index d483b0b2f9e74a8163bb0f41c8a6a2bdd69b4875..c94bf21fd36c396c6c355746f642e399b27c7eff 100644 (file)
@@ -1,3 +1,8 @@
+2014-04-07  João Távora  <joaotavora@gmail.com>
+
+       * automated/electric-tests.el (inhibit-if-strings-mismatched):
+       New test, change from `inhibit-only-of-next-is-mismatched'.
+
 2014-04-06  João Távora  <joaotavora@gmail.com>
 
        * automated/python-tests.el (python-triple-quote-pairing): New test.
index 184a91f5105e000fc220cd3d72d403cdce83dd10..301130747f3ce8317a9ac4a845c671dae353ee15 100644 (file)
@@ -295,9 +295,9 @@ Should %s |%s| and point at %d"
   :bindings `((electric-pair-text-syntax-table
                . ,prog-mode-syntax-table)))
 
-(define-electric-pair-test inhibit-only-if-next-is-mismatched
+(define-electric-pair-test inhibit-if-strings-mismatched
   "\"foo\"\"bar" "\""
-  :expected-string "\"\"\"foo\"\"bar"
+  :expected-string "\"\"foo\"\"bar"
   :expected-point 2
   :test-in-strings nil
   :bindings `((electric-pair-text-syntax-table