]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix `goto-address-url-regexp'
authorPhil Sainty <psainty@orcon.net.nz>
Tue, 25 Jun 2019 14:02:12 +0000 (16:02 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 25 Jun 2019 14:02:12 +0000 (16:02 +0200)
* lisp/net/goto-addr.el (goto-address-uri-schemes-ignored): New
variable.
(goto-address-uri-schemes): Ditto.
(goto-address-url-regexp): Use them to compose the final regexp.

* lisp/net/goto-addr.el: The URI schemes to be recognised by
`goto-address-mode' were not regexp-quoted (Bug#23343).

etc/NEWS
lisp/net/goto-addr.el

index 101b7f5b7bb26bdb7ac54ca859b2a37ae580ba47..eac7a7f6947591392348ca8dc39e7e45ac05f5cb 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -475,6 +475,11 @@ current and the previous or the next line, as before.
 \f
 * Changes in Specialized Modes and Packages in Emacs 27.1
 
+** goto-addr
+*** A way to more conveniently specify what URI address schemes that
+should be ignored have been added via the
+`goto-address-uri-schemes-ignored' variable.
+
 ** tex-mode
 *** 'latex-noindent-commands' stops indenting arguments of \emph and friends
 
index af2b83653dd5ea83de6ed12864a02bf31c6bb9ab..eaa1356955af34f2b48d9008882f4af3e5753d5f 100644 (file)
@@ -59,6 +59,7 @@
 
 ;;; Code:
 
+(require 'seq)
 (require 'thingatpt)
 (autoload 'browse-url-url-at-point "browse-url")
 
@@ -101,23 +102,32 @@ A value of t means there is no limit--fontify regardless of the size."
   "[-a-zA-Z0-9=._+]+@\\([-a-zA-Z0-9_]+\\.\\)+[a-zA-Z0-9]+"
   "A regular expression probably matching an e-mail address.")
 
+(defvar goto-address-uri-schemes-ignored
+  ;; By default we exclude `mailto:' (email addresses are matched
+  ;; by `goto-address-mail-regexp') and also `data:', as it is not
+  ;; terribly useful to follow those URIs, and leaving them causes
+  ;; `use Data::Dumper;' to be fontified oddly in Perl files.
+  '("mailto:" "data:")
+  "List of URI schemes to exclude from `goto-address-uri-schemes'.
+
+Customisations to this variable made after goto-addr is loaded
+will have no effect.")
+
+(defvar goto-address-uri-schemes
+  ;; We use `thing-at-point-uri-schemes', with a few exclusions,
+  ;; as listed in `goto-address-uri-schemes-ignored'.
+  (seq-reduce (lambda (accum elt) (delete elt accum))
+              goto-address-uri-schemes-ignored
+              (copy-sequence thing-at-point-uri-schemes))
+  "List of URI schemes matched by `goto-address-url-regexp'.
+
+Customisations to this variable made after goto-addr is loaded
+will have no effect.")
+
 (defvar goto-address-url-regexp
-  (concat
-   "\\<\\("
-   (mapconcat 'identity
-              (delete "mailto:"
-                     ;; Remove `data:', as it's not terribly useful to follow
-                     ;; those.  Leaving them causes `use Data::Dumper;' to be
-                     ;; fontified oddly in Perl files.
-                      (delete "data:"
-                              (copy-sequence thing-at-point-uri-schemes)))
-              "\\|")
-   "\\)"
-   thing-at-point-url-path-regexp)
-  ;; (concat "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|"
-  ;;     "telnet\\|wais\\):\\(//[-a-zA-Z0-9_.]+:"
-  ;;     "[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*"
-  ;;     "[-a-zA-Z0-9_=#$@~`%&*+|\\/]")
+  (concat "\\<"
+          (regexp-opt goto-address-uri-schemes t)
+          thing-at-point-url-path-regexp)
   "A regular expression probably matching a URL.")
 
 (defvar goto-address-highlight-keymap