Skip to content

Commit

Permalink
[Fix #786] Hyperlinks in elisp are valid if followed by punctuation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuco1 committed Mar 4, 2018
1 parent 68a4597 commit 826bdcd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
27 changes: 17 additions & 10 deletions smartparens-config.el
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,23 @@ ID, ACTION, CONTEXT."
;; Ignore errors due to us being at the start or end of the
;; buffer.
(ignore-errors
(or (and (looking-at "\\sw\\|\\s_")
(save-excursion
(backward-char 2)
(looking-at "\\sw\\|\\s_")))
(and (save-excursion
(backward-char 1)
(looking-at "\\sw\\|\\s_"))
(save-excursion
(forward-char 1)
(looking-at "\\sw\\|\\s_")))))))
(or
;; foo'|bar
(and (looking-at "\\sw\\|\\s_")
;; do not consider punctuation
(not (looking-at "[?.,;!]"))
(save-excursion
(backward-char 2)
(looking-at "\\sw\\|\\s_")))
;; foo|'bar
(and (save-excursion
(backward-char 1)
(looking-at "\\sw\\|\\s_"))
(save-excursion
(forward-char 1)
(looking-at "\\sw\\|\\s_")
;; do not consider punctuation
(not (looking-at "[?.,;!]"))))))))

;; emacs is lisp hacking enviroment, so we set up some most common
;; lisp modes too
Expand Down
15 changes: 15 additions & 0 deletions test/smartparens-elisp-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(ert-deftest sp-test-elisp-invalid-hyperlink/point-before-contraction ()
(sp-test-with-temp-elisp-buffer "; foo|'bar"
(should (sp-lisp-invalid-hyperlink-p nil 'navigate nil))))

(ert-deftest sp-test-elisp-invalid-hyperlink/point-after-contraction ()
(sp-test-with-temp-elisp-buffer "; foo'|bar"
(should (sp-lisp-invalid-hyperlink-p nil 'navigate nil))))

(ert-deftest sp-test-elisp-invalid-hyperlink/point-before-before-punctuation ()
(sp-test-with-temp-elisp-buffer "; foo|'."
(should-not (sp-lisp-invalid-hyperlink-p nil 'navigate nil))))

(ert-deftest sp-test-elisp-invalid-hyperlink/point-after-before-punctuation ()
(sp-test-with-temp-elisp-buffer "; foo'|."
(should-not (sp-lisp-invalid-hyperlink-p nil 'navigate nil))))
6 changes: 6 additions & 0 deletions test/smartparens-get-paired-expression-elisp-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,9 @@ Test https://github.com/Fuco1/smartparens/issues/653"
;; with sexp in front
(sp-test--paired-expression-parse-in-elisp "(defun true () t)\n ;; asd |(as d\n ;; asd\n ;; asd) as\n" '(:beg 28 :end 52 :op "(" :cl ")" :prefix "" :suffix ""))
(sp-test--paired-expression-parse-in-elisp "(defun true () t)\n ;; asd (as d\n ;; asd\n ;; asd)| as\n" '(:beg 28 :end 52 :op "(" :cl ")" :prefix "" :suffix "") t))

;; #786
(ert-deftest sp-test-get-paired-expression-valid-hyperlink ()
(sp-test--paired-expression-parse-in-elisp
";; |`foo-bar'."
(list :beg 4 :end 13 :op "`" :cl "'" :prefix "" :suffix "")))

0 comments on commit 826bdcd

Please sign in to comment.