2021-03-08 10:11:22 -05:00
|
|
|
;;; goto-addr.el --- click to browse URL or to send to e-mail address -*- lexical-binding: t; -*-
|
2000-03-20 13:12:14 +00:00
|
|
|
|
2021-01-01 01:13:56 -08:00
|
|
|
;; Copyright (C) 1995, 2000-2021 Free Software Foundation, Inc.
|
2000-03-20 13:12:14 +00:00
|
|
|
|
2000-07-13 19:01:10 +00:00
|
|
|
;; Author: Eric Ding <ericding@alum.mit.edu>
|
2019-05-25 13:43:06 -07:00
|
|
|
;; Maintainer: emacs-devel@gnu.org
|
2000-03-20 13:12:14 +00:00
|
|
|
;; Created: 15 Aug 1995
|
2020-01-29 09:21:19 -08:00
|
|
|
;; Keywords: www, mouse, mail
|
2000-03-20 13:12:14 +00:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 07:31:51 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2000-03-20 13:12:14 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 07:31:51 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2000-03-20 13:12:14 +00:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2000-03-20 13:12:14 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; This package allows you to click or hit a key sequence while on a
|
|
|
|
;; URL or e-mail address, and either load the URL into a browser of
|
|
|
|
;; your choice using the browse-url package, or if it's an e-mail
|
|
|
|
;; address, to send an e-mail to that address. By default, we bind to
|
|
|
|
;; the [mouse-2] and the [C-c return] key sequences.
|
|
|
|
|
|
|
|
;; INSTALLATION
|
|
|
|
;;
|
2020-01-29 09:21:19 -08:00
|
|
|
;; To use goto-address in a particular mode (this example uses
|
|
|
|
;; the fictional rich-text-mode), add this to your init file:
|
2000-03-20 13:12:14 +00:00
|
|
|
;;
|
2020-01-29 09:21:19 -08:00
|
|
|
;; (add-hook 'rich-text-mode-hook 'goto-address)
|
2000-03-20 13:12:14 +00:00
|
|
|
;;
|
2000-06-15 11:43:01 +00:00
|
|
|
;; The mouse click method is bound to [mouse-2] on highlighted URLs or
|
2000-03-20 13:12:14 +00:00
|
|
|
;; e-mail addresses only; it functions normally everywhere else. To bind
|
|
|
|
;; another mouse click to the function, add the following to your .emacs
|
|
|
|
;; (for example):
|
|
|
|
;;
|
|
|
|
;; (setq goto-address-highlight-keymap
|
|
|
|
;; (let ((m (make-sparse-keymap)))
|
2005-05-06 21:24:09 +00:00
|
|
|
;; (define-key m [S-mouse-2] 'goto-address-at-point)
|
2000-03-20 13:12:14 +00:00
|
|
|
;; m))
|
|
|
|
;;
|
|
|
|
|
|
|
|
;; Known bugs/features:
|
|
|
|
;; * goto-address-mail-regexp only catches foo@bar.org style addressing,
|
|
|
|
;; not stuff like X.400 addresses, etc.
|
|
|
|
;; * regexp also catches Message-Id line, since it is in the format of
|
|
|
|
;; an Internet e-mail address (like Compuserve addresses)
|
2000-07-20 17:29:46 +00:00
|
|
|
;; * If the buffer is fontified after goto-address-fontify is run
|
|
|
|
;; (say, using font-lock-fontify-buffer), then font-lock faces will
|
2000-03-20 13:12:14 +00:00
|
|
|
;; override goto-address faces.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2019-06-25 16:02:12 +02:00
|
|
|
(require 'seq)
|
2000-08-16 21:28:35 +00:00
|
|
|
(require 'thingatpt)
|
|
|
|
(autoload 'browse-url-url-at-point "browse-url")
|
2000-03-20 13:12:14 +00:00
|
|
|
|
|
|
|
(defgroup goto-address nil
|
|
|
|
"Click to browse URL or to send to e-mail address."
|
|
|
|
:group 'mouse
|
2010-03-12 14:13:38 -05:00
|
|
|
:group 'comm)
|
2000-03-20 13:12:14 +00:00
|
|
|
|
|
|
|
|
2001-10-05 09:36:02 +00:00
|
|
|
;; I don't expect users to want fontify'ing without highlighting.
|
2000-03-20 13:12:14 +00:00
|
|
|
(defcustom goto-address-fontify-p t
|
2012-04-09 21:05:48 +08:00
|
|
|
"Non-nil means URLs and e-mail addresses in buffer are fontified.
|
2000-03-20 13:12:14 +00:00
|
|
|
But only if `goto-address-highlight-p' is also non-nil."
|
2021-03-08 10:11:22 -05:00
|
|
|
:type 'boolean)
|
2000-03-20 13:12:14 +00:00
|
|
|
|
|
|
|
(defcustom goto-address-highlight-p t
|
2012-04-09 21:05:48 +08:00
|
|
|
"Non-nil means URLs and e-mail addresses in buffer are highlighted."
|
2021-03-08 10:11:22 -05:00
|
|
|
:type 'boolean)
|
2000-03-20 13:12:14 +00:00
|
|
|
|
|
|
|
(defcustom goto-address-fontify-maximum-size 30000
|
2012-04-09 21:05:48 +08:00
|
|
|
"Maximum size of file in which to fontify and/or highlight URLs.
|
2003-05-19 14:49:25 +00:00
|
|
|
A value of t means there is no limit--fontify regardless of the size."
|
2021-03-08 10:11:22 -05:00
|
|
|
:type '(choice (integer :tag "Maximum size") (const :tag "No limit" t)))
|
2000-03-20 13:12:14 +00:00
|
|
|
|
|
|
|
(defvar goto-address-mail-regexp
|
2001-10-11 23:40:35 +00:00
|
|
|
;; Actually pretty much any char could appear in the username part. -stef
|
Fix regular-expression glitches and typos
Problems reported by Mattias Engdegård in:
https://lists.gnu.org/r/emacs-devel/2019-03/msg00085.html
* admin/admin.el (set-version):
* lisp/allout.el (allout-latexify-one-item):
* lisp/arc-mode.el (archive-arc-rename-entry)
(archive-rar-summarize):
* lisp/calc/calc-graph.el (calc-graph-set-styles)
(calc-graph-hide):
* lisp/calc/calc-help.el (calc-describe-key):
* lisp/calc/calc-lang.el (math-compose-tex-func, eqn):
* lisp/calc/calc.el (calcDigit-key):
* lisp/cedet/ede/makefile-edit.el (makefile-macro-file-list):
* lisp/cedet/ede/speedbar.el (ede-tag-expand):
* lisp/cedet/semantic/sb.el (semantic-sb-show-extra)
(semantic-sb-expand-group):
* lisp/comint.el (comint-substitute-in-file-name):
* lisp/dired.el (dired-actual-switches):
* lisp/emacs-lisp/chart.el (chart-rmail-from):
* lisp/emacs-lisp/eieio-opt.el (eieio-sb-expand):
* lisp/emacs-lisp/eieio-speedbar.el (eieio-speedbar-object-expand):
* lisp/emacs-lisp/rx.el (rx-not, rx-atomic-p):
* lisp/emulation/viper-ex.el (viper-get-ex-token)
(viper-get-ex-pat, ex-set-read-variable):
* lisp/epg.el (epg--status-SIG_CREATED):
* lisp/erc/erc-speedbar.el (erc-speedbar-expand-user):
(erc-speedbar-expand-channel, erc-speedbar-expand-server)
* lisp/erc/erc.el (erc-is-message-ctcp-and-not-action-p)
(erc-banlist-update):
* lisp/eshell/em-dirs.el (eshell-parse-drive-letter, eshell/pwd):
* lisp/find-dired.el (find-dired):
* lisp/frame.el (frame-set-background-mode):
* lisp/generic-x.el (apache-log-generic-mode):
* lisp/gnus/gnus-art.el (gnus-button-valid-localpart-regexp):
* lisp/gnus/gnus.el (gnus-short-group-name):
* lisp/gnus/message.el (message-mailer-swallows-blank-line):
* lisp/ibuffer.el (ibuffer-fontification-alist):
* lisp/ido.el (ido-set-matches-1):
* lisp/info-xref.el (info-xref-lock-file-p):
* lisp/info.el (Info-dir-remove-duplicates)
(Info-unescape-quotes, Info-split-parameter-string)
(Info-speedbar-expand-node):
* lisp/international/mule.el (sgml-html-meta-auto-coding-function):
* lisp/isearch.el (isearch-pre-command-hook):
* lisp/language/ethio-util.el (ethio-fidel-to-tex-buffer):
* lisp/mail/rmail.el (rmail-collect-deleted):
* lisp/mh-e/mh-alias.el (mh-alias-suggest-alias):
* lisp/mh-e/mh-comp.el (mh-forward):
* lisp/mh-e/mh-search.el (mh-index-next-folder)
(mh-index-create-imenu-index):
* lisp/mh-e/mh-xface.el (mh-picon-get-image):
* lisp/minibuffer.el (completion--embedded-envvar-re):
* lisp/net/ange-ftp.el (ange-ftp-ls-parser):
* lisp/net/goto-addr.el (goto-address-mail-regexp)
(goto-address-find-address-at-point):
* lisp/net/pop3.el (pop3-read-response, pop3-user)
(pop3-pass, pop3-apop):
* lisp/net/tramp.el (tramp-ipv6-regexp)
(tramp-replace-environment-variables):
* lisp/nxml/nxml-maint.el (nxml-insert-target-repertoire-glyph-set):
* lisp/nxml/rng-uri.el (rng-uri-escape-multibyte):
* lisp/nxml/rng-xsd.el (rng-xsd-convert-any-uri):
* lisp/obsolete/pgg.el (pgg-fetch-key):
* lisp/obsolete/vip.el (vip-get-ex-token):
* lisp/org/ob-core.el (org-babel-string-read):
* lisp/org/org-agenda.el:
(org-agenda-add-entry-to-org-agenda-diary-file):
* lisp/org/org-element.el (org-element-keyword-parser):
* lisp/org/org-list.el (org-list-indent-item-generic):
* lisp/org/org-mhe.el (org-mhe-get-message-folder-from-index):
* lisp/org/org-mobile.el (org-mobile-apply):
* lisp/org/org-mouse.el (org-mouse-context-menu):
* lisp/org/org-plot.el (org-plot/gnuplot):
* lisp/org/org-protocol.el (org-protocol-flatten-greedy):
* lisp/org/org-table.el (org-table-copy-down)
(org-table-formula-make-cmp-string)
(org-table-get-stored-formulas, org-table-recalculate)
(org-table-edit-formulas):
* lisp/org/org.el (org-translate-link-from-planner)
(org-fill-line-break-nobreak-p):
* lisp/org/ox-ascii.el (org-ascii-item):
* lisp/org/ox-latex.el (org-latex-clean-invalid-line-breaks):
* lisp/org/ox.el (org-export-expand-include-keyword):
* lisp/progmodes/ada-xref.el (ada-treat-cmd-string):
* lisp/progmodes/cfengine.el (cfengine2-font-lock-keywords):
* lisp/progmodes/cperl-mode.el (cperl-to-comment-or-eol)
(cperl-find-pods-heres, cperl-fix-line-spacing)
(cperl-have-help-regexp, cperl-word-at-point-hard)
(cperl-make-regexp-x):
* lisp/progmodes/dcl-mode.el (dcl-option-value-offset):
* lisp/progmodes/etags.el (tag-implicit-name-match-p):
* lisp/progmodes/fortran.el (fortran-fill):
* lisp/progmodes/gdb-mi.el (gdb-speedbar-expand-node)
(gdb-locals-handler-custom):
* lisp/progmodes/grep.el (grep-mode-font-lock-keywords):
* lisp/progmodes/gud.el (gud-jdb-find-source-using-classpath):
* lisp/progmodes/js.el (js--continued-expression-p):
* lisp/progmodes/m4-mode.el (m4-font-lock-keywords):
* lisp/progmodes/meta-mode.el (meta-indent-level-count):
* lisp/progmodes/mixal-mode.el (mixal-font-lock-keywords):
* lisp/progmodes/opascal.el (opascal-find-unit-in-directory):
* lisp/progmodes/pascal.el (pascal-progbeg-re):
* lisp/progmodes/ruby-mode.el (ruby-expression-expansion-re)
(ruby-expr-beg, ruby-parse-partial)
(ruby-toggle-string-quotes, ruby-font-lock-keywords):
* lisp/progmodes/sql.el (sql--make-help-docstring):
* lisp/progmodes/verilog-mode.el (verilog-coverpoint-re)
(verilog-skip-forward-comment-p)
(verilog-read-sub-decls-gate)
(verilog-read-auto-template-middle):
* lisp/progmodes/vhdl-mode.el (vhdl-resolve-env-variable)
(vhdl-speedbar-expand-project, vhdl-speedbar-expand-entity)
(vhdl-speedbar-expand-architecture)
(vhdl-speedbar-expand-config, vhdl-speedbar-expand-package)
(vhdl-speedbar-dired):
* lisp/speedbar.el (speedbar-dired, speedbar-tag-file)
(speedbar-tag-expand):
* lisp/textmodes/dns-mode.el (dns-mode-font-lock-keywords):
* lisp/textmodes/flyspell.el (flyspell-debug-signal-word-checked):
* lisp/textmodes/ispell.el (ispell-process-line):
* lisp/textmodes/reftex-cite.el (reftex-end-of-bib-entry):
* lisp/textmodes/reftex-ref.el (reftex-replace-prefix-escapes):
* lisp/url/url-parse.el (url-generic-parse-url):
* lisp/url/url-util.el (url-truncate-url-for-viewing):
* lisp/vc/diff-mode.el (diff-unified->context):
* lisp/vc/vc-bzr.el (vc-bzr-error-regexp-alist):
* lisp/vc/vc-cvs.el (vc-cvs-parse-status):
* lisp/woman.el (woman0-el, woman-if-ignore)
(woman-change-fonts):
* lisp/xdg.el (xdg--substitute-home-env):
Fix regular-expression infelicities and typos.
Fix regular expression typos
Fix typos reported by Mattias Engdegård in:
that occurred in preloaded modules.
* lisp/frame.el (frame-set-background-mode):
* lisp/international/mule.el (sgml-html-meta-auto-coding-function):
* lisp/isearch.el (isearch-pre-command-hook):
* lisp/minibuffer.el (completion--embedded-envvar-re):
2019-03-04 18:00:00 -08:00
|
|
|
"[-a-zA-Z0-9=._+]+@\\([-a-zA-Z0-9_]+\\.\\)+[a-zA-Z0-9]+"
|
2000-03-20 13:12:14 +00:00
|
|
|
"A regular expression probably matching an e-mail address.")
|
|
|
|
|
2019-06-25 16:02:12 +02:00
|
|
|
(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'.
|
|
|
|
|
2019-12-09 18:44:35 -08:00
|
|
|
Customizations to this variable made after goto-addr is loaded
|
2019-06-25 16:02:12 +02:00
|
|
|
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'.
|
|
|
|
|
2019-12-09 18:44:35 -08:00
|
|
|
Customizations to this variable made after goto-addr is loaded
|
2019-06-25 16:02:12 +02:00
|
|
|
will have no effect.")
|
|
|
|
|
2002-10-29 18:12:33 +00:00
|
|
|
(defvar goto-address-url-regexp
|
2019-06-25 16:02:12 +02:00
|
|
|
(concat "\\<"
|
|
|
|
(regexp-opt goto-address-uri-schemes t)
|
|
|
|
thing-at-point-url-path-regexp)
|
2000-03-20 13:12:14 +00:00
|
|
|
"A regular expression probably matching a URL.")
|
|
|
|
|
|
|
|
(defvar goto-address-highlight-keymap
|
|
|
|
(let ((m (make-sparse-keymap)))
|
2021-03-08 10:11:22 -05:00
|
|
|
(define-key m (kbd "<mouse-2>") #'goto-address-at-point)
|
|
|
|
(define-key m (kbd "C-c RET") #'goto-address-at-point)
|
2000-03-20 13:12:14 +00:00
|
|
|
m)
|
2005-12-30 05:57:48 +00:00
|
|
|
"Keymap to hold goto-addr's mouse key defs under highlighted URLs.")
|
2000-03-20 13:12:14 +00:00
|
|
|
|
2009-01-14 23:14:51 +00:00
|
|
|
(defcustom goto-address-url-face 'link
|
2000-08-16 21:28:35 +00:00
|
|
|
"Face to use for URLs."
|
2021-03-08 10:11:22 -05:00
|
|
|
:type 'face)
|
2000-03-20 13:12:14 +00:00
|
|
|
|
|
|
|
(defcustom goto-address-url-mouse-face 'highlight
|
2000-08-16 21:28:35 +00:00
|
|
|
"Face to use for URLs when the mouse is on them."
|
2021-03-08 10:11:22 -05:00
|
|
|
:type 'face)
|
2000-03-20 13:12:14 +00:00
|
|
|
|
|
|
|
(defcustom goto-address-mail-face 'italic
|
2000-08-16 21:28:35 +00:00
|
|
|
"Face to use for e-mail addresses."
|
2021-03-08 10:11:22 -05:00
|
|
|
:type 'face)
|
2000-03-20 13:12:14 +00:00
|
|
|
|
|
|
|
(defcustom goto-address-mail-mouse-face 'secondary-selection
|
2000-08-16 21:28:35 +00:00
|
|
|
"Face to use for e-mail addresses when the mouse is on them."
|
2021-03-08 10:11:22 -05:00
|
|
|
:type 'face)
|
2000-03-20 13:12:14 +00:00
|
|
|
|
2008-04-24 05:48:08 +00:00
|
|
|
(defun goto-address-unfontify (start end)
|
|
|
|
"Remove `goto-address' fontification from the given region."
|
|
|
|
(dolist (overlay (overlays-in start end))
|
|
|
|
(if (overlay-get overlay 'goto-address)
|
|
|
|
(delete-overlay overlay))))
|
|
|
|
|
2008-04-24 06:06:53 +00:00
|
|
|
(defvar goto-address-prog-mode)
|
|
|
|
|
2013-02-14 10:53:46 -05:00
|
|
|
(defun goto-address-fontify (&optional start end)
|
2000-06-15 11:43:01 +00:00
|
|
|
"Fontify the URLs and e-mail addresses in the current buffer.
|
2000-03-20 13:12:14 +00:00
|
|
|
This function implements `goto-address-highlight-p'
|
|
|
|
and `goto-address-fontify-p'."
|
2000-07-20 17:29:46 +00:00
|
|
|
;; Clean up from any previous go.
|
2013-02-14 10:53:46 -05:00
|
|
|
(goto-address-unfontify (or start (point-min)) (or end (point-max)))
|
2000-03-20 13:12:14 +00:00
|
|
|
(save-excursion
|
2000-07-20 17:29:46 +00:00
|
|
|
(let ((inhibit-point-motion-hooks t))
|
2013-02-14 10:53:46 -05:00
|
|
|
(goto-char (or start (point-min)))
|
2008-04-24 05:48:08 +00:00
|
|
|
(when (or (eq t goto-address-fontify-maximum-size)
|
2013-02-14 10:53:46 -05:00
|
|
|
(< (- (or end (point-max)) (point))
|
|
|
|
goto-address-fontify-maximum-size))
|
|
|
|
(while (re-search-forward goto-address-url-regexp end t)
|
2008-04-24 05:48:08 +00:00
|
|
|
(let* ((s (match-beginning 0))
|
|
|
|
(e (match-end 0))
|
|
|
|
this-overlay)
|
|
|
|
(when (or (not goto-address-prog-mode)
|
|
|
|
;; This tests for both comment and string
|
|
|
|
;; syntax.
|
|
|
|
(nth 8 (syntax-ppss)))
|
|
|
|
(setq this-overlay (make-overlay s e))
|
|
|
|
(and goto-address-fontify-p
|
|
|
|
(overlay-put this-overlay 'face goto-address-url-face))
|
|
|
|
(overlay-put this-overlay 'evaporate t)
|
|
|
|
(overlay-put this-overlay
|
|
|
|
'mouse-face goto-address-url-mouse-face)
|
|
|
|
(overlay-put this-overlay 'follow-link t)
|
|
|
|
(overlay-put this-overlay
|
|
|
|
'help-echo "mouse-2, C-c RET: follow URL")
|
|
|
|
(overlay-put this-overlay
|
|
|
|
'keymap goto-address-highlight-keymap)
|
|
|
|
(overlay-put this-overlay 'goto-address t))))
|
2013-02-14 10:53:46 -05:00
|
|
|
(goto-char (or start (point-min)))
|
|
|
|
(while (re-search-forward goto-address-mail-regexp end t)
|
2008-04-24 05:48:08 +00:00
|
|
|
(let* ((s (match-beginning 0))
|
|
|
|
(e (match-end 0))
|
|
|
|
this-overlay)
|
|
|
|
(when (or (not goto-address-prog-mode)
|
|
|
|
;; This tests for both comment and string
|
|
|
|
;; syntax.
|
|
|
|
(nth 8 (syntax-ppss)))
|
|
|
|
(setq this-overlay (make-overlay s e))
|
|
|
|
(and goto-address-fontify-p
|
|
|
|
(overlay-put this-overlay 'face goto-address-mail-face))
|
|
|
|
(overlay-put this-overlay 'evaporate t)
|
|
|
|
(overlay-put this-overlay 'mouse-face
|
|
|
|
goto-address-mail-mouse-face)
|
|
|
|
(overlay-put this-overlay 'follow-link t)
|
|
|
|
(overlay-put this-overlay
|
|
|
|
'help-echo "mouse-2, C-c RET: mail this address")
|
|
|
|
(overlay-put this-overlay
|
|
|
|
'keymap goto-address-highlight-keymap)
|
|
|
|
(overlay-put this-overlay 'goto-address t))))))))
|
|
|
|
|
|
|
|
(defun goto-address-fontify-region (start end)
|
|
|
|
"Fontify URLs and e-mail addresses in the given region."
|
|
|
|
(save-excursion
|
2013-02-14 10:53:46 -05:00
|
|
|
(let ((beg-line (progn (goto-char start) (line-beginning-position)))
|
|
|
|
(end-line (progn (goto-char end) (line-end-position))))
|
|
|
|
(goto-address-fontify beg-line end-line))))
|
2000-03-20 13:12:14 +00:00
|
|
|
|
2001-10-05 09:36:02 +00:00
|
|
|
;; code to find and goto addresses; much of this has been blatantly
|
|
|
|
;; snarfed from browse-url.el
|
2000-03-20 13:12:14 +00:00
|
|
|
|
|
|
|
;;;###autoload
|
2005-05-06 21:24:09 +00:00
|
|
|
(defun goto-address-at-point (&optional event)
|
2000-03-20 13:12:14 +00:00
|
|
|
"Send to the e-mail address or load the URL at point.
|
|
|
|
Send mail to address at point. See documentation for
|
|
|
|
`goto-address-find-address-at-point'. If no address is found
|
|
|
|
there, then load the URL at or before point."
|
2005-05-06 21:24:09 +00:00
|
|
|
(interactive (list last-input-event))
|
2000-03-20 13:12:14 +00:00
|
|
|
(save-excursion
|
2005-11-22 22:08:11 +00:00
|
|
|
(if event (posn-set-point (event-end event)))
|
2000-03-20 13:12:14 +00:00
|
|
|
(let ((address (save-excursion (goto-address-find-address-at-point))))
|
2003-02-04 13:24:35 +00:00
|
|
|
(if (and address
|
2001-05-18 12:50:27 +00:00
|
|
|
(save-excursion
|
|
|
|
(goto-char (previous-single-char-property-change
|
|
|
|
(point) 'goto-address nil
|
|
|
|
(line-beginning-position)))
|
|
|
|
(not (looking-at goto-address-url-regexp))))
|
2000-08-16 21:28:35 +00:00
|
|
|
(compose-mail address)
|
|
|
|
(let ((url (browse-url-url-at-point)))
|
|
|
|
(if url
|
|
|
|
(browse-url url)
|
|
|
|
(error "No e-mail address or URL found")))))))
|
2000-03-20 13:12:14 +00:00
|
|
|
|
|
|
|
(defun goto-address-find-address-at-point ()
|
|
|
|
"Find e-mail address around or before point.
|
|
|
|
Then search backwards to beginning of line for the start of an e-mail
|
2000-08-16 21:28:35 +00:00
|
|
|
address. If no e-mail address found, return nil."
|
Fix regular-expression glitches and typos
Problems reported by Mattias Engdegård in:
https://lists.gnu.org/r/emacs-devel/2019-03/msg00085.html
* admin/admin.el (set-version):
* lisp/allout.el (allout-latexify-one-item):
* lisp/arc-mode.el (archive-arc-rename-entry)
(archive-rar-summarize):
* lisp/calc/calc-graph.el (calc-graph-set-styles)
(calc-graph-hide):
* lisp/calc/calc-help.el (calc-describe-key):
* lisp/calc/calc-lang.el (math-compose-tex-func, eqn):
* lisp/calc/calc.el (calcDigit-key):
* lisp/cedet/ede/makefile-edit.el (makefile-macro-file-list):
* lisp/cedet/ede/speedbar.el (ede-tag-expand):
* lisp/cedet/semantic/sb.el (semantic-sb-show-extra)
(semantic-sb-expand-group):
* lisp/comint.el (comint-substitute-in-file-name):
* lisp/dired.el (dired-actual-switches):
* lisp/emacs-lisp/chart.el (chart-rmail-from):
* lisp/emacs-lisp/eieio-opt.el (eieio-sb-expand):
* lisp/emacs-lisp/eieio-speedbar.el (eieio-speedbar-object-expand):
* lisp/emacs-lisp/rx.el (rx-not, rx-atomic-p):
* lisp/emulation/viper-ex.el (viper-get-ex-token)
(viper-get-ex-pat, ex-set-read-variable):
* lisp/epg.el (epg--status-SIG_CREATED):
* lisp/erc/erc-speedbar.el (erc-speedbar-expand-user):
(erc-speedbar-expand-channel, erc-speedbar-expand-server)
* lisp/erc/erc.el (erc-is-message-ctcp-and-not-action-p)
(erc-banlist-update):
* lisp/eshell/em-dirs.el (eshell-parse-drive-letter, eshell/pwd):
* lisp/find-dired.el (find-dired):
* lisp/frame.el (frame-set-background-mode):
* lisp/generic-x.el (apache-log-generic-mode):
* lisp/gnus/gnus-art.el (gnus-button-valid-localpart-regexp):
* lisp/gnus/gnus.el (gnus-short-group-name):
* lisp/gnus/message.el (message-mailer-swallows-blank-line):
* lisp/ibuffer.el (ibuffer-fontification-alist):
* lisp/ido.el (ido-set-matches-1):
* lisp/info-xref.el (info-xref-lock-file-p):
* lisp/info.el (Info-dir-remove-duplicates)
(Info-unescape-quotes, Info-split-parameter-string)
(Info-speedbar-expand-node):
* lisp/international/mule.el (sgml-html-meta-auto-coding-function):
* lisp/isearch.el (isearch-pre-command-hook):
* lisp/language/ethio-util.el (ethio-fidel-to-tex-buffer):
* lisp/mail/rmail.el (rmail-collect-deleted):
* lisp/mh-e/mh-alias.el (mh-alias-suggest-alias):
* lisp/mh-e/mh-comp.el (mh-forward):
* lisp/mh-e/mh-search.el (mh-index-next-folder)
(mh-index-create-imenu-index):
* lisp/mh-e/mh-xface.el (mh-picon-get-image):
* lisp/minibuffer.el (completion--embedded-envvar-re):
* lisp/net/ange-ftp.el (ange-ftp-ls-parser):
* lisp/net/goto-addr.el (goto-address-mail-regexp)
(goto-address-find-address-at-point):
* lisp/net/pop3.el (pop3-read-response, pop3-user)
(pop3-pass, pop3-apop):
* lisp/net/tramp.el (tramp-ipv6-regexp)
(tramp-replace-environment-variables):
* lisp/nxml/nxml-maint.el (nxml-insert-target-repertoire-glyph-set):
* lisp/nxml/rng-uri.el (rng-uri-escape-multibyte):
* lisp/nxml/rng-xsd.el (rng-xsd-convert-any-uri):
* lisp/obsolete/pgg.el (pgg-fetch-key):
* lisp/obsolete/vip.el (vip-get-ex-token):
* lisp/org/ob-core.el (org-babel-string-read):
* lisp/org/org-agenda.el:
(org-agenda-add-entry-to-org-agenda-diary-file):
* lisp/org/org-element.el (org-element-keyword-parser):
* lisp/org/org-list.el (org-list-indent-item-generic):
* lisp/org/org-mhe.el (org-mhe-get-message-folder-from-index):
* lisp/org/org-mobile.el (org-mobile-apply):
* lisp/org/org-mouse.el (org-mouse-context-menu):
* lisp/org/org-plot.el (org-plot/gnuplot):
* lisp/org/org-protocol.el (org-protocol-flatten-greedy):
* lisp/org/org-table.el (org-table-copy-down)
(org-table-formula-make-cmp-string)
(org-table-get-stored-formulas, org-table-recalculate)
(org-table-edit-formulas):
* lisp/org/org.el (org-translate-link-from-planner)
(org-fill-line-break-nobreak-p):
* lisp/org/ox-ascii.el (org-ascii-item):
* lisp/org/ox-latex.el (org-latex-clean-invalid-line-breaks):
* lisp/org/ox.el (org-export-expand-include-keyword):
* lisp/progmodes/ada-xref.el (ada-treat-cmd-string):
* lisp/progmodes/cfengine.el (cfengine2-font-lock-keywords):
* lisp/progmodes/cperl-mode.el (cperl-to-comment-or-eol)
(cperl-find-pods-heres, cperl-fix-line-spacing)
(cperl-have-help-regexp, cperl-word-at-point-hard)
(cperl-make-regexp-x):
* lisp/progmodes/dcl-mode.el (dcl-option-value-offset):
* lisp/progmodes/etags.el (tag-implicit-name-match-p):
* lisp/progmodes/fortran.el (fortran-fill):
* lisp/progmodes/gdb-mi.el (gdb-speedbar-expand-node)
(gdb-locals-handler-custom):
* lisp/progmodes/grep.el (grep-mode-font-lock-keywords):
* lisp/progmodes/gud.el (gud-jdb-find-source-using-classpath):
* lisp/progmodes/js.el (js--continued-expression-p):
* lisp/progmodes/m4-mode.el (m4-font-lock-keywords):
* lisp/progmodes/meta-mode.el (meta-indent-level-count):
* lisp/progmodes/mixal-mode.el (mixal-font-lock-keywords):
* lisp/progmodes/opascal.el (opascal-find-unit-in-directory):
* lisp/progmodes/pascal.el (pascal-progbeg-re):
* lisp/progmodes/ruby-mode.el (ruby-expression-expansion-re)
(ruby-expr-beg, ruby-parse-partial)
(ruby-toggle-string-quotes, ruby-font-lock-keywords):
* lisp/progmodes/sql.el (sql--make-help-docstring):
* lisp/progmodes/verilog-mode.el (verilog-coverpoint-re)
(verilog-skip-forward-comment-p)
(verilog-read-sub-decls-gate)
(verilog-read-auto-template-middle):
* lisp/progmodes/vhdl-mode.el (vhdl-resolve-env-variable)
(vhdl-speedbar-expand-project, vhdl-speedbar-expand-entity)
(vhdl-speedbar-expand-architecture)
(vhdl-speedbar-expand-config, vhdl-speedbar-expand-package)
(vhdl-speedbar-dired):
* lisp/speedbar.el (speedbar-dired, speedbar-tag-file)
(speedbar-tag-expand):
* lisp/textmodes/dns-mode.el (dns-mode-font-lock-keywords):
* lisp/textmodes/flyspell.el (flyspell-debug-signal-word-checked):
* lisp/textmodes/ispell.el (ispell-process-line):
* lisp/textmodes/reftex-cite.el (reftex-end-of-bib-entry):
* lisp/textmodes/reftex-ref.el (reftex-replace-prefix-escapes):
* lisp/url/url-parse.el (url-generic-parse-url):
* lisp/url/url-util.el (url-truncate-url-for-viewing):
* lisp/vc/diff-mode.el (diff-unified->context):
* lisp/vc/vc-bzr.el (vc-bzr-error-regexp-alist):
* lisp/vc/vc-cvs.el (vc-cvs-parse-status):
* lisp/woman.el (woman0-el, woman-if-ignore)
(woman-change-fonts):
* lisp/xdg.el (xdg--substitute-home-env):
Fix regular-expression infelicities and typos.
Fix regular expression typos
Fix typos reported by Mattias Engdegård in:
that occurred in preloaded modules.
* lisp/frame.el (frame-set-background-mode):
* lisp/international/mule.el (sgml-html-meta-auto-coding-function):
* lisp/isearch.el (isearch-pre-command-hook):
* lisp/minibuffer.el (completion--embedded-envvar-re):
2019-03-04 18:00:00 -08:00
|
|
|
(re-search-backward "[^-_A-Za-z0-9.@]" (line-beginning-position) 'lim)
|
2000-08-16 21:28:35 +00:00
|
|
|
(if (or (looking-at goto-address-mail-regexp) ; already at start
|
|
|
|
(and (re-search-forward goto-address-mail-regexp
|
|
|
|
(line-end-position) 'lim)
|
|
|
|
(goto-char (match-beginning 0))))
|
|
|
|
(match-string-no-properties 0)))
|
2000-03-20 13:12:14 +00:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun goto-address ()
|
|
|
|
"Sets up goto-address functionality in the current buffer.
|
|
|
|
Allows user to use mouse/keyboard command to click to go to a URL
|
|
|
|
or to send e-mail.
|
2005-12-30 05:57:48 +00:00
|
|
|
By default, goto-address binds `goto-address-at-point' to mouse-2 and C-c RET
|
|
|
|
only on URLs and e-mail addresses.
|
2000-03-20 13:12:14 +00:00
|
|
|
|
|
|
|
Also fontifies the buffer appropriately (see `goto-address-fontify-p' and
|
|
|
|
`goto-address-highlight-p' for more information)."
|
|
|
|
(interactive)
|
|
|
|
(if goto-address-highlight-p
|
|
|
|
(goto-address-fontify)))
|
2006-07-05 12:35:22 +00:00
|
|
|
;;;###autoload(put 'goto-address 'safe-local-eval-function t)
|
2000-03-20 13:12:14 +00:00
|
|
|
|
2008-04-24 05:48:08 +00:00
|
|
|
;;;###autoload
|
|
|
|
(define-minor-mode goto-address-mode
|
2018-07-01 23:34:53 -04:00
|
|
|
"Minor mode to buttonize URLs and e-mail addresses in the current buffer."
|
2021-04-11 23:47:14 -04:00
|
|
|
:lighter ""
|
2008-04-24 05:48:08 +00:00
|
|
|
(if goto-address-mode
|
|
|
|
(jit-lock-register #'goto-address-fontify-region)
|
|
|
|
(jit-lock-unregister #'goto-address-fontify-region)
|
|
|
|
(save-restriction
|
|
|
|
(widen)
|
|
|
|
(goto-address-unfontify (point-min) (point-max)))))
|
|
|
|
|
2020-08-20 15:17:19 +02:00
|
|
|
(defun goto-addr-mode--turn-on ()
|
|
|
|
(when (not goto-address-mode)
|
|
|
|
(goto-address-mode 1)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(define-globalized-minor-mode global-goto-address-mode
|
|
|
|
goto-address-mode goto-addr-mode--turn-on
|
|
|
|
:version "28.1")
|
|
|
|
|
2008-04-24 05:48:08 +00:00
|
|
|
;;;###autoload
|
|
|
|
(define-minor-mode goto-address-prog-mode
|
2011-10-19 20:26:14 -04:00
|
|
|
"Like `goto-address-mode', but only for comments and strings."
|
2021-04-11 23:47:14 -04:00
|
|
|
:lighter ""
|
2008-04-24 05:48:08 +00:00
|
|
|
(if goto-address-prog-mode
|
|
|
|
(jit-lock-register #'goto-address-fontify-region)
|
|
|
|
(jit-lock-unregister #'goto-address-fontify-region)
|
|
|
|
(save-restriction
|
|
|
|
(widen)
|
|
|
|
(goto-address-unfontify (point-min) (point-max)))))
|
|
|
|
|
2000-03-20 13:12:14 +00:00
|
|
|
(provide 'goto-addr)
|
|
|
|
|
2001-07-15 16:15:35 +00:00
|
|
|
;;; goto-addr.el ends here
|