emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 3b6e01c: Correctly detect URLs surrounded by parent


From: Philipp Stephani
Subject: [Emacs-diffs] master 3b6e01c: Correctly detect URLs surrounded by parentheses in comments
Date: Fri, 16 Jun 2017 12:26:28 -0400 (EDT)

branch: master
commit 3b6e01cccf89ba0f3485751125f43463bc429345
Author: Philipp Stephani <address@hidden>
Commit: Philipp Stephani <address@hidden>

    Correctly detect URLs surrounded by parentheses in comments
    
    * lisp/thingatpt.el (thing-at-point--bounds-of-well-formed-url):
    Make parentheses match work inside comments.
    
    * test/lisp/thingatpt-tests.el (thing-at-point-url-in-comment): Add
    unit test.
---
 lisp/thingatpt.el            | 4 +++-
 test/lisp/thingatpt-tests.el | 9 +++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index 25e01df..7c3d73e 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -380,7 +380,9 @@ the bounds of a possible ill-formed URI (one lacking a 
scheme)."
             (save-restriction
               (narrow-to-region (1- url-beg) (min end (point-max)))
               (setq paren-end (ignore-errors
-                                (scan-lists (1- url-beg) 1 0))))
+                                 ;; Make the scan work inside comments.
+                                 (let ((parse-sexp-ignore-comments nil))
+                                   (scan-lists (1- url-beg) 1 0)))))
             (not (blink-matching-check-mismatch (1- url-beg) paren-end))
             (setq end (1- paren-end)))
        ;; Ensure PT is actually within BOUNDARY. Check the following
diff --git a/test/lisp/thingatpt-tests.el b/test/lisp/thingatpt-tests.el
index d4449ea..1285342 100644
--- a/test/lisp/thingatpt-tests.el
+++ b/test/lisp/thingatpt-tests.el
@@ -120,4 +120,13 @@ position to retrieve THING.")
         (should (equal (list-at-point)
                        (cdr str-res)))))))
 
+(ert-deftest thing-at-point-url-in-comment ()
+  (with-temp-buffer
+    (c-mode)
+    (insert "/* (http://foo/bar)\n(http://foo/bar(baz)) */\n")
+    (goto-char 6)
+    (should (equal (thing-at-point 'url) "http://foo/bar";))
+    (goto-char 23)
+    (should (equal (thing-at-point 'url) "http://foo/bar(baz)"))))
+
 ;;; thingatpt.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]