annotate lisp/ffap.el @ 13728:4b7903cfa7ee

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