annotate lisp/ffap.el @ 14385:aa3232e9077f

(server-process-filter): In file name, collapse multiple slashes to one.
author Richard M. Stallman <rms@gnu.org>
date Fri, 26 Jan 1996 23:57:39 +0000
parents 83f275dcd93a
children cecaaaec6fd6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13531
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; ffap.el -- find-file-at-point,
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13979
diff changeset
3 ;; Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13979
diff changeset
4
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13979
diff changeset
5 ;; Author: Michelangelo Grigni <mic@mathcs.emory.edu>
13531
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; any later version.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13979
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13979
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13979
diff changeset
22 ;; Boston, MA 02111-1307, USA.
13531
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;;; Commentary:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; A replacement for find-file {C-x C-f}: finds file or URL,
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; guessing default from text at point. Many features!
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; Send bugs or suggestions with M-x ffap-bug.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; See ftp://ftp.mathcs.emory.edu:/pub/mic/emacs/ for most recent version:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; ffap.el.gz -- this file, compressed with gzip
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; ffap-xe.el -- support code for XEmacs 19.*
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; COPYING.gz -- GNU General Public License, version 2
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; README -- description of these and other files
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; For the last version sent to elisp-archive@cis.ohio-state.edu, see:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; ftp://ftp.cis.ohio-state.edu/pub/gnu/emacs/elisp-archive/misc/ffap.el.Z
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; (mirrored in gatekeeper.dec.com:/pub/GNU/elisp-archive/misc/)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;;; Description:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; Command find-file-at-point (== ffap) replaces find-file. With a
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; prefix, it behaves exactly like find-file. Without a prefix, it
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; first tries to guess a default file or URL based on the text around
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; the point (set `ffap-require-prefix' to swap these behaviors).
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; This is a quick way to fetch URL and file references in many
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; situations, such as in mail or news messages, README's, and
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; MANIFEST's.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; Some related commands are ffap-at-mouse, ffap-next, ffap-menu,
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; ffap-other-window, ffap-other-frame.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; This package is about user convenience. It adds nothing to the
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; elisp programmer's repertoire.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;;; Installation:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; Quick Setup:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;; For a basic installation, just install ffap.el somewhere in your
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;; `load-path', byte-compile it, and add the following two lines near
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; the end of your ~/.emacs (or equivalent) file:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; (require 'ffap) ; load this file
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;; (global-set-key "\C-x\C-f" 'find-file-at-point)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;; Other Packages: ffap notices the presence of several other packages
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;; when it is loaded. In particular, if you use ange-ftp, efs, w3,
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;; complete, or ff-paths (version < 3.00), it is best to load or
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;; autoload them before loading ffap (ffap does not need any of them).
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;; If you use ff-paths version >= 3.00, load it after ffap.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;; Fancier Setup:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;; ffap has many options. The next comment block contains some
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; fancier code that you might want to adapt for your .emacs. For
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;; even more features, look at the documentation (M-x apropos ffap),
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;; and perhaps check the comments in the "User Variables" and "Peanut
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;; Gallery" sections of this file.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;; ;; Before loading ffap:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;; (setq ffap-url-regexp nil) ; to disable all URL features
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;; ;; Loading ffap:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;; (require 'ffap) ; as in "Quick Setup" above
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;; After loading ffap:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 ;; (global-set-key "\C-x\C-f" 'find-file-at-point) ; as in "Quick Setup"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 ;; (global-set-key "\C-x4f" 'ffap-other-window) ; or \C-f
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ;; (global-set-key "\C-x5f" 'ffap-other-frame) ; or \C-f
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;; (setq ffap-alist ; remove something in `ffap-alist'
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;; (delete (assoc 'c-mode ffap-alist) ffap-alist))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 ;; (setq ffap-alist ; add something to `ffap-alist'
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;; (cons
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 ;; (cons "^[Yy][Ss][Nn][0-9]+$"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 ;; (defun ffap-ysn (name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 ;; (concat
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 ;; "http://snorri.chem.washington.edu/ysnarchive/issuefiles/"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 ;; (substring name 3) ".html")))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 ;; ffap-alist))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 ;; Before or after loading ffap:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 ;; (setq ffap-alist nil) ; disable all `ffap-alist' actions
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 ;; (setq ffap-require-prefix t) ; without prefix, ffap == find-file
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 ;; (setq ffap-machine-p-known 'accept) ; to avoid pinging
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 ;; ;; Choose a mouse binding appropriate for your emacs version:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 ;; (global-set-key [S-mouse-1] 'ffap-at-mouse) ; Emacs 19
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 ;; (global-set-key [(meta button1)] 'ffap-at-mouse) ; XEmacs
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 ;; (and window-system ; Emacs 18 (from .emacs)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 ;; (setq window-setup-hook
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 ;; '(lambda nil (define-key mouse-map x-button-s-left
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 ;; 'ffap-at-mouse))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 ;; ;; Use Netscape instead of w3 to fetch URL's. Mosaic is very similar.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 ;; (if (eq window-system 'x)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 ;; (progn
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 ;; ;; Get browse-url at http://wombat.doc.ic.ac.uk/emacs/browse-url.el,
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 ;; ;; or get a (probably out of date) copy from the ftp site above.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 ;; (autoload 'browse-url-netscape "browse-url" nil t)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 ;; (setq ffap-url-fetcher 'browse-url-netscape)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 ;; ;; Or for a hairier ffap-url-fetcher, get ffap-url.el (same ftp site).
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 ;; ;; Support for gnus, vm, rmail (see hook definitions for bindings):
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 ;; (add-hook 'gnus-summary-mode-hook 'ffap-gnus-hook)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 ;; (add-hook 'gnus-article-mode-hook 'ffap-gnus-hook)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 ;; (add-hook 'vm-mode-hook 'ffap-ro-mode-hook)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 ;; (add-hook 'rmail-mode-hook 'ffap-ro-mode-hook)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 ;;; Related packages:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 ;; If you have hyperbole, you may not need this package, although ffap
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 ;; is smaller and smarter at this particular task. Also note that w3
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 ;; (ftp.cs.indiana.edu:/pub/elisp/w3/README) offers a similar command
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 ;; w3-follow-url-at-point.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 ;; The browse-url package (above) notices URL's and hands them off to
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 ;; w3 or an external WWW browser. Package |~/misc/goto-address.el.gz|
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 ;; by Eric J. Ding <ericding@mit.edu> notices URL's and mail
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 ;; addresses, and can pre-fontify a buffer to highlight them. Gnus5
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 ;; (ding) and vm also provide similar support in their messages.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 ;;; Examples:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 ;; Try M-x find-file-at-point (maybe {C-x C-f}) on these examples.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 ;; These local file examples use ordinary find-file:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 ;; ffap.el, /etc/motd, $MAIL -- find local or absolute files
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 ;; .emacs book.sty info/cl pwd.h -- search paths depending on filename
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 ;; (require 'rmail) -- search paths depending on major-mode
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 ;; file:/etc/motd -- depends on `ffap-url-unwrap-local'
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ;; These remote file examples work if you have ange-ftp or efs:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 ;; ftp:/pub -- no ping (always works)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 ;; ftp.x.org:README -- no ping, a nice recursive example
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 ;; anonymous@ftp.x.org:/README -- synonym
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 ;; ftp.x.org://README -- synonym
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 ;; ftp://ftp.x.org/README -- depends on `ffap-url-unwrap-remote'
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 ;; ftp.mathcs.emory.edu -- depends on `ffap-machine-p-known'
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 ;; mic@ftp:/ -- depends on `ffap-machine-p-local'
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ;; ftp.mathcs.emory.edu:/ -- depends on `ffap-ftp-sans-slash-regexp'
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 ;; These URL examples use `ffap-url-fetcher' (default w3-fetch):
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 ;; http://www.cc.emory.edu
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 ;; http://www.cs.indiana.edu/elisp/w3/docs.html
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 ;; http://info.cern.ch/default.html
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 ;; news:news.newusers.questions
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 ;; mailto:mic@mathcs.emory.edu
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 ;; mic@mathcs.emory.edu -- same as previous
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 ;; <mic@mathcs.emory.edu> -- same as previous
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 ;; <root> -- mailto:root
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 ;; <mic.9@mathcs.emory.edu> -- see `ffap-foo@bar-prefix'
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 ;; file:/etc/motd -- see `ffap-url-unwrap-local'
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 ;; ftp://ftp.x.org/README -- see `ffap-url-unwrap-remote'
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 ;; Multiline gopher blocks (as in .gopherrc and usenet of yesteryear):
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 ;; Type=1
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 ;; Name=Electronic Texts (ffap ignores this)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 ;; Path=
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 ;; Host=etext.archive.umich.edu
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 ;; Port=70
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 ;;; Code:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (provide 'ffap)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 ;;; User Variables:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 ;; This function is used inside defvars:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (defun ffap-soft-value (name &optional default)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 ;; Avoid interning. Bug: (ffap-soft-value "nil" 5) --> 5
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (let ((sym (intern-soft name)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (if (and sym (boundp sym)) (symbol-value sym) default)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (defvar ffap-ftp-regexp
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (and
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (or (featurep 'ange-ftp)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (featurep 'efs)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (and (boundp 'file-name-handler-alist) ; v19
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (or (rassq 'ange-ftp-hook-function file-name-handler-alist)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (rassq 'efs-file-handler-function file-name-handler-alist))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 ;; Apparently this is good enough for both ange-ftp and efs:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 "\\`/[^/:]+:")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 "*Treat paths matching this as remote ftp paths. Nil to disable.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 Nil also disables the generation of such paths by ffap.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (defvar ffap-url-unwrap-local t
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 "*If set, convert local \"file:\" URL to path before prompting.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (defvar ffap-url-unwrap-remote t
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 "*Convert remote \"file:\" or \"ftp:\" URL to path before prompting.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 This is ignored if `ffap-ftp-regexp' is nil.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (defvar ffap-ftp-default-user
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (if (or (equal (ffap-soft-value "ange-ftp-default-user") "anonymous")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (equal (ffap-soft-value "efs-default-user") "anonymous"))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 "anonymous")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 "*User name in ftp paths generated by ffap (see host-to-ftp-path).
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 Nil to fall back on `efs-default-user' or `ange-ftp-default-user'.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (defvar ffap-rfs-regexp
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 ;; Remote file access built into file system? HP rfa or Andrew afs:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 "\\`/\\(afs\\|net\\)/."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 ;; afs only: (and (file-exists-p "/afs") "\\`/afs/.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 "*Paths matching this are remote file-system paths. Nil to disable.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (defvar ffap-url-regexp
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 ;; Could just use `url-nonrelative-link' of w3, if loaded.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 ;; This regexp is not exhaustive, it just matches common cases.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (concat
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 "\\`\\("
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 "news\\(post\\)?:\\|mailto:\\|file:" ; no host ok
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 "\\|"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 "\\(ftp\\|http\\|telnet\\|gopher\\|www\\|wais\\)://" ; needs host
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 "\\)." ; require one more character
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 )
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 "Regexp matching URL's, or nil to disable.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (defvar ffap-foo@bar-prefix "mailto"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 "*Presumed url prefix type of strings like \"<foo.9z@bar>\".
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 Sensible values are nil, \"news\", or \"mailto\".")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 ;;; Peanut Gallery:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 ;; Users of ffap occasionally suggest new features. If I consider
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 ;; those features interesting but not clear winners (a matter of
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 ;; personal taste) I try to leave options to enable them. Read
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 ;; through this section, and for any features you like, put an
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 ;; appropriate form in your ~/.emacs file.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (defvar ffap-dired-wildcards nil ; "[*?][^/]*$"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 ;; From RHOGEE, 07 Jul 1994.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 ;; Disabled: dired is still available by "C-x C-d <pattern>", and
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 ;; valid filenames may contain wildcard characters.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 "*A regexp matching filename wildcard characters, or nil.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 If find-file-at-point gets a filename matching this pattern,
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 it passes it on to dired instead of find-file.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (defvar ffap-newfile-prompt nil ; t
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 ;; From RHOGEE, 11 Jul 1994.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 ;; Disabled: this is better handled by `find-file-not-found-hooks'.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 "*Whether find-file-at-point prompts about a nonexistent file.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (defvar ffap-require-prefix nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 ;; From RHOGEE, 20 Oct 1994.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 ;; This is nil so that neophytes notice ffap. Experts instead may
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 ;; prefer to disable ffap most of the time.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 "*If set, reverses the prefix argument to find-file-at-point.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (defvar ffap-file-finder
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 ;; From RHOGEE, 20 Oct 1994.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 ;; This allows compatibility with ff-paths version < 3.00.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 ;; For ff-paths version >= 3.00, just load it after ffap.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (if (commandp 'find-file-using-paths)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 'find-file-using-paths
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 ;; Try to overcome load-order dependency:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (eval-after-load
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 "ff-paths"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 '(and (commandp 'find-file-using-paths)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (setq ffap-file-finder find-file-using-paths)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 'find-file)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 "*The command symbol called by find-file-at-point to find a file.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 Probably find-file, or find-file-using-paths if you use ff-paths
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 with version < 3.00.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (put 'ffap-file-finder 'risky-local-variable t)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 (defvar ffap-url-fetcher 'w3-fetch
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 "*A function of one argument, called by ffap to fetch URL's.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 The default is w3-fetch from the w3 package. If you prefer Mosaic or
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 Netscape, install http://wombat.doc.ic.ac.uk/emacs/browse-url.el, and
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 add one of the following lines to your setup:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 \(setq ffap-url-fetcher 'browse-url-netscape\)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 \(setq ffap-url-fetcher 'browse-url-mosaic\)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 Or for something hairier \(choose fetch method based on url type and
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 prompting\) get ffap-url.el wherever you ffap.el."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 ;; Big old `lambda' examples deleted. Some remote-control references:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 ;; http://www.ncsa.uiuc.edu/SDG/Software/XMosaic/remote-control.html
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 ;; http://home.netscape.com/newsref/std/x-remote.html
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 )
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (put 'ffap-url-fetcher 'risky-local-variable t)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 ;;; Command ffap-next:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 ;; Original ffap-next-url (URL's only) from RPECK 30 Mar 1995.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 ;; Since then, broke up into ffap-next-guess (noninteractive) and
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 ;; ffap-next (a command), now work on files as well as url's.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (defvar ffap-next-regexp
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 ;; If you want ffap-next to find URL's only, try this:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 ;; (and ffap-url-regexp (string-match "\\\\`" ffap-url-regexp)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 ;; (concat "\\<" (substring ffap-url-regexp 2))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 ;; It pays to put a big fancy regexp here, since ffap-guesser is
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 ;; much more time-consuming than regexp searching:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 "[/:.~a-zA-Z]/\\|@[a-zA-Z][-a-zA-Z0-9]*\\."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 "*Regular expression governing search of ffap-next.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (defvar ffap-next-guess nil "Last value returned by `ffap-next-guess'.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (defun ffap-next-guess (&optional back lim)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 "Move point to next file or url, and return it as a string.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 If nothing found, leaves point at limit and returns nil.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 Optional BACK argument makes search backwards.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 Optional LIM argument limits the search.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 Only considers strings that match `ffap-next-regexp'."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (or lim (setq lim (if back (point-min) (point-max))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (let (guess)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (while (not (or guess (eq (point) lim)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (funcall (if back 're-search-backward 're-search-forward)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 ffap-next-regexp lim 'move)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (setq guess (ffap-guesser)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 ;; Go to end, so we do not get same guess twice:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (goto-char (nth (if back 0 1) ffap-string-at-point-region))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (setq ffap-next-guess guess)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 ;;;###autoload
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (defun ffap-next (&optional back wrap)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 "Search buffer for next file or url, and run ffap.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 Optional argument BACK says to search backwards.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 Optional argument WRAP says to try wrapping around if necessary.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 Interactively: use a single prefix to search backwards,
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 double prefix to wrap forward, triple to wrap backwards.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 Actual search is done by ffap-next-guess."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (interactive
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 (cdr (assq (prefix-numeric-value current-prefix-arg)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 '((1) (4 t) (16 nil t) (64 t t)))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (let ((pt (point))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 (guess (ffap-next-guess back)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 ;; Try wraparound if necessary:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (and (not guess) wrap
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (goto-char (if back (point-max) (point-min)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (setq guess (ffap-next-guess back pt)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (if guess
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (progn
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (sit-for 0) ; display point movement
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (find-file-at-point (ffap-prompter guess)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (goto-char pt) ; restore point
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (message "No %sfiles or URL's found."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (if wrap "" "more ")))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (defun ffap-next-url (&optional back wrap)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 "Just like ffap-next, but searches with `ffap-url-regexp'."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (interactive)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 (let ((ffap-next-regexp ffap-url-regexp))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (if (interactive-p)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 (call-interactively 'ffap-next)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (ffap-next back wrap))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 ;;; Hooks for GNUS, VM, Rmail:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 ;; See "Installation" above for suggested use of these hooks.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 ;; If you do not like these bindings, just write hooks with
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 ;; whatever bindings you would prefer.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 ;; Any suggestions of more "memorable" bindings? -- Mic
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (defun ffap-ro-mode-hook nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 "Binds ffap-gnus-next and ffap-gnus-menu to M-l and M-m, resp."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (local-set-key "\M-l" 'ffap-next)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (local-set-key "\M-m" 'ffap-menu)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 )
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (defun ffap-gnus-hook nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 "Binds ffap-gnus-next and ffap-gnus-menu to L and M, resp."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 (set (make-local-variable 'ffap-foo@bar-prefix) "news") ; message-id's
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 ;; Note lowercase l and m are taken:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (local-set-key "L" 'ffap-gnus-next)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (local-set-key "M" 'ffap-gnus-menu))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 (defun ffap-gnus-wrapper (form) ; used by both commands below
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (and (eq (current-buffer) (get-buffer gnus-summary-buffer))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 (gnus-summary-select-article)) ; get article of current line
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 ;; Preserve selected buffer, but do not do save-window-excursion,
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 ;; since we want to see any window created by form. Temporarily
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 ;; select the article buffer, so we see any point movement.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (let ((sb (window-buffer (selected-window))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 (gnus-configure-windows 'article)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (pop-to-buffer gnus-article-buffer)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (widen)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 ;; Skip headers at first, for ffap-gnus-next (which wraps around)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (if (eq (point) (point-min)) (search-forward "\n\n" nil t))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (unwind-protect
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (eval form)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (pop-to-buffer sb))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (defun ffap-gnus-next nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 "Run ffap-next in the GNUS article buffer."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (interactive) (ffap-gnus-wrapper '(ffap-next nil t)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 (defun ffap-gnus-menu nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 "Run ffap-menu in the GNUS article buffer."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 (interactive) (ffap-gnus-wrapper '(ffap-menu)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 ;;; Remote machines and paths:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (fset 'ffap-replace-path-component
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 (if (or (featurep 'efs)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (and
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 (boundp 'file-name-handler-alist) ; v19
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 (rassq 'efs-file-handler-function file-name-handler-alist)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 'efs-replace-path-component
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 'ange-ftp-replace-name-component))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (defun ffap-file-exists-string (file)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 ;; With certain packages (ange-ftp, jka-compr?) file-exists-p
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 ;; sometimes returns a nicer string than it is given. Otherwise, it
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 ;; just returns nil or t.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 "Return FILE \(maybe modified\) if it exists, else nil."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (let ((exists (file-exists-p file)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 (and exists (if (stringp exists) exists file))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 ;; I cannot decide a "best" strategy here, so these are variables. In
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 ;; particular, if `Pinging...' is broken or takes too long on your
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 ;; machine, try setting these all to accept or reject.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (defvar ffap-machine-p-local 'reject ; this happens often
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 "A symbol, one of: ping, accept, reject.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 This is what ffap-machine-p does with hostnames that have no domain.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 (defvar ffap-machine-p-known 'ping ; 'accept for speed
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 "A symbol, one of: ping, accept, reject.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 This is what ffap-machine-p does with hostnames that have a known domain
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 \(see lisp/mail-extr.el for the list of known domains\).")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 (defvar ffap-machine-p-unknown 'reject
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 "A symbol, one of: ping, accept, reject.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 This is what ffap-machine-p does with hostnames that have an unknown domain
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 \(see lisp/mail-extr.el for the list of known domains\).")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 (defvar ffap-machine-p-known-domains
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 '("com" "edu" "net" "org" "mil" "gov" "us" "arpa") ; USA USA...
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 ;; This variable is mainly for emacs18.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 "Top-level domains known to ffap. Ignored if mail-extr is loadable.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (defun ffap-machine-p (host &optional service quiet)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 "Indicate whether HOST is the name of a real machine.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 The variables ffap-machine-p-local, ffap-machine-p-known, and ffap-machine-p-unknown
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 control ffap-machine-p depending on HOST's domain \(none/known/unknown\).
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 Pinging is done using open-network-stream to decide HOST existence.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 Optional SERVICE specifies the service used \(default \"discard\"\).
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 Optional QUIET flag suppresses the \"Pinging...\" message.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 Returned values:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 A t value means that HOST answered.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 A symbol \(accept\) means the relevant variable told us to accept.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 A string means the machine exists, but does not respond for some reason."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 ;; Try some:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 ;; (ffap-machine-p "ftp")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 ;; (ffap-machine-p "nonesuch")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 ;; (ffap-machine-p "ftp.mathcs.emory.edu")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 ;; (ffap-machine-p "foo.bonk")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 ;; (ffap-machine-p "foo.bonk.com")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 ;; (ffap-machine-p "cs" 5678)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 ;; (ffap-machine-p "gopher.house.gov")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 ;; Not known to 19.28
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 ;; (ffap-
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 (if (or (string-match "[^-a-zA-Z0-9.]" host) ; Illegal chars (?)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 (not (string-match "[^0-9]" host))) ; all numeric! reject it
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 (let* ((domain
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 (and (string-match "\\.[^.]*$" host)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 (downcase (substring host (1+ (match-beginning 0))))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 (domain-name ; t, "Country", "Local", or nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 (cond
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 ((not domain) "Local")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 ;; common non-country domains (some imply US though):
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 ;; t)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 (t
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 ;; Use domain-name properties from v19 lisp/mail-extr.el;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 ;; bbdb/mail-extr also puts this in `all-top-level-domains'.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 (if (or (featurep 'mail-extr)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 (and (load "mail-extr" t t)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 ;; It became a feature between 19.22 and 19.28
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 (provide 'mail-extr)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 (get (intern-soft
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 domain
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 (condition-case nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 mail-extr-all-top-level-domains
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 ;; Before 19.28, the symbols were in `obarray':
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 (error obarray)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 'domain-name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 ;; Emacs18 does not have mail-extr:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 (and (member domain ffap-machine-p-known-domains) t))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 )))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 (strategy
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 (cond ((not domain) ffap-machine-p-local)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 ((not domain-name) ffap-machine-p-unknown)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 (ffap-machine-p-known))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 (cond
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 ((eq strategy 'accept) 'accept)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 ((eq strategy 'reject) nil)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 ;; assume (eq strategy 'ping)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 (t
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 (or quiet
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 (if (stringp domain-name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 (message "Pinging %s (%s)..." host domain-name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 (message "Pinging %s ..." host)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 (condition-case error
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 (progn
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 (delete-process
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 (open-network-stream
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 "ffap-machine-p" nil host (or service "discard")))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 t)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 (error
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 (let ((mesg (car (cdr error))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 (cond
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 ;; v18:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 ((string-match "^Unknown host" mesg) nil)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 ((string-match "not responding$" mesg) mesg)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 ;; v19:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 ;; (file-error "connection failed" "permission denied"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 ;; "nonesuch" "ffap-machine-p")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 ;; (file-error "connection failed" "host is unreachable"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 ;; "gopher.house.gov" "ffap-machine-p")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 ;; (file-error "connection failed" "address already in use"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 ;; "ftp.uu.net" "ffap-machine-p")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 ((equal mesg "connection failed")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 (if (equal (nth 2 error) "permission denied")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 nil ; host does not exist
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 ;; Other errors mean host exists:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 (nth 2 error)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 ;; Could be "Unknown service":
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 (t (signal (car error) (cdr error))))))))))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 (defun ffap-file-remote-p (filename)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 "If FILENAME looks remote, return it \(maybe slightly improved\)."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 ;; (ffap-file-remote-p "/user@foo.bar.com:/pub")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 ;; (ffap-file-remote-p "/foo.dom://path")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 (or (and ffap-ftp-regexp
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 (string-match ffap-ftp-regexp filename)
13979
278af59c9e29 (ffap-list-env): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 13905
diff changeset
569 ;; Convert "/host://path" to "/host:/path", to handle a dying
13531
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 ;; practice of advertising ftp paths as "host.dom://path".
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 (if (string-match "//" filename)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 (concat (substring filename 0 (match-beginning 0))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 (substring filename (1- (match-end 0))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 filename))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 (and ffap-rfs-regexp
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 (string-match ffap-rfs-regexp filename)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 filename)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 (defun ffap-machine-at-point nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 "Return machine name from around point if it exists, or nil."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 (let ((mach (ffap-string-at-point "-a-zA-Z0-9." nil ".")))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 (and (ffap-machine-p mach) mach)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 (defun ffap-fixup-machine (mach)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 ;; Convert a machine into an URL, an ftp path, or nil.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 (cond
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 ((not (and ffap-url-regexp (stringp mach))) nil)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 ((string-match "\\`gopher[-.]" mach) ; or "info"?
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 (concat "gopher://" mach "/"))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 ((and (string-match "\\`w\\(ww\\|eb\\)[-.]" mach))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 (concat "http://" mach "/"))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 ;; More cases? Maybe "telnet:" for archie?
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 (ffap-ftp-regexp (ffap-host-to-path mach))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 ))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 (defun ffap-host-to-path (host)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597 "Convert \"HOST\" to \"/anonymous@HOST:\" (or \"\" for \"localhost\").
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 Variable `ffap-ftp-default-user' overrides or suppresses \"anonymous\"."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 (if (equal host "localhost")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 ""
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601 (if ffap-ftp-default-user
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 (concat "/" ffap-ftp-default-user "@" host ":")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 (concat "/" host ":"))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605 (defun ffap-newsgroup-p (string)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 "Return STRING if it looks like a newsgroup name, else nil."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607 (and
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 (string-match ffap-newsgroup-regexp string)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 (let ((htbs '(gnus-active-hashtb gnus-newsrc-hashtb gnus-killed-hashtb))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 (heads ffap-newsgroup-heads)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 htb ret)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 (while htbs
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 (setq htb (car htbs) htbs (cdr htbs))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614 (condition-case nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 (progn
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 ;; errs: htb symbol may be unbound, or not a hash-table.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 ;; gnus-gethash is just a macro for intern-soft.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 (and (intern-soft string (symbol-value htb))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619 (setq ret string htbs nil))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620 ;; If we made it this far, GNUS is running, so ignore "heads":
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 (setq heads nil))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622 (error nil)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 (or ret (not heads)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 (let ((head (string-match "\\`\\([a-z]+\\)\\." string)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625 (and head (setq head (substring string 0 (match-end 1)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 (member head heads)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 (setq ret string))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 ;; Ever any need to modify string as a newsgroup name?
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629 ret)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630 (defvar ffap-newsgroup-regexp "^[a-z]+\\.[-+a-z_0-9.]+$"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631 "ffap-newsgroup-p quickly rejects strings that do not match this.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 (defvar ffap-newsgroup-heads ; entirely inadequate
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 '("alt" "comp" "gnu" "misc" "news" "sci" "soc" "talk")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 "Used by ffap-newsgroup-p if GNUS is not running.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 (defun ffap-url-p (string)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637 "If STRING looks like an URL, return it (maybe improved), else nil."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 ;; Does it look like an URL? Ignore case.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 (let ((case-fold-search t))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 (and ffap-url-regexp (string-match ffap-url-regexp string)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 ;; I lied, no improvement:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 string)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 ;; Broke these two out of ffap-fixup-url, for sake of ffap-url package.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 (defun ffap-url-unwrap-local (url)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 "Return unwrapped local file URL, or nil. Ignores ffap-* variables."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 (and (string-match "\\`\\(file\\|ftp\\):/?\\([^/]\\|\\'\\)" url)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 (substring url (1+ (match-end 1)))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 (defun ffap-url-unwrap-remote (url)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 "Return unwrapped remote file URL, or nil. Ignores ffap-* variables."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 (and (string-match "\\`\\(ftp\\|file\\)://\\([^:/]+\\):?\\(/.*\\)" url)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 (concat
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 (ffap-host-to-path (substring url (match-beginning 2) (match-end 2)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 (substring url (match-beginning 3) (match-end 3)))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 (defun ffap-fixup-url (url)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 "Given URL, clean it up and return it. May become a file name."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 (cond
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 ((not (stringp url)) nil)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 ((and ffap-url-unwrap-local (ffap-url-unwrap-local url)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 ((and ffap-url-unwrap-remote ffap-ftp-regexp
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 (ffap-url-unwrap-remote url)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663 ;; Do not load w3 just for this:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 (t (let ((normal (and (fboundp 'url-normalize-url)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665 (url-normalize-url url))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 ;; In case url-normalize-url is confused:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 (or (and normal (not (zerop (length normal))) normal)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 url)))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 ;;; `ffap-alist':
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 ;; Search actions depending on the major-mode or extensions of the
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 ;; current name. Note all the little defun's could be broken out, at
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 ;; some loss of locality. I have had a vote for eliminating this
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 ;; from ffap (featuritis)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678 ;; First, some helpers for functions in `ffap-alist':
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 (defun ffap-list-env (env &optional empty)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681 ;; Replace this with parse-colon-path (lisp/files.el)?
13979
278af59c9e29 (ffap-list-env): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 13905
diff changeset
682 "Directory list parsed from \":\"-separated ENVironment variable.
13531
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683 Optional EMPTY is default if (getenv ENV) is undefined, and is also
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684 substituted for the first empty-string component, if there is one."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 ;; Derived from psg-list-env in RHOGEE's ff-paths and
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 ;; bib-cite packages. The `empty' argument is intended to mimic
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687 ;; the semantics of TeX/BibTeX variables, it is substituted for
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 ;; any empty string entry.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
689 (if (or empty (getenv env)) ; should return something
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 (let ((start 0) match dir ret)
13905
7df0a9cb269a (ffap-list-env): Use `path-separator' rather than ":".
Richard M. Stallman <rms@gnu.org>
parents: 13531
diff changeset
691 (setq env (concat (getenv env) path-separator)) ; note undefined -> ":"
7df0a9cb269a (ffap-list-env): Use `path-separator' rather than ":".
Richard M. Stallman <rms@gnu.org>
parents: 13531
diff changeset
692 (while (setq match (string-match path-separator env start))
13531
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693 (setq dir (substring env start match) start (1+ match))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694 ;;(and (file-directory-p dir) (not (member dir ret)) ...)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
695 (setq ret (cons dir ret)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
696 (setq ret (nreverse ret))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 (and empty (setq match (member "" ret))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698 (progn
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699 (setcdr match (append (cdr-safe empty) (cdr match)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
700 (setcar match (or (car-safe empty) empty))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
701 ret)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
703 (defun ffap-reduce-path (path)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704 "Remove duplicates or non-dirs from PATH."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705 (let (ret tem)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706 (while path
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707 (setq tem path path (cdr path))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 (or (member (car tem) ret)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709 (not (file-directory-p (car tem)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710 (progn (setcdr tem ret) (setq ret tem))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 (nreverse ret)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713 (defun ffap-add-subdirs (path)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 "Return PATH augmented with its immediate subdirectories."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 ;; (ffap-add-subdirs '("/notexist" "~"))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 (let (ret subs)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 (while path
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 (mapcar
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 (function
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720 (lambda (f) (and (file-directory-p f) (setq ret (cons f ret)))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 (condition-case nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 (directory-files (car path) t "[^.]")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 (error nil)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 (setq ret (cons (car path) ret)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 path (cdr path)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726 (nreverse ret)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 (defvar ffap-locate-jka-suffixes t
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 "List of compression suffixes that ffap-locate-file tries.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 If not a list, it will be initialized by ffap-locate-file,
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731 and it will become nil unless you are using jka-compr.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732 You might set this to nil or a list like '(\".gz\" \".z\" \".Z\").")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 (defun ffap-locate-file (file &optional nosuffix path)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 ;; If this package is only working in v19 now, maybe should
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736 ;; replace this with a quiet version of locate-library.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 "A generic path-searching function, defaults mimic `load' behavior.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 Returns path of an existing FILE that (load FILE) would load, or nil.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739 Optional second argument NOSUFFIX, if t, is like the fourth argument
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740 for load, i.e. don't try adding suffixes \".elc\" and \".el\".
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 If a list, it is taken as a list of suffixes to try instead.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 Optional third argument PATH specifies a different search path, it
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 defaults to `load-path'."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 (or path (setq path load-path))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745 (if (file-name-absolute-p file)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
746 (setq path (list (file-name-directory file))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747 file (file-name-nondirectory file)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 (let ((suffixes-to-try
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 (cond
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750 ((consp nosuffix) nosuffix)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751 (nosuffix '(""))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752 (t '(".elc" ".el" "")))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753 ;; Compensate for modern (19.28) jka-compr, that no longer searches
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
754 ;; for foo.gz when you asked for foo:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 (or (listp ffap-locate-jka-suffixes)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
756 (setq ffap-locate-jka-suffixes
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
757 (and (featurep 'jka-compr) ; an early version was jka-compr19
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758 (not (featurep 'jka-aux))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759 jka-compr-file-name-handler-entry
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 (not (string-match
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
761 (car jka-compr-file-name-handler-entry)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762 "foo"))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
763 ;; Hard to do cleverly across various jka-compr versions:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764 '(".gz" ".Z"))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
765 (if ffap-locate-jka-suffixes
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
766 (setq suffixes-to-try
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
767 (apply
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
768 'nconc
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
769 (mapcar
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
770 (function
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771 (lambda (suf)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
772 (cons suf
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
773 (mapcar
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774 (function (lambda (x) (concat suf x)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775 ffap-locate-jka-suffixes))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776 suffixes-to-try))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777 (let (found suffixes)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778 (while (and path (not found))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779 (setq suffixes suffixes-to-try)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
780 (while (and suffixes (not found))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
781 (let ((try (expand-file-name
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
782 (concat file (car suffixes))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
783 (car path))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784 (if (and (file-exists-p try) (not (file-directory-p try)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785 (setq found try)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
786 (setq suffixes (cdr suffixes)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787 (setq path (cdr path)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
788 found)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
789
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790 (defvar ffap-alist
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791 ;; A big mess! Parts are probably useless.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792 (list
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
793 (cons "\\.info\\'"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794 (defun ffap-info (name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
795 (ffap-locate-file
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 name '("" ".info")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797 (or (ffap-soft-value "Info-directory-list")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798 (ffap-soft-value "Info-default-directory-list")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799 ;; v18:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800 (list (ffap-soft-value "Info-directory" "~/info/"))))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
801 ;; Since so many info files do not have .info extension, also do this:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
802 (cons "\\`info/"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
803 (defun ffap-info-2 (name) (ffap-info (substring name 5))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
804 (cons "\\`[-a-z]+\\'"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
805 ;; This ignores the node! "(emacs)Top" same as "(emacs)Intro"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
806 (defun ffap-info-3 (name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
807 (and (equal (ffap-string-around) "()") (ffap-info name))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
808 (cons "\\.elc?\\'"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
809 (defun ffap-el (name) (ffap-locate-file name t)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
810 (cons 'emacs-lisp-mode
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
811 (defun ffap-el-mode (name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
812 ;; We do not bother with "" here, since it was considered above.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
813 ;; Also ignore "elc", for speed (who else reads elc files?)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
814 (and (not (string-match "\\.el\\'" name))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
815 (ffap-locate-file name '(".el")))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816 '(finder-mode . ffap-el-mode) ; v19: {C-h p}
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
817 '(help-mode . ffap-el-mode) ; v19.29
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
818 (cons 'c-mode
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
819 (progn
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
820 ;; Need better default here:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
821 (defvar ffap-c-path '("/usr/include" "/usr/local/include"))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
822 (defun ffap-c-mode (name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
823 (ffap-locate-file name t ffap-c-path))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
824 '(c++-mode . ffap-c-mode)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
825 '(cc-mode . ffap-c-mode)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
826 '("\\.\\([chCH]\\|cc\\|hh\\)\\'" . ffap-c-mode)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
827 (cons 'tex-mode
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
828 ;; Complicated because auctex may not be loaded yet.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
829 (progn
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
830 (defvar ffap-tex-path
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
831 (ffap-reduce-path
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
832 (append
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
833 (list ".")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
834 (ffap-list-env "TEXINPUTS")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
835 ;; (ffap-list-env "BIBINPUTS")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
836 (ffap-add-subdirs
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
837 (ffap-list-env "TEXINPUTS_SUBDIR"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
838 (ffap-soft-value
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
839 "TeX-macro-global"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
840 '("/usr/local/lib/tex/macros"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
841 "/usr/local/lib/tex/inputs")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
842 )))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
843 "*Where ffap-tex-mode looks for tex files.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
844 (defun ffap-tex-mode (name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
845 (ffap-locate-file name '(".tex" "") ffap-tex-path))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
846 (cons 'latex-mode
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
847 (defun ffap-latex-mode (name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
848 ;; Any real need for "" here?
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
849 (ffap-locate-file name '(".sty" ".tex" "") ffap-tex-path)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
850 (cons "\\.\\(tex\\|sty\\|doc\\)\\'"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
851 (defun ffap-tex (name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
852 (ffap-locate-file name t ffap-tex-path)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
853 (cons "\\.bib\\'"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
854 (defun ffap-bib (name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
855 (ffap-locate-file
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
856 name t
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
857 (ffap-list-env "BIBINPUTS" '("/usr/local/lib/tex/macros/bib")))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
858 (cons 'math-mode
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
859 (defun ffap-math-mode (name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
860 (while (string-match "`" name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
861 (setq name (concat (substring name 0 (match-beginning 0))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
862 "/"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
863 (substring name (match-end 0)))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
864 (ffap-locate-file
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
865 name '(".m" "") (ffap-soft-value "Mathematica-search-path"))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
866 (cons "\\`\\." (defun ffap-home (name) (ffap-locate-file name t '("~"))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
867 (cons "\\`~/"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
868 ;; Maybe a "Lisp Code Directory" reference:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
869 (defun ffap-lcd (name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
870 (and
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
871 (or
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
872 ;; lisp-dir-apropos output buffer:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
873 (string-match "Lisp Code Dir" (buffer-name))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
874 ;; Inside an LCD entry like |~/misc/ffap.el.Z|,
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
875 ;; or maybe the holy LCD-Datafile itself:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
876 (member (ffap-string-around) '("||" "|\n")))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
877 (concat
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
878 ;; lispdir.el may not be loaded yet:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
879 (ffap-host-to-path
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
880 (ffap-soft-value "elisp-archive-host"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
881 "archive.cis.ohio-state.edu"))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
882 (file-name-as-directory
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
883 (ffap-soft-value "elisp-archive-directory"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
884 "/pub/gnu/emacs/elisp-archive/"))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
885 (substring name 2)))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
886 (cons "^[Rr][Ff][Cc][- #]?\\([0-9]+\\)" ; no $
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
887 (progn
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
888 (defvar ffap-rfc-path
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
889 (concat (ffap-host-to-path "ds.internic.net") "/rfc/rfc%s.txt"))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
890 (defun ffap-rfc (name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
891 (format ffap-rfc-path
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
892 (substring name (match-beginning 1) (match-end 1))))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
893 )
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
894 "Alist of \(KEY . FUNCTION\), applied to text around point.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
895
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
896 If ffap-file-at-point has a string NAME (maybe \"\") which is not an
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
897 existing filename, it looks for pairs with a matching KEY:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
898 * if KEY is a symbol, it should equal `major-mode'.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
899 * if KEY is a string, it should match NAME as a regular expression.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
900 If KEY matches, ffap-file-at-point calls \(FUNCTION NAME\).
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
901 FUNCTION should return a file, url, or nil \(nil means keep looking
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
902 for more KEY matches\). Note URL's are ok despite the function name.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
903 (put 'ffap-alist 'risky-local-variable t)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
904
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
905
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
906 ;;; At-Point Functions:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
907
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
908 (defvar ffap-string-at-point-mode-alist
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
909 '(
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
910 ;; Slightly controversial decisions:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
911 ;; * strip trailing "@" and ":"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
912 ;; * no commas (good for latex)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
913 (t "--:$+<>@-Z_a-z~" "<@" "@>;.,!?:")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
914 (math-mode ",-:$+<>@-Z_a-z~`" "<" "@>;.,!?`:") ; allow backquote
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
915 ;; Note: you are better off using "C-c C-c" in compilation buffers:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
916 ;; Maybe handle "$HOME", or "$(HOME)/bin/foo" in makefile-mode?
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
917 )
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
918 "Alist of \(MODE CHARS BEG END\), where MODE is a major-mode or t.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
919 The data are arguments to ffap-string-at-point, used to guess the
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
920 filename at point. The `t' entry is the default.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
921
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
922 (defvar ffap-string-at-point-region '(1 1)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
923 "List (BEG END), last region returned by ffap-string-at-point.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
924
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
925 (defvar ffap-string-at-point nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
926 ;; Added at suggestion of RHOGEE (for ff-paths), 7/24/95.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
927 "Last string returned by ffap-string-at-point.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
928 (defun ffap-string-at-point (&optional chars begpunct endpunct)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
929 "Return maximal string of CHARS (a string) around point.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
930 Optional BEGPUNCT chars before point are stripped from the beginning;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
931 Optional ENDPUNCT chars after point are stripped from the end.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
932 Without arguments, uses `ffap-string-at-point-mode-alist'.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
933 Also sets `ffap-string-at-point' and `ffap-string-at-point-region'."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
934 (if chars
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
935 (let* ((pt (point))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
936 (str
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
937 (buffer-substring
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
938 (save-excursion
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
939 (skip-chars-backward chars)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
940 (and begpunct (skip-chars-forward begpunct pt))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
941 (setcar ffap-string-at-point-region (point)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
942 (save-excursion
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
943 (skip-chars-forward chars)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
944 (and endpunct (skip-chars-backward endpunct pt))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
945 (setcar (cdr ffap-string-at-point-region) (point))))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
946 (set-text-properties 0 (length str) nil str)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
947 (setq ffap-string-at-point str))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
948 ;; Get default args from `ffap-string-at-point-mode-alist'
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
949 (apply 'ffap-string-at-point
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
950 (cdr (or (assq major-mode ffap-string-at-point-mode-alist)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
951 (assq t ffap-string-at-point-mode-alist)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
952 ;; avoid infinite loop!
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
953 (error "ffap-string-at-point: bad alist")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
954 )))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
955
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
956 (defun ffap-string-around nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
957 ;; Sometimes useful to decide how to treat a string.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
958 "Return string of two characters around last ffap-string-at-point."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
959 (save-excursion
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
960 (format "%c%c"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
961 (progn
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
962 (goto-char (car ffap-string-at-point-region))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
963 (preceding-char)) ; maybe 0
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
964 (progn
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
965 (goto-char (nth 1 ffap-string-at-point-region))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
966 (following-char)) ; maybe 0
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
967 )))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
968
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
969 (defun ffap-url-at-point nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
970 "Return URL from around point if it exists, or nil."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
971 ;; Could use url-get-url-at-point instead ... how do they compare?
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
972 ;; Both handle "URL:", ignore non-relative links, trim punctuation.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
973 ;; The other will actually look back if point is in whitespace, but
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
974 ;; I would rather ffap be non-rabid in such situations.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
975 (and
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
976 ffap-url-regexp
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
977 (or
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
978 ;; In a w3 buffer button zone?
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
979 (let (tem)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
980 (and (eq major-mode 'w3-mode)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
981 ;; assume: (boundp 'w3-zone-at) (boundp 'w3-zone-data)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
982 (setq tem (w3-zone-at (point)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
983 (consp (setq tem (w3-zone-data tem)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
984 (nth 2 tem)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
985 ;; Is there a reason not to strip trailing colon?
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
986 (let ((name (ffap-string-at-point
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
987 ;; Allow leading digits for email/news id's:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
988 "--:?$+@-Z_a-z~#,%" "^A-Za-z0-9" ":;.,!?")))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
989 ;; (case-fold-search t), why?
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
990 (cond
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
991 ((string-match "^url:" name) (setq name (substring name 4)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
992 ((and (string-match "\\`[^:</>@]+@[^:</>@]+[a-zA-Z]\\'" name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
993 ;; "foo@bar": could be "mailto" or "news" (a Message-ID).
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
994 ;; If not adorned with "<>", it must be "mailto".
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
995 ;; Otherwise could be either, so consult `ffap-foo@bar-prefix'.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
996 (let ((prefix (if (and (equal (ffap-string-around) "<>")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
997 ;; At least a couple of odd characters:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
998 (string-match "[$.0-9].*[$.0-9].*@" name))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
999 ;; Could be news:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1000 ffap-foo@bar-prefix
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1001 "mailto")))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1002 (and prefix (setq name (concat prefix ":" name))))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1003 ((ffap-newsgroup-p name) (setq name (concat "news:" name)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1004 ((and (string-match "\\`[a-z0-9]+\\'" name) ; <mic> <root> <nobody>
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1005 (equal (ffap-string-around) "<>")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1006 ;; (ffap-user-p name):
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1007 (not (string-match "~" (expand-file-name (concat "~" name))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1008 )
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1009 (setq name (concat "mailto:" name)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1010 )
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1011 (and (ffap-url-p name) name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1012 ))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1013
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1014 (defvar ffap-gopher-regexp
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1015 "^.*\\<\\(Type\\|Name\\|Path\\|Host\\|Port\\) *= *\\(.*\\) *$"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1016 "Regexp Matching a line in a gopher bookmark (maybe indented).
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1017 Two subexpressions are the KEY and VALUE.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1018
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1019 (defun ffap-gopher-at-point nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1020 "If point is inside a gopher bookmark block, return its url."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1021 ;; We could use gopher-parse-bookmark from gopher.el, but it is not
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1022 ;; so robust, and w3 users are better off without gopher.el anyway.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1023 (save-excursion
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1024 (beginning-of-line)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1025 (if (looking-at ffap-gopher-regexp)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1026 (progn
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1027 (while (and (looking-at ffap-gopher-regexp) (not (bobp)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1028 (forward-line -1))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1029 (or (looking-at ffap-gopher-regexp) (forward-line 1))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1030 (let ((type "1") name path host (port "70"))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1031 (while (looking-at ffap-gopher-regexp)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1032 (let ((var (intern
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1033 (downcase
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1034 (buffer-substring (match-beginning 1)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1035 (match-end 1)))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1036 (val (buffer-substring (match-beginning 2)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1037 (match-end 2))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1038 (set var val)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1039 (forward-line 1)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1040 (if (and path (string-match "^ftp:.*@" path))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1041 (concat "ftp://"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1042 (substring path 4 (1- (match-end 0)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1043 (substring path (match-end 0)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1044 (and (= (length type) 1)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1045 host;; (ffap-machine-p host)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1046 (concat "gopher://" host
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1047 (if (equal port "70") "" (concat ":" port))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1048 "/" type path))))))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1049
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1050 (defvar ffap-ftp-sans-slash-regexp
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1051 (and
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1052 ffap-ftp-regexp
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1053 ;; Note: by now, we know it is not an URL.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1054 ;; Icky regexp avoids: default: 123: foo::bar cs:pub
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1055 ;; It does match on: mic@cs: cs:/pub mathcs.emory.edu: (point at end)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1056 ;; Todo: handle foo.com://path
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1057 "\\`\\([^:@]+@[^:@]+:\\|[^@.:]+\\.[^@:]+:\\|[^:]+:[~/]\\)\\([^:]\\|\\'\\)")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1058 "Strings matching this are coerced to ftp paths by ffap.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1059 That is, ffap just prepends \"/\". Set to nil to disable.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1060
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1061 (defun ffap-file-at-point nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1062 "Return filename from around point if it exists, or nil.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1063 Existence test is skipped for names that look remote.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1064 If the filename is not obvious, it also tries `ffap-alist',
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1065 which may actually result in an URL rather than a filename."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1066 ;; Note: this function does not need to look for URL's, just
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1067 ;; filenames. On the other hand, it is responsible for converting
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1068 ;; a pseudo-URL "site.dom://path" to an ftp path "/site.dom:/path"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1069 (let* ((case-fold-search t) ; url prefixes are case-insensitive
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1070 (data (match-data))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1071 (string (ffap-string-at-point)) ; use its mode-alist
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1072 (name
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1073 (condition-case nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1074 (substitute-in-file-name string)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1075 (error string)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1076 (abs (file-name-absolute-p name))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1077 (default-directory default-directory))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1078 (unwind-protect
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1079 (cond
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1080 ;; Immediate rejects (/ and // are too common in C++):
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1081 ((member name '("" "/" "//")) nil)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1082 ;; Immediately test local filenames. If default-directory is
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1083 ;; remote, you probably already have a connection.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1084 ((and (not abs) (ffap-file-exists-string name)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1085 ;; Accept remote names without actual checking (too slow):
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1086 ((if abs
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1087 (ffap-file-remote-p name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1088 ;; Try adding a leading "/" (common omission in ftp paths):
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1089 (and
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1090 ffap-ftp-sans-slash-regexp
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1091 (string-match ffap-ftp-sans-slash-regexp name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1092 (ffap-file-remote-p (concat "/" name)))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1093 ;; Ok, not remote, try the existence test even if it is absolute:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1094 ((and abs (ffap-file-exists-string name)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1095 ;; File does not exist, try the alist:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1096 ((let ((alist ffap-alist) tem try case-fold-search)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1097 (while (and alist (not try))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1098 (setq tem (car alist) alist (cdr alist))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1099 (if (or (eq major-mode (car tem))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1100 (and (stringp (car tem))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1101 (string-match (car tem) name)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1102 (and (setq try (funcall (cdr tem) name))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1103 (setq try (or
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1104 (ffap-url-p try) ; not a file!
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1105 (ffap-file-remote-p try)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1106 (ffap-file-exists-string try))))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1107 try))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1108 ;; Alist failed? Try to guess an active remote connection
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1109 ;; from buffer variables, and try once more, both as an
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1110 ;; absolute and relative path on that remote host.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1111 ((let* (ffap-rfs-regexp ; suppress
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1112 (remote-dir
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1113 (cond
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1114 ((ffap-file-remote-p default-directory))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1115 ((and (eq major-mode 'internal-ange-ftp-mode)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1116 (string-match "^\\*ftp \\(.*\\)@\\(.*\\)\\*$"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1117 (buffer-name)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1118 (concat "/" (substring (buffer-name) 5 -1) ":"))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1119 ;; This is too often a bad idea:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1120 ;;((and (eq major-mode 'w3-mode)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1121 ;; (stringp url-current-server))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1122 ;; (host-to-ange-path url-current-server))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1123 )))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1124 (and remote-dir
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1125 (or
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1126 (and (string-match "\\`\\(/?~?ftp\\)/" name)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1127 (ffap-file-exists-string
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1128 (ffap-replace-path-component
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1129 remote-dir (substring name (match-end 1)))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1130 (ffap-file-exists-string
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1131 (ffap-replace-path-component remote-dir name))))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1132 )
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1133 (store-match-data data))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1134
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1135
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1136 ;;; ffap-read-file-or-url:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1137 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1138 ;; Want to read filenames with completion as in read-file-name, but
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1139 ;; also allow URL's which read-file-name-internal would truncate at
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1140 ;; the "//" string. Solution here is to replace read-file-name-internal
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1141 ;; with another function that does not attempt to complete url's.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1142
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1143 ;; We implement a pretty clean completion semantics to work with
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1144 ;; packages like complete.el and exit-minibuffer.el. Even for
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1145 ;; complete.el (v19.22), we still need to make a small patch (it has a
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1146 ;; hardwired list of `minibuffer-completion-table' values which it
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1147 ;; considers to deal with filenames, this ought to be a variable).
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1148
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1149 (defun ffap-read-file-or-url (prompt guess)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1150 "Read a file or url from minibuffer, with PROMPT and initial GUESS."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1151 (or guess (setq guess default-directory))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1152 (let ((filep (not (ffap-url-p guess))) dir)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1153 ;; Tricky: guess may have or be a local directory, like "w3/w3.elc"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1154 ;; or "w3/" or "../el/ffap.el" or "../../../"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1155 (if filep
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1156 (progn
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1157 (or (ffap-file-remote-p guess)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1158 (setq guess (abbreviate-file-name (expand-file-name guess))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1159 (setq dir (file-name-directory guess))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1160 (apply
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1161 'completing-read
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1162 prompt
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1163 'ffap-read-file-or-url-internal
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1164 dir
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1165 nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1166 (if (and dir) (cons guess (length dir)) guess)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1167 (list 'file-name-history)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1168 )))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1169
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1170 (defvar url-global-history-completion-list nil) ; variable in w3/url.el
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1171
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1172 (defun ffap-read-url-internal (string dir action)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1173 ;; Complete URL's from history, always treat given url as acceptable.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1174 (let ((hist url-global-history-completion-list))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1175 (cond
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1176 ((not action)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1177 (or (try-completion string hist) string))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1178 ((eq action t)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1179 (or (all-completions string hist) (list string)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1180 ;; lambda?
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1181 (t string))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1182
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1183 (defun ffap-read-file-or-url-internal (string dir action)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1184 (if (ffap-url-p string)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1185 (ffap-read-url-internal string dir action)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1186 (read-file-name-internal string dir action)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1187
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1188 ;; Unfortunately, for complete.el to work correctly, we need to vary
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1189 ;; the value it sees of minibuffer-completion-table, depending on the
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1190 ;; current minibuffer contents! It would be nice if it were written a
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1191 ;; little more easily. I consider this a bug in complete.el, since
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1192 ;; the builtin emacs functions do not have this problem.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1193 (and
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1194 (featurep 'complete)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1195 (require 'advice)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1196 (defadvice PC-do-completion (around ffap-fix act)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1197 "Work with ffap.el."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1198 (let ((minibuffer-completion-table minibuffer-completion-table)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1199 ;; (minibuffer-completion-predicate minibuffer-completion-predicate)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1200 )
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1201 (and (eq minibuffer-completion-table 'ffap-read-file-or-url-internal)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1202 (setq minibuffer-completion-table
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1203 (if (ffap-url-p (buffer-string))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1204 ;; List would work better with icomplete ...
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1205 'ffap-read-url-internal
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1206 'read-file-name-internal)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1207 ad-do-it)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1208
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1209
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1210 ;;; Highlighting:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1211 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1212 ;; Based on overlay highlighting in Emacs 19.28 isearch.el.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1213
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1214 (defvar ffap-highlight (and window-system t)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1215 "If non-nil, ffap highlights the current buffer substring.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1216
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1217 (defvar ffap-overlay nil "Overlay used by ffap-highlight.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1218
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1219 (defun ffap-highlight (&optional remove)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1220 "If `ffap-highlight' is set, highlight the guess in the buffer.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1221 That is, the last buffer substring found by ffap-string-at-point.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1222 Optional argument REMOVE means to remove any such highlighting.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1223 Uses the face `ffap' if it is defined, else `highlight'."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1224 (cond
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1225 (remove (and ffap-overlay (delete-overlay ffap-overlay)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1226 ((not ffap-highlight) nil)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1227 (ffap-overlay
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1228 (move-overlay ffap-overlay
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1229 (car ffap-string-at-point-region)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1230 (nth 1 ffap-string-at-point-region)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1231 (current-buffer)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1232 (t
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1233 (setq ffap-overlay (apply 'make-overlay ffap-string-at-point-region))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1234 (overlay-put ffap-overlay 'face
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1235 (if (internal-find-face 'ffap nil)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1236 'ffap 'highlight)))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1237
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1238 ;;; The big enchilada:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1239
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1240 (defun ffap-guesser nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1241 "Return file or URL or nil, guessed from text around point."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1242 (or (and ffap-url-regexp
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1243 (ffap-fixup-url (or (ffap-url-at-point)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1244 (ffap-gopher-at-point))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1245 (ffap-file-at-point) ; may yield url!
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1246 (ffap-fixup-machine (ffap-machine-at-point))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1247
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1248 (defun ffap-prompter (&optional guess)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1249 ;; Does guess and prompt step for find-file-at-point.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1250 ;; Extra complication just to do the temporary highlighting.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1251 (unwind-protect
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1252 (ffap-read-file-or-url
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1253 (if ffap-url-regexp "Find file or URL: " "Find file: ")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1254 (prog1
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1255 (setq guess (or guess (ffap-guesser)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1256 (and guess (ffap-highlight))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1257 (ffap-highlight t)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1258
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1259 ;;;###autoload
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1260 (defun find-file-at-point (&optional filename)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1261 "Find FILENAME (or url), guessing default from text around point.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1262 If `ffap-dired-wildcards' is set, wildcard patterns are passed to dired.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1263 See also the functions ffap-file-at-point, ffap-url-at-point.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1264 With a prefix, this command behaves *exactly* like `ffap-file-finder'.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1265 If `ffap-require-prefix' is set, the prefix meaning is reversed.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1266
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1267 See ftp://ftp.mathcs.emory.edu/pub/mic/emacs/ for most recent version."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1268 (interactive)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1269 (if (and (interactive-p)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1270 (if ffap-require-prefix (not current-prefix-arg)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1271 current-prefix-arg))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1272 ;; Do exactly the ffap-file-finder command, even the prompting:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1273 (call-interactively ffap-file-finder)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1274 (or filename (setq filename (ffap-prompter)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1275 (cond
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1276 ((ffap-url-p filename)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1277 (funcall ffap-url-fetcher filename))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1278 ;; This junk more properly belongs in a modified ffap-file-finder:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1279 ((and ffap-dired-wildcards (string-match ffap-dired-wildcards filename))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1280 (dired filename))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1281 ((or (not ffap-newfile-prompt)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1282 (file-exists-p filename)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1283 (y-or-n-p "File does not exist, create buffer? "))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1284 (funcall ffap-file-finder
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1285 ;; expand-file-name fixes "~/~/.emacs" bug sent by CHUCKR.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1286 (expand-file-name filename)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1287 ;; User does not want to find a non-existent file:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1288 ((signal 'file-error (list "Opening file buffer"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1289 "no such file or directory"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1290 filename))))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1291
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1292 ;; M-x shortcut:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1293 (fset 'ffap 'find-file-at-point)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1294
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1295
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1296 ;;; Menu support:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1297 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1298 ;; Bind ffap-menu to a key if you want, since it also works in tty mode.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1299 ;; Or just use it through the ffap-at-mouse binding (next section).
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1300
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1301 (defvar ffap-menu-regexp nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1302 "*If non-nil, overrides `ffap-next-regexp' during ffap-menu.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1303 Make this more restrictive for faster menu building.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1304 For example, try \":/\" for url (and some ftp) references.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1305
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1306 (defvar ffap-menu-alist nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1307 "Buffer local menu of files and urls cached by ffap-menu.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1308 (make-variable-buffer-local 'ffap-menu-alist)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1309
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1310 ;;;###autoload
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1311 (defun ffap-menu (&optional rescan)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1312 "Puts up a menu of files and urls mentioned in the buffer.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1313 Sets mark, jumps to choice, and tries to fetch it.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1314 Menu is cached in `ffap-menu-alist', but will always be rebuilt
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1315 with the optional RESCAN argument (a prefix interactively).
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1316 Searches buffer with `ffap-menu-regexp' (see `ffap-next-regexp')."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1317 (interactive "P")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1318 ;; (require 'imenu) -- no longer used, but roughly emulated
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1319 (if (or (not ffap-menu-alist) rescan
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1320 ;; or if the first entry is wrong:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1321 (and ffap-menu-alist
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1322 (let ((first (car ffap-menu-alist)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1323 (save-excursion
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1324 (goto-char (cdr first))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1325 (not (equal (car first) (ffap-guesser)))))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1326 (ffap-menu-rescan))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1327 ;; Tail recursive:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1328 (ffap-menu-ask
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1329 (if ffap-url-regexp "Find file or URL" "Find file")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1330 (cons (cons "*Rescan Buffer*" -1) ffap-menu-alist)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1331 'ffap-menu-cont))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1332
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1333 (defun ffap-menu-cont (choice) ; continuation of ffap-menu
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1334 (if (< (cdr choice) 0)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1335 (ffap-menu t) ; *Rescan*
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1336 (push-mark)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1337 (goto-char (cdr choice))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1338 ;; Momentary highlight:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1339 (unwind-protect
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1340 (progn
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1341 (and ffap-highlight (ffap-guesser) (ffap-highlight))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1342 (sit-for 0) ; display
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1343 (find-file-at-point (car choice)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1344 (ffap-highlight t))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1345
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1346 (defun ffap-menu-ask (title alist cont)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1347 "Prompt from a menu of choices, and then apply some action.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1348 Arguments are TITLE, ALIST, and CONT (a continuation).
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1349 This uses either a menu or the minibuffer depending on invocation.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1350 The TITLE string is used as either the prompt or menu title.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1351 Each (string . data) entry in ALIST defines a choice (data is ignored).
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1352 Once the user makes a choice, function CONT is applied to the entry.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1353 Always returns nil."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1354 ;; Bug: minibuffer prompting assumes the strings are unique.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1355 ;; Todo: break up long menus into multiple panes (like imenu).
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1356 (let ((choice
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1357 (if (and (fboundp 'x-popup-menu) ; 19 or XEmacs 19.13
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1358 (boundp 'last-nonmenu-event) ; not in XEmacs 19.13
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1359 (listp last-nonmenu-event))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1360 (x-popup-menu
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1361 t
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1362 (list ""
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1363 (cons title
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1364 (mapcar
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1365 (function (lambda (i) (cons (car i) i)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1366 alist))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1367 ;; Automatically popup completion help, one way or another:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1368 (let ((minibuffer-setup-hook 'minibuffer-completion-help)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1369 (unread-command-char -1))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1370 ;; BUG: this code assumes that "" is not a valid choice
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1371 (completing-read
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1372 (format "%s (default %s): " title (car (car alist)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1373 alist nil t
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1374 ;; Let first be default:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1375 ;; (if ffap-v18 (car (car alist))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1376 ;; (cons (car (car alist)) 0))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1377 ;; No, then you do not get all completions!
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1378 nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1379 )))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1380 ;; Defaulting: convert "" to (car (car alist))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1381 (and (equal choice "") (setq choice (car (car alist))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1382 (and (stringp choice) (setq choice (assoc choice alist)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1383 (if choice (funcall cont choice) (message "No choice made!")))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1384 nil) ; return nothing
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1385
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1386 (defun ffap-menu-rescan nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1387 (interactive)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1388 (let ((ffap-next-regexp (or ffap-menu-regexp ffap-next-regexp))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1389 (range (- (point-max) (point-min))) item)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1390 (setq ffap-menu-alist nil)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1391 (save-excursion
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1392 (goto-char (point-min))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1393 (while (setq item (ffap-next-guess))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1394 (setq ffap-menu-alist (cons (cons item (point)) ffap-menu-alist))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1395 (message "Scanning...%2d%% <%s>"
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1396 (/ (* 100 (- (point) (point-min))) range) item))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1397 (message "Scanning...done")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1398 ;; Remove duplicates.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1399 (setq ffap-menu-alist ; sort by item
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1400 (sort ffap-menu-alist
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1401 (function
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1402 (lambda (a b) (string-lessp (car a) (car b))))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1403 (let ((ptr ffap-menu-alist))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1404 (while (cdr ptr)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1405 (if (equal (car (car ptr)) (car (car (cdr ptr))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1406 (setcdr ptr (cdr (cdr ptr)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1407 (setq ptr (cdr ptr)))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1408 (setq ffap-menu-alist ; sort by position
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1409 (sort ffap-menu-alist
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1410 (function
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1411 (lambda (a b) (< (cdr a) (cdr b)))))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1412
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1413
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1414 ;;; Mouse Support:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1415 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1416 ;; I suggest a mouse binding, something like:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1417 ;; (global-set-key [S-mouse-1] 'ffap-at-mouse)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1418
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1419 (defvar ffap-at-mouse-fallback 'ffap-menu
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1420 "Invoked by ffap-at-mouse if no file or url found at point.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1421 A command symbol, or nil for nothing.")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1422 (put 'ffap-at-mouse-fallback 'risky-local-variable t)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1423
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1424 (defun ffap-at-mouse (e)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1425 "Find file or URL guessed from text around mouse point.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1426 If none is found, call `ffap-at-mouse-fallback'."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1427 (interactive "e")
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1428 (let ((guess
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1429 ;; Maybe less surprising without the save-excursion?
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1430 (save-excursion
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1431 (mouse-set-point e)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1432 ;; Would like to do nothing unless click was *on* text. How?
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1433 ;; (cdr (posn-col-row (event-start e))) is always same as
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1434 ;; current column. For posn-x-y, need pixel-width!
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1435 (ffap-guesser))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1436 (cond
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1437 (guess
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1438 (ffap-highlight)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1439 (unwind-protect
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1440 (progn
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1441 (sit-for 0) ; display
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1442 (message "Guessing `%s'" guess)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1443 (find-file-at-point guess))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1444 (ffap-highlight t)))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1445 ((and (interactive-p)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1446 ffap-at-mouse-fallback)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1447 (call-interactively ffap-at-mouse-fallback))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1448 ((message "No file or URL found at mouse click.")))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1449
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1450
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1451 ;;; ffap-other-* commands
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1452 ;; Suggested by KPC. Possible bindings for C-x 4 C-f, C-x 5 C-f.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1453
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1454 (defun ffap-other-window nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1455 "Like ffap, but put buffer in another window."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1456 (interactive)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1457 (switch-to-buffer-other-window
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1458 (save-window-excursion (call-interactively 'ffap) (current-buffer))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1459
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1460 (defun ffap-other-frame nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1461 "Like ffap, but put buffer in another frame."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1462 (interactive)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1463 (switch-to-buffer-other-frame
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1464 (save-window-excursion (call-interactively 'ffap) (current-buffer))))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1465
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1466
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1467 ;;; ffap-bug:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1468 (defun ffap-bug nil
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1469 ;; Tested with Emacs 19.28 reporter.el
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1470 "Submit a bug report for ffap."
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1471 (interactive)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1472 (require 'reporter)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1473 (let ((reporter-prompt-for-summary-p t))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1474 (reporter-submit-bug-report
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1475 "mic@mathcs.emory.edu" "ffap "
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1476 (mapcar 'intern (all-completions "ffap-" obarray 'boundp))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1477 )))
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1478 (fset 'ffap-submit-bug 'ffap-bug) ; another likely name
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1479
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1480
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1481 ;;; Todo, End.
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1482 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1483 ;; * w3 may eventually make URL's part of the filesystem!
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1484 ;; this package (prompt & completion) could become much simpler
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1485 ;; * improve minibuffer-completion-help display of long completions
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1486 ;; * notice "machine.dom blah blah blah path/file" (how?)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1487 ;; * check X selections (x-get-selection PRIMARY/SECONDARY LENGTH/TEXT)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1488 ;; * let "/path/file#key" jump to key (anchor or regexp) in /path/file
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1489 ;; * notice node in "(dired)Virtual Dired" (how to handle space?)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1490 ;; * try find-tag on symbol if TAGS is loaded (need above)
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1491 ;;
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1492 ;; For information on URL/URI syntax, try:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1493 ;; <http://ds.internic.net/rfc/rfc1630.txt>
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1494 ;; <http://www.w3.org/hypertext/WWW/Protocols/Overview.html>
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1495 ;; <http://info.cern.ch/hypertext/WWW/Addressing/Addressing.html>
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1496
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1497 ;; Local Variables?
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1498 ;; foo: bar
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1499 ;; End:
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1500
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1501
b4d9bb7adf24 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1502 ;;; ffap.el ends here