diff options
| author | Philipp Stephani | 2017-06-15 11:49:56 +0200 |
|---|---|---|
| committer | Philipp Stephani | 2017-06-16 18:06:28 +0200 |
| commit | 3b6e01cccf89ba0f3485751125f43463bc429345 (patch) | |
| tree | 439adae70db311405f2abd6369ad75004eb2eca4 | |
| parent | ea196ebb93188b0962f478f5dec0ff0645c4da10 (diff) | |
| download | emacs-3b6e01cccf89ba0f3485751125f43463bc429345.tar.gz emacs-3b6e01cccf89ba0f3485751125f43463bc429345.zip | |
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.
| -rw-r--r-- | lisp/thingatpt.el | 4 | ||||
| -rw-r--r-- | test/lisp/thingatpt-tests.el | 9 |
2 files changed, 12 insertions, 1 deletions
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el index 25e01df70ee..7c3d73e52b7 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)." | |||
| 380 | (save-restriction | 380 | (save-restriction |
| 381 | (narrow-to-region (1- url-beg) (min end (point-max))) | 381 | (narrow-to-region (1- url-beg) (min end (point-max))) |
| 382 | (setq paren-end (ignore-errors | 382 | (setq paren-end (ignore-errors |
| 383 | (scan-lists (1- url-beg) 1 0)))) | 383 | ;; Make the scan work inside comments. |
| 384 | (let ((parse-sexp-ignore-comments nil)) | ||
| 385 | (scan-lists (1- url-beg) 1 0))))) | ||
| 384 | (not (blink-matching-check-mismatch (1- url-beg) paren-end)) | 386 | (not (blink-matching-check-mismatch (1- url-beg) paren-end)) |
| 385 | (setq end (1- paren-end))) | 387 | (setq end (1- paren-end))) |
| 386 | ;; Ensure PT is actually within BOUNDARY. Check the following | 388 | ;; Ensure PT is actually within BOUNDARY. Check the following |
diff --git a/test/lisp/thingatpt-tests.el b/test/lisp/thingatpt-tests.el index d4449eacbf9..128534264e5 100644 --- a/test/lisp/thingatpt-tests.el +++ b/test/lisp/thingatpt-tests.el | |||
| @@ -120,4 +120,13 @@ position to retrieve THING.") | |||
| 120 | (should (equal (list-at-point) | 120 | (should (equal (list-at-point) |
| 121 | (cdr str-res))))))) | 121 | (cdr str-res))))))) |
| 122 | 122 | ||
| 123 | (ert-deftest thing-at-point-url-in-comment () | ||
| 124 | (with-temp-buffer | ||
| 125 | (c-mode) | ||
| 126 | (insert "/* (http://foo/bar)\n(http://foo/bar(baz)) */\n") | ||
| 127 | (goto-char 6) | ||
| 128 | (should (equal (thing-at-point 'url) "http://foo/bar")) | ||
| 129 | (goto-char 23) | ||
| 130 | (should (equal (thing-at-point 'url) "http://foo/bar(baz)")))) | ||
| 131 | |||
| 123 | ;;; thingatpt.el ends here | 132 | ;;; thingatpt.el ends here |