branch: elpa/smartparens
commit 773f930196c48b9b4d94a84a8cdceb04ada3801a
Merge: b0d935c118 4756255474
Author: Matus Goljer <matus.gol...@gmail.com>
Commit: GitHub <nore...@github.com>

    Merge pull request #1229 from thatismatt/master
    
    fix: ignore prefix syntax not in prefix position
---
 smartparens.el                    | 32 ++++++++++++++++------------
 test/smartparens-commands-test.el | 44 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 61 insertions(+), 15 deletions(-)

diff --git a/smartparens.el b/smartparens.el
index 492c1c73c2..9cdc8dfbdf 100644
--- a/smartparens.el
+++ b/smartparens.el
@@ -1944,29 +1944,33 @@ See `sp-get-buffer-char-syntax'."
   (setq p (or p (point)))
   (sp-get-buffer-char-syntax (1- p)))
 
-(defun sp-syntax-after-is-prefix (&optional p)
+(defun sp-syntax-after-is-prefix (check-prefix-flag &optional p)
   "Check that the character after P has prefix syntax.
 
 Prefix syntax can either come from the global major-mode syntax
 table, from the text property syntax-table or from the syntax
-flag (20)."
+flag (20).  The flag must be ignored once inside a symbol, this
+is done by passing CHECK-PREFIX-FLAG as nil."
   (setq p (or p (point)))
   (let ((parse-sexp-lookup-properties t))
     (when-let ((syntax (syntax-after p)))
       (or (= (syntax-class syntax) 6)
-          (/= 0 (logand (lsh 1 20) (car syntax)))))))
+          (and check-prefix-flag
+               (/= 0 (logand (lsh 1 20) (car syntax))))))))
 
-(defun sp-syntax-before-is-prefix (&optional p)
+(defun sp-syntax-before-is-prefix (check-prefix-flag &optional p)
   "Check that the character before P has prefix syntax.
 
 Prefix syntax can either come from the global major-mode syntax
 table, from the text property syntax-table or from the syntax
-flag (20)."
+flag (20).  The flag must be ignored once inside a symbol, this
+is done by passing CHECK-PREFIX-FLAG as nil."
   (setq p (or p (point)))
   (let ((parse-sexp-lookup-properties t))
     (when-let ((syntax (syntax-after (1- p))))
       (or (= (syntax-class syntax) 6)
-          (/= 0 (logand (lsh 1 20) (car syntax)))))))
+          (and check-prefix-flag
+               (/= 0 (logand (lsh 1 20) (car syntax))))))))
 
 (defun sp-syntax-after-is-word-or-symbol (&optional p)
   "Check that the character after P has word or symbol syntax.
@@ -1977,9 +1981,9 @@ regularly the character would be (for example according 
to the
 syntax table)."
   (setq p (or p (point)))
   (and (memq (sp-syntax-after p) '(?w ?_))
-       (not (sp-syntax-after-is-prefix p))))
+       (not (sp-syntax-after-is-prefix (not 
(sp-syntax-before-is-word-or-symbol t)) p))))
 
-(defun sp-syntax-before-is-word-or-symbol (&optional p)
+(defun sp-syntax-before-is-word-or-symbol (check-prefix-flag &optional p)
   "Check that the character before P has word or symbol syntax.
 
 In case the character has a special syntax flag 'p', meaning a
@@ -1988,7 +1992,7 @@ regularly the character would be (for example according 
to the
 syntax table)."
   (setq p (or p (point)))
   (and (memq (sp-syntax-before p) '(?w ?_))
-       (not (sp-syntax-before-is-prefix p))))
+       (not (sp-syntax-before-is-prefix check-prefix-flag p))))
 
 (defun sp-point-in-string (&optional p)
   "Return non-nil if point is inside string or documentation string.
@@ -7812,8 +7816,10 @@ Examples:
                         ,(if forward '(sp-syntax-after) '(sp-syntax-before))
                         '(?< ?> ?! ?| ?\ ?\\ ?\" ?' ?.))
                        ,(if forward
-                            '(sp-syntax-after-is-prefix (point))
-                          '(sp-syntax-before-is-prefix (point)))
+                            ;; ignore prefix syntax not in a prefix position
+                            '(and (not (sp-syntax-before-is-word-or-symbol t))
+                                  (sp-syntax-after-is-prefix t))
+                          '(sp-syntax-before-is-prefix t))
                        (unless in-comment (sp-point-in-comment))
                        ;; This is the case where we are starting at
                        ;; pair (looking at it) and there is some
@@ -7985,7 +7991,7 @@ Examples:
           (while (> n 0)
             (while (cond
                     ((bobp) nil)
-                    ((not (sp-syntax-before-is-word-or-symbol))
+                    ((not (sp-syntax-before-is-word-or-symbol t))
                      (backward-char)
                      t)
                     ((sp--valid-initial-delimiter-p (sp--looking-back open))
@@ -7995,7 +8001,7 @@ Examples:
             (while (and (not (bobp))
                         (not (or (sp--valid-initial-delimiter-p 
(sp--looking-back open))
                                  (sp--valid-initial-delimiter-p 
(sp--looking-back close))))
-                        (or (sp-syntax-before-is-word-or-symbol)
+                        (or (sp-syntax-before-is-word-or-symbol nil) ;; now 
inside symbol so ignore prefix flag
                             ;; Specifically for lisp, we consider
                             ;; sequences of ?\<ANYTHING> a symbol
                             ;; sequence
diff --git a/test/smartparens-commands-test.el 
b/test/smartparens-commands-test.el
index 32111e2add..ba6f80f755 100644
--- a/test/smartparens-commands-test.el
+++ b/test/smartparens-commands-test.el
@@ -200,13 +200,53 @@ be."
 
 (sp-test-command sp-forward-symbol
   ((nil
-    ("|foo bar" "foo| bar" "foo bar|"))
+    ("|foo bar" "foo| bar" "foo bar|")
+    ("|,foo ,bar" ",foo| ,bar" ",foo ,bar|")
+    ("|'foo 'bar" "'foo| 'bar" "'foo 'bar|"))
    (((mode 'clojure))
     ("|(map #(identity) {:a 1})"
      "(map| #(identity) {:a 1})"
      "(map #(identity|) {:a 1})"
      "(map #(identity) {:a| 1})"
-     "(map #(identity) {:a 1|})"))))
+     "(map #(identity) {:a 1|})")
+    ("|foo' 'bar qu'ux" "foo'| 'bar qu'ux" "foo' 'bar| qu'ux" "foo' 'bar 
qu'ux|")
+    ("|and# ~x ~@next" "and#| ~x ~@next" "and# ~x| ~@next" "and# ~x 
~@next|"))))
+
+(sp-test-command sp-backward-symbol
+  ((nil
+    ("foo bar|" "foo |bar" "|foo bar")
+    (",foo ,bar|" ",foo ,|bar" ",|foo ,bar" "|,foo ,bar")
+    ("'foo 'bar|" "'foo '|bar" "'|foo 'bar" "|'foo 'bar"))
+   (((mode 'clojure))
+    ("(map #(identity) {:a 1})|"
+     "(map #(identity) {:a |1})"
+     "(map #(identity) {|:a 1})"
+     "(map #(|identity) {:a 1})"
+     "(|map #(identity) {:a 1})")
+    ("foo' 'bar qu'ux|" "foo' 'bar |qu'ux" "foo' '|bar qu'ux" "|foo' 'bar 
qu'ux")
+    ("and# ~x ~@next|" "and# ~x ~@|next" "and# ~|x ~@next" "|and# ~x 
~@next"))))
+
+(sp-test-command sp-skip-forward-to-symbol
+  ((nil
+    ("foo|   bar" "foo   |bar")
+    ("foo| 'bar" "foo '|bar")
+    ("foo|   [bar baz]" "foo   |[bar baz]"))))
+
+(sp-test-command sp-wrap-round
+  ((nil
+    ("|foo bar" "(|foo) bar")
+    ("fo|o bar" "(|foo) bar")
+    ("foo| bar" "foo (|bar)")
+    ("'|foo" "'(|foo)")
+    ("'f|oo" "(|'foo)")
+    ("|'foo" "(|'foo)"))
+   (((mode 'clojure))
+    ("f|n?" "(|fn?)")
+    ("fn|?" "(|fn?)")
+    ("|#(foo)" "(|#(foo))")
+    ("#|(foo)" "#(|(foo))")
+    ("?|#(:clj x)" "(|?#(:clj x))")
+    ("?#|(:clj x)" "?#(|(:clj x))"))))
 
 (sp-test-command sp-forward-parallel-sexp
   ((nil

Reply via email to