annotate lisp/ffap.el @ 18156:f7296dc03177

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