diff options
Diffstat (limited to 'lisp/net/goto-addr.el')
-rw-r--r-- | lisp/net/goto-addr.el | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/lisp/net/goto-addr.el b/lisp/net/goto-addr.el index d1926302470..2c43d0f7532 100644 --- a/lisp/net/goto-addr.el +++ b/lisp/net/goto-addr.el @@ -1,4 +1,4 @@ -;;; goto-addr.el --- click to browse URL or to send to e-mail address +;;; goto-addr.el --- click to browse URL or to send to e-mail address -*- lexical-binding: t; -*- ;; Copyright (C) 1995, 2000-2021 Free Software Foundation, Inc. @@ -73,19 +73,16 @@ (defcustom goto-address-fontify-p t "Non-nil means URLs and e-mail addresses in buffer are fontified. But only if `goto-address-highlight-p' is also non-nil." - :type 'boolean - :group 'goto-address) + :type 'boolean) (defcustom goto-address-highlight-p t "Non-nil means URLs and e-mail addresses in buffer are highlighted." - :type 'boolean - :group 'goto-address) + :type 'boolean) (defcustom goto-address-fontify-maximum-size 30000 "Maximum size of file in which to fontify and/or highlight URLs. A value of t means there is no limit--fontify regardless of the size." - :type '(choice (integer :tag "Maximum size") (const :tag "No limit" t)) - :group 'goto-address) + :type '(choice (integer :tag "Maximum size") (const :tag "No limit" t))) (defvar goto-address-mail-regexp ;; Actually pretty much any char could appear in the username part. -stef @@ -122,30 +119,34 @@ will have no effect.") (defvar goto-address-highlight-keymap (let ((m (make-sparse-keymap))) - (define-key m (kbd "<mouse-2>") 'goto-address-at-point) - (define-key m (kbd "C-c RET") 'goto-address-at-point) + (define-key m (kbd "<mouse-2>") #'goto-address-at-point) + (define-key m (kbd "C-c RET") #'goto-address-at-point) m) "Keymap to hold goto-addr's mouse key defs under highlighted URLs.") +(defun goto-address-context-menu (menu) + (when (mouse-posn-property (event-start last-input-event) 'goto-address) + (define-key menu [goto-address-separator] menu-bar-separator) + (define-key menu [goto-address-at-mouse] + '(menu-item "Follow Link" goto-address-at-mouse + :help "Follow a link where you click"))) + menu) + (defcustom goto-address-url-face 'link "Face to use for URLs." - :type 'face - :group 'goto-address) + :type 'face) (defcustom goto-address-url-mouse-face 'highlight "Face to use for URLs when the mouse is on them." - :type 'face - :group 'goto-address) + :type 'face) (defcustom goto-address-mail-face 'italic "Face to use for e-mail addresses." - :type 'face - :group 'goto-address) + :type 'face) (defcustom goto-address-mail-mouse-face 'secondary-selection "Face to use for e-mail addresses when the mouse is on them." - :type 'face - :group 'goto-address) + :type 'face) (defun goto-address-unfontify (start end) "Remove `goto-address' fontification from the given region." @@ -252,6 +253,11 @@ address. If no e-mail address found, return nil." (goto-char (match-beginning 0)))) (match-string-no-properties 0))) +(defun goto-address-at-mouse (click) + "Send to the e-mail address or load the URL at mouse click." + (interactive "e") + (goto-address-at-point click)) + ;;;###autoload (defun goto-address () "Sets up goto-address functionality in the current buffer. @@ -270,15 +276,17 @@ Also fontifies the buffer appropriately (see `goto-address-fontify-p' and ;;;###autoload (define-minor-mode goto-address-mode "Minor mode to buttonize URLs and e-mail addresses in the current buffer." - nil - "" - nil - (if goto-address-mode - (jit-lock-register #'goto-address-fontify-region) + :lighter "" + (cond + (goto-address-mode + (jit-lock-register #'goto-address-fontify-region) + (add-hook 'context-menu-functions 'goto-address-context-menu 10 t)) + (t (jit-lock-unregister #'goto-address-fontify-region) (save-restriction (widen) - (goto-address-unfontify (point-min) (point-max))))) + (goto-address-unfontify (point-min) (point-max))) + (remove-hook 'context-menu-functions 'goto-address-context-menu t)))) (defun goto-addr-mode--turn-on () (when (not goto-address-mode) @@ -287,15 +295,12 @@ Also fontifies the buffer appropriately (see `goto-address-fontify-p' and ;;;###autoload (define-globalized-minor-mode global-goto-address-mode goto-address-mode goto-addr-mode--turn-on - :group 'goto-address :version "28.1") ;;;###autoload (define-minor-mode goto-address-prog-mode "Like `goto-address-mode', but only for comments and strings." - nil - "" - nil + :lighter "" (if goto-address-prog-mode (jit-lock-register #'goto-address-fontify-region) (jit-lock-unregister #'goto-address-fontify-region) |