]> git.eshelyaron.com Git - emacs.git/commitdiff
Correctly detect URLs surrounded by parentheses in comments
authorPhilipp Stephani <phst@google.com>
Thu, 15 Jun 2017 09:49:56 +0000 (11:49 +0200)
committerPhilipp Stephani <phst@google.com>
Fri, 16 Jun 2017 16:06:28 +0000 (18:06 +0200)
* 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
test/lisp/thingatpt-tests.el

index 25e01df70ee5068a5738a41558bc92adfae795c2..7c3d73e52b7ce33e28c8c9ce634f5ad9cc5778ed 100644 (file)
@@ -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
index d4449eacbf9855329aaf4684ade4defd8ec54854..128534264e57fd55ca3cad62d3f7b535ba3e769e 100644 (file)
@@ -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