Mercurial > emacs
comparison lisp/ffap.el @ 90737:95d0cdf160ea
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 586-614)
- Update from CVS
- Update from erc--emacs--22
- Merge from gnus--rel--5.10
- Merge from erc--main--0
- Make byte compiler correctly write circular constants
* gnus--rel--5.10 (patch 186-196)
- Update from CVS
- Merge from emacs--devo--0
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-162
author | Miles Bader <miles@gnu.org> |
---|---|
date | Fri, 26 Jan 2007 06:16:11 +0000 |
parents | f1d13e615070 c456d15d23fd |
children | 4ef881a120fe |
comparison
equal
deleted
inserted
replaced
90736:ef1369583937 | 90737:95d0cdf160ea |
---|---|
1 ;;; ffap.el --- find file (or url) at point | 1 ;;; ffap.el --- find file (or url) at point |
2 | 2 |
3 ;; Copyright (C) 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2004, | 3 ;; Copyright (C) 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2004, |
4 ;; 2005, 2006 Free Software Foundation, Inc. | 4 ;; 2005, 2006, 2007 Free Software Foundation, Inc. |
5 | 5 |
6 ;; Author: Michelangelo Grigni <mic@mathcs.emory.edu> | 6 ;; Author: Michelangelo Grigni <mic@mathcs.emory.edu> |
7 ;; Maintainer: FSF | 7 ;; Maintainer: FSF |
8 ;; Created: 29 Mar 1993 | 8 ;; Created: 29 Mar 1993 |
9 ;; Keywords: files, hypermedia, matching, mouse, convenience | 9 ;; Keywords: files, hypermedia, matching, mouse, convenience |
308 ;; (and ffap-url-regexp (string-match "\\\\`" ffap-url-regexp) | 308 ;; (and ffap-url-regexp (string-match "\\\\`" ffap-url-regexp) |
309 ;; (concat "\\<" (substring ffap-url-regexp 2)))) | 309 ;; (concat "\\<" (substring ffap-url-regexp 2)))) |
310 ;; | 310 ;; |
311 ;; It pays to put a big fancy regexp here, since ffap-guesser is | 311 ;; It pays to put a big fancy regexp here, since ffap-guesser is |
312 ;; much more time-consuming than regexp searching: | 312 ;; much more time-consuming than regexp searching: |
313 "[/:.~a-zA-Z]/\\|@[a-zA-Z][-a-zA-Z0-9]*\\." | 313 "[/:.~[:alpha:]]/\\|@[[:alpha:]][-[:alnum:]]*\\." |
314 "*Regular expression governing movements of `ffap-next'." | 314 "*Regular expression governing movements of `ffap-next'." |
315 :type 'regexp | 315 :type 'regexp |
316 :group 'ffap) | 316 :group 'ffap) |
317 | 317 |
318 (defvar ffap-next-guess nil | 318 (defvar ffap-next-guess nil |
424 ;; (ffap-machine-p "nonesuch" nil nil 'ping) | 424 ;; (ffap-machine-p "nonesuch" nil nil 'ping) |
425 ;; (ffap-machine-p "ftp.mathcs.emory.edu" nil nil 'ping) | 425 ;; (ffap-machine-p "ftp.mathcs.emory.edu" nil nil 'ping) |
426 ;; (ffap-machine-p "mathcs" 5678 nil 'ping) | 426 ;; (ffap-machine-p "mathcs" 5678 nil 'ping) |
427 ;; (ffap-machine-p "foo.bonk" nil nil 'ping) | 427 ;; (ffap-machine-p "foo.bonk" nil nil 'ping) |
428 ;; (ffap-machine-p "foo.bonk.com" nil nil 'ping) | 428 ;; (ffap-machine-p "foo.bonk.com" nil nil 'ping) |
429 (if (or (string-match "[^-a-zA-Z0-9.]" host) ; Illegal chars (?) | 429 (if (or (string-match "[^-[:alnum:].]" host) ; Illegal chars (?) |
430 (not (string-match "[^0-9]" host))) ; 1: a number? 2: quick reject | 430 (not (string-match "[^0-9]" host))) ; 1: a number? 2: quick reject |
431 nil | 431 nil |
432 (let* ((domain | 432 (let* ((domain |
433 (and (string-match "\\.[^.]*$" host) | 433 (and (string-match "\\.[^.]*$" host) |
434 (downcase (substring host (1+ (match-beginning 0)))))) | 434 (downcase (substring host (1+ (match-beginning 0)))))) |
573 (concat "http://" mach "/")) | 573 (concat "http://" mach "/")) |
574 ;; More cases? Maybe "telnet:" for archie? | 574 ;; More cases? Maybe "telnet:" for archie? |
575 (ffap-ftp-regexp (ffap-host-to-filename mach)) | 575 (ffap-ftp-regexp (ffap-host-to-filename mach)) |
576 )) | 576 )) |
577 | 577 |
578 (defvar ffap-newsgroup-regexp "^[a-z]+\\.[-+a-z_0-9.]+$" | 578 (defvar ffap-newsgroup-regexp "^[[:lower:]]+\\.[-+[:lower:]_0-9.]+$" |
579 "Strings not matching this fail `ffap-newsgroup-p'.") | 579 "Strings not matching this fail `ffap-newsgroup-p'.") |
580 (defvar ffap-newsgroup-heads ; entirely inadequate | 580 (defvar ffap-newsgroup-heads ; entirely inadequate |
581 '("alt" "comp" "gnu" "misc" "news" "sci" "soc" "talk") | 581 '("alt" "comp" "gnu" "misc" "news" "sci" "soc" "talk") |
582 "Used by `ffap-newsgroup-p' if gnus is not running.") | 582 "Used by `ffap-newsgroup-p' if gnus is not running.") |
583 | 583 |
599 (setq ret string htbs nil)) | 599 (setq ret string htbs nil)) |
600 ;; If we made it this far, gnus is running, so ignore "heads": | 600 ;; If we made it this far, gnus is running, so ignore "heads": |
601 (setq heads nil)) | 601 (setq heads nil)) |
602 (error nil))) | 602 (error nil))) |
603 (or ret (not heads) | 603 (or ret (not heads) |
604 (let ((head (string-match "\\`\\([a-z]+\\)\\." string))) | 604 (let ((head (string-match "\\`\\([[:lower:]]+\\)\\." string))) |
605 (and head (setq head (substring string 0 (match-end 1))) | 605 (and head (setq head (substring string 0 (match-end 1))) |
606 (member head heads) | 606 (member head heads) |
607 (setq ret string)))) | 607 (setq ret string)))) |
608 ;; Is there ever a need to modify string as a newsgroup name? | 608 ;; Is there ever a need to modify string as a newsgroup name? |
609 ret))) | 609 ret))) |
778 (defvar ffap-alist | 778 (defvar ffap-alist |
779 '( | 779 '( |
780 ("" . ffap-completable) ; completion, slow on some systems | 780 ("" . ffap-completable) ; completion, slow on some systems |
781 ("\\.info\\'" . ffap-info) ; gzip.info | 781 ("\\.info\\'" . ffap-info) ; gzip.info |
782 ("\\`info/" . ffap-info-2) ; info/emacs | 782 ("\\`info/" . ffap-info-2) ; info/emacs |
783 ("\\`[-a-z]+\\'" . ffap-info-3) ; (emacs)Top [only in the parentheses] | 783 ("\\`[-[:lower:]]+\\'" . ffap-info-3) ; (emacs)Top [only in the parentheses] |
784 ("\\.elc?\\'" . ffap-el) ; simple.el, simple.elc | 784 ("\\.elc?\\'" . ffap-el) ; simple.el, simple.elc |
785 (emacs-lisp-mode . ffap-el-mode) ; rmail, gnus, simple, custom | 785 (emacs-lisp-mode . ffap-el-mode) ; rmail, gnus, simple, custom |
786 ;; (lisp-interaction-mode . ffap-el-mode) ; maybe | 786 ;; (lisp-interaction-mode . ffap-el-mode) ; maybe |
787 (finder-mode . ffap-el-mode) ; type {C-h p} and try it | 787 (finder-mode . ffap-el-mode) ; type {C-h p} and try it |
788 (help-mode . ffap-el-mode) ; maybe useful | 788 (help-mode . ffap-el-mode) ; maybe useful |
967 '( | 967 '( |
968 ;; The default, used when the `major-mode' is not found. | 968 ;; The default, used when the `major-mode' is not found. |
969 ;; Slightly controversial decisions: | 969 ;; Slightly controversial decisions: |
970 ;; * strip trailing "@" and ":" | 970 ;; * strip trailing "@" and ":" |
971 ;; * no commas (good for latex) | 971 ;; * no commas (good for latex) |
972 (file "--:$+<>@-Z_a-z~*?" "<@" "@>;.,!:") | 972 (file "--:$+<>@-Z_[:lower:]~*?" "<@" "@>;.,!:") |
973 ;; An url, or maybe a email/news message-id: | 973 ;; An url, or maybe a email/news message-id: |
974 (url "--:=&?$+@-Z_a-z~#,%;*" "^A-Za-z0-9" ":;.,!?") | 974 (url "--:=&?$+@-Z_[:lower:]~#,%;*" "^[:alnum:]" ":;.,!?") |
975 ;; Find a string that does *not* contain a colon: | 975 ;; Find a string that does *not* contain a colon: |
976 (nocolon "--9$+<>@-Z_a-z~" "<@" "@>;.,!?") | 976 (nocolon "--9$+<>@-Z_[:lower:]~" "<@" "@>;.,!?") |
977 ;; A machine: | 977 ;; A machine: |
978 (machine "-a-zA-Z0-9." "" ".") | 978 (machine "-[:alnum:]." "" ".") |
979 ;; Mathematica paths: allow backquotes | 979 ;; Mathematica paths: allow backquotes |
980 (math-mode ",-:$+<>@-Z_a-z~`" "<" "@>;.,!?`:") | 980 (math-mode ",-:$+<>@-Z_[:lower:]~`" "<" "@>;.,!?`:") |
981 ) | 981 ) |
982 "Alist of \(MODE CHARS BEG END\), where MODE is a symbol, | 982 "Alist of \(MODE CHARS BEG END\), where MODE is a symbol, |
983 possibly a major-mode name, or one of the symbol | 983 possibly a major-mode name, or one of the symbol |
984 `file', `url', `machine', and `nocolon'. | 984 `file', `url', `machine', and `nocolon'. |
985 `ffap-string-at-point' uses the data fields as follows: | 985 `ffap-string-at-point' uses the data fields as follows: |
1060 (w3-view-this-url t)) | 1060 (w3-view-this-url t)) |
1061 ;; Is there a reason not to strip trailing colon? | 1061 ;; Is there a reason not to strip trailing colon? |
1062 (let ((name (ffap-string-at-point 'url))) | 1062 (let ((name (ffap-string-at-point 'url))) |
1063 (cond | 1063 (cond |
1064 ((string-match "^url:" name) (setq name (substring name 4))) | 1064 ((string-match "^url:" name) (setq name (substring name 4))) |
1065 ((and (string-match "\\`[^:</>@]+@[^:</>@]+[a-zA-Z0-9]\\'" name) | 1065 ((and (string-match "\\`[^:</>@]+@[^:</>@]+[[:alnum:]]\\'" name) |
1066 ;; "foo@bar": could be "mailto" or "news" (a Message-ID). | 1066 ;; "foo@bar": could be "mailto" or "news" (a Message-ID). |
1067 ;; Without "<>" it must be "mailto". Otherwise could be | 1067 ;; Without "<>" it must be "mailto". Otherwise could be |
1068 ;; either, so consult `ffap-foo-at-bar-prefix'. | 1068 ;; either, so consult `ffap-foo-at-bar-prefix'. |
1069 (let ((prefix (if (and (equal (ffap-string-around) "<>") | 1069 (let ((prefix (if (and (equal (ffap-string-around) "<>") |
1070 ;; Expect some odd characters: | 1070 ;; Expect some odd characters: |
1072 ;; Could be news: | 1072 ;; Could be news: |
1073 ffap-foo-at-bar-prefix | 1073 ffap-foo-at-bar-prefix |
1074 "mailto"))) | 1074 "mailto"))) |
1075 (and prefix (setq name (concat prefix ":" name)))))) | 1075 (and prefix (setq name (concat prefix ":" name)))))) |
1076 ((ffap-newsgroup-p name) (setq name (concat "news:" name))) | 1076 ((ffap-newsgroup-p name) (setq name (concat "news:" name))) |
1077 ((and (string-match "\\`[a-z0-9]+\\'" name) ; <mic> <root> <nobody> | 1077 ((and (string-match "\\`[[:alnum:]]+\\'" name) ; <mic> <root> <nobody> |
1078 (equal (ffap-string-around) "<>") | 1078 (equal (ffap-string-around) "<>") |
1079 ;; (ffap-user-p name): | 1079 ;; (ffap-user-p name): |
1080 (not (string-match "~" (expand-file-name (concat "~" name)))) | 1080 (not (string-match "~" (expand-file-name (concat "~" name)))) |
1081 ) | 1081 ) |
1082 (setq name (concat "mailto:" name))) | 1082 (setq name (concat "mailto:" name))) |