;;; ffap.el --- find file (or url) at point
-;; Copyright (C) 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2004,
-;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1995-1997, 2000-2012 Free Software Foundation, Inc.
;; Author: Michelangelo Grigni <mic@mathcs.emory.edu>
;; Maintainer: FSF
\f
;;; Code:
-(provide 'ffap)
-
-;; Please do not delete this variable, it is checked in bug reports.
-(defconst ffap-version "1.9-fsf <97/06/25 13:21:41 mic>"
- "The version of ffap: \"Major.Minor-Build <Timestamp>\"")
-
+(define-obsolete-variable-alias 'ffap-version 'emacs-version "23.2")
(defgroup ffap nil
"Find file or URL at point."
- :link '(url-link :tag "URL" "ftp://ftp.mathcs.emory.edu/pub/mic/emacs/")
+ ;; Dead 2009/07/05.
+;; :link '(url-link :tag "URL" "ftp://ftp.mathcs.emory.edu/pub/mic/emacs/")
:group 'matching
:group 'convenience)
\f
;;; User Variables:
-(defun ffap-soft-value (name &optional default)
- "Return value of symbol with NAME, if it is interned.
-Otherwise return nil (or the optional DEFAULT value)."
- ;; Bug: (ffap-soft-value "nil" 5) --> 5
- (let ((sym (intern-soft name)))
- (if (and sym (boundp sym)) (symbol-value sym) default)))
+(defun ffap-symbol-value (sym &optional default)
+ "Return value of symbol SYM, if bound, or DEFAULT otherwise."
+ (if (boundp sym) (symbol-value sym) default))
(defcustom ffap-shell-prompt-regexp
;; This used to test for some shell prompts that don't have a space
;; after them. The common root shell prompt (#) is not listed since it
;; also doubles up as a valid URL character.
"[$%><]*"
- "Paths matching this regexp are stripped off the shell prompt
+ "Paths matching this regexp are stripped off the shell prompt.
If nil, ffap doesn't do shell prompt stripping."
:type '(choice (const :tag "Disable" nil)
(const :tag "Standard" "[$%><]*")
"\\(ftp\\|https?\\|telnet\\|gopher\\|www\\|wais\\)://" ; needs host
"\\)." ; require one more character
)
- "Regexp matching URL's. nil to disable URL features in ffap.")
+ "Regexp matching URLs. Use nil to disable URL features in ffap.")
(defcustom ffap-foo-at-bar-prefix "mailto"
"Presumed URL prefix type of strings like \"<foo.9z@bar>\".
;; See the ftp site for a more general version. The following
;; functions are necessary "leftovers" from the more general version.
-(defun ffap-mouse-event nil ; current mouse event, or nil
+(defun ffap-mouse-event () ; current mouse event, or nil
(and (listp last-nonmenu-event) last-nonmenu-event))
(defun ffap-event-buffer (event)
(window-buffer (car (event-start event))))
"Like `ffap-next', but search with `ffap-url-regexp'."
(interactive)
(let ((ffap-next-regexp ffap-url-regexp))
- (if (interactive-p)
+ (if (called-interactively-p 'interactive)
(call-interactively 'ffap-next)
(ffap-next back wrap))))
(defun ffap-what-domain (domain)
;; Like what-domain in mail-extr.el, returns string or nil.
(require 'mail-extr)
- (let ((ob (or (ffap-soft-value "mail-extr-all-top-level-domains")
- (ffap-soft-value "all-top-level-domains")))) ; XEmacs
+ (let ((ob (or (ffap-symbol-value 'mail-extr-all-top-level-domains)
+ (ffap-symbol-value 'all-top-level-domains)))) ; XEmacs
(and ob (get (intern-soft (downcase domain) ob) 'domain-name))))
(defun ffap-machine-p (host &optional service quiet strategy)
;; (ffap-file-remote-p "/ffap.el:80")
(or (and ffap-ftp-regexp
(string-match ffap-ftp-regexp filename)
- ;; Convert "/host.com://dir" to "/host:/dir", to handle a dieing
+ ;; Convert "/host.com://dir" to "/host:/dir", to handle a dying
;; practice of advertising ftp files as "host.dom://filename".
(if (string-match "//" filename)
;; (replace-match "/" nil nil filename)
(string-match ffap-rfs-regexp filename)
filename)))
-(defun ffap-machine-at-point nil
+(defun ffap-machine-at-point ()
"Return machine name at point if it exists, or nil."
(let ((mach (ffap-string-at-point 'machine)))
(and (ffap-machine-p mach) mach)))
""
(let ((user ffap-ftp-default-user))
;; Avoid including the user if it is same as default:
- (if (or (equal user (ffap-soft-value "ange-ftp-default-user"))
- (equal user (ffap-soft-value "efs-default-user")))
+ (if (or (equal user (ffap-symbol-value 'ange-ftp-default-user))
+ (equal user (ffap-symbol-value 'efs-default-user)))
(setq user nil))
(concat "/" user (and user "@") host ":"))))
ret)))
(defsubst ffap-url-p (string)
- "If STRING looks like an url, return it (maybe improved), else nil."
+ "If STRING looks like an URL, return it (maybe improved), else nil."
(let ((case-fold-search t))
(and ffap-url-regexp (string-match ffap-url-regexp string)
;; I lied, no improvement:
(nreverse ret)))
(defun ffap-all-subdirs (dir &optional depth)
- "Return list all subdirectories under DIR, starting with itself.
+ "Return list of all subdirectories under DIR, starting with itself.
Directories beginning with \".\" are ignored, and directory symlinks
are listed but never searched (to avoid loops).
Optional DEPTH limits search depth."
(list dir))))
path)))
-(defun ffap-locate-file (file &optional nosuffix path dir-ok)
+(defun ffap-locate-file (file nosuffix path)
;; The current version of locate-library could almost replace this,
;; except it does not let us override the suffix list. The
;; compression-suffixes search moved to ffap-file-exists-string.
- "A generic path-searching function, mimics `load' by default.
-Returns path to file that \(load FILE\) would load, or nil.
+ "A generic path-searching function.
+Returns the name of file in PATH, or nil.
Optional NOSUFFIX, if nil or t, is like the fourth argument
-for load: whether to try the suffixes (\".elc\" \".el\" \"\").
+for `load': whether to try the suffixes (\".elc\" \".el\" \"\").
If a nonempty list, it is a list of suffixes to try instead.
-Optional PATH is a list of directories instead of `load-path'.
-Optional DIR-OK means that returning a directory is allowed,
-DIR-OK is already implicit if FILE looks like a directory.
+PATH is a list of directories.
-This uses ffap-file-exists-string, which may try adding suffixes from
+This uses `ffap-file-exists-string', which may try adding suffixes from
`ffap-compression-suffixes'."
- (or path (setq path load-path))
- (or dir-ok (setq dir-ok (equal "" (file-name-nondirectory file))))
(if (file-name-absolute-p file)
(setq path (list (file-name-directory file))
file (file-name-nondirectory file)))
- (let ((suffixes-to-try
+ (let ((dir-ok (equal "" (file-name-nondirectory file)))
+ (suffixes-to-try
(cond
((consp nosuffix) nosuffix)
(nosuffix '(""))
("\\.bib\\'" . ffap-bib) ; search ffap-bib-path
("\\`\\." . ffap-home) ; .emacs, .bashrc, .profile
("\\`~/" . ffap-lcd) ; |~/misc/ffap.el.Z|
- ;; This uses to have a blank, but ffap-string-at-point doesn't
+ ;; This used to have a blank, but ffap-string-at-point doesn't
;; handle blanks.
;; http://lists.gnu.org/archive/html/emacs-devel/2008-01/msg01058.html
- ("^[Rr][Ff][Cc][-#]?\\([0-9]+\\)" ; no $
+ ("\\`[Rr][Ff][Cc][-#]?\\([0-9]+\\)" ; no $
. ffap-rfc) ; "100% RFC2100 compliant"
(dired-mode . ffap-dired) ; maybe in a subdirectory
)
"Alist of \(KEY . FUNCTION\) pairs parsed by `ffap-file-at-point'.
-If string NAME at point (maybe \"\") is not a file or url, these pairs
+If string NAME at point (maybe \"\") is not a file or URL, these pairs
specify actions to try creating such a string. A pair matches if either
KEY is a symbol, and it equals `major-mode', or
- KEY is a string, it should matches NAME as a regexp.
+ KEY is a string, it should match NAME as a regexp.
On a match, \(FUNCTION NAME\) is called and should return a file, an
-url, or nil. If nil, search the alist for further matches.")
+URL, or nil. If nil, search the alist for further matches.")
(put 'ffap-alist 'risky-local-variable t)
(defun ffap-info (name)
(ffap-locate-file
name '("" ".info")
- (or (ffap-soft-value "Info-directory-list")
- (ffap-soft-value "Info-default-directory-list")
+ (or (ffap-symbol-value 'Info-directory-list)
+ (ffap-symbol-value 'Info-default-directory-list)
)))
(defun ffap-info-2 (name) (ffap-info (substring name 5)))
;; This ignores the node! "(emacs)Top" same as "(emacs)Intro"
(and (equal (ffap-string-around) "()") (ffap-info name)))
-(defun ffap-el (name) (ffap-locate-file name t))
+(defun ffap-el (name) (ffap-locate-file name t load-path))
(defun ffap-el-mode (name)
;; If name == "foo.el" we will skip it, since ffap-el already
;; searched for it once. (This assumes the default ffap-alist.)
(and (not (string-match "\\.el\\'" name))
- (ffap-locate-file name '(".el"))))
+ (ffap-locate-file name '(".el") load-path)))
(defvar ffap-c-path
;; Need smarter defaults here! Suggestions welcome.
(defvar ffap-tex-path
t ; delayed initialization
- "Path where `ffap-tex-mode' looks for tex files.
+ "Path where `ffap-tex-mode' looks for TeX files.
If t, `ffap-tex-init' will initialize this when needed.")
-(defun ffap-tex-init nil
+(defun ffap-tex-init ()
;; Compute ffap-tex-path if it is now t.
(and (eq t ffap-tex-path)
;; this may be slow, so say something
(append
(ffap-list-env "TEXINPUTS")
;; (ffap-list-env "BIBINPUTS")
- (ffap-soft-value
- "TeX-macro-global" ; AUCTeX
+ (ffap-symbol-value
+ 'TeX-macro-global ; AUCTeX
'("/usr/local/lib/tex/macros"
"/usr/local/lib/tex/inputs")))))))))
;; Maybe a "Lisp Code Directory" reference:
(defun ffap-lcd (name)
+ ;; FIXME: Is this still in use?
(and
(or
;; lisp-dir-apropos output buffer:
(concat
;; lispdir.el may not be loaded yet:
(ffap-host-to-filename
- (ffap-soft-value "elisp-archive-host"
- "archive.cis.ohio-state.edu"))
+ (ffap-symbol-value 'elisp-archive-host
+ "archive.cis.ohio-state.edu"))
(file-name-as-directory
- (ffap-soft-value "elisp-archive-directory"
- "/pub/gnu/emacs/elisp-archive/"))
+ (ffap-symbol-value 'elisp-archive-directory
+ "/pub/gnu/emacs/elisp-archive/"))
(substring name 2))))
+(defcustom ffap-rfc-path
+ (concat (ffap-host-to-filename "ftp.rfc-editor.org") "/in-notes/rfc%s.txt")
+ "A `format' string making a filename for RFC documents.
+This can be an ange-ftp or tramp remote filename to download, or
+a local filename if you have full set of RFCs locally. See also
+`ffap-rfc-directories'."
+ :type 'string
+ :version "23.1"
+ :group 'ffap)
+
(defcustom ffap-rfc-directories nil
"A list of directories to look for RFC files.
If a given RFC isn't in these then `ffap-rfc-path' is offered."
:version "23.1"
:group 'ffap)
-(defvar ffap-rfc-path
- (concat (ffap-host-to-filename "ftp.rfc-editor.org") "/in-notes/rfc%s.txt"))
-
(defun ffap-rfc (name)
(let ((num (match-string 1 name)))
(or (ffap-locate-file (format "rfc%s.txt" num) t ffap-rfc-directories)
(set-text-properties 0 (length str) nil str)
(setq ffap-string-at-point str)))
-(defun ffap-string-around nil
+(defun ffap-string-around ()
;; Sometimes useful to decide how to treat a string.
"Return string of two chars around last `ffap-string-at-point'.
Assumes the buffer has not changed."
;; External.
(declare-function w3-view-this-url "ext:w3" (&optional no-show))
-(defun ffap-url-at-point nil
- "Return url from around point if it exists, or nil."
+(defun ffap-url-at-point ()
+ "Return URL from around point if it exists, or nil."
;; Could use w3's url-get-url-at-point instead. Both handle "URL:",
;; ignore non-relative links, trim punctuation. The other will
;; actually look back if point is in whitespace, but I would rather
(defvar ffap-gopher-regexp
"^.*\\<\\(Type\\|Name\\|Path\\|Host\\|Port\\) *= *\\(.*\\) *$"
- "Regexp Matching a line in a gopher bookmark (maybe indented).
+ "Regexp matching a line in a gopher bookmark (maybe indented).
The two subexpressions are the KEY and VALUE.")
-(defun ffap-gopher-at-point nil
- "If point is inside a gopher bookmark block, return its url."
+(defun ffap-gopher-at-point ()
+ "If point is inside a gopher bookmark block, return its URL."
;; `gopher-parse-bookmark' from gopher.el is not so robust
(save-excursion
(beginning-of-line)
(while (and (looking-at ffap-gopher-regexp) (not (bobp)))
(forward-line -1))
(or (looking-at ffap-gopher-regexp) (forward-line 1))
- (let ((type "1") name path host (port "70"))
+ (let ((type "1") path host (port "70"))
(while (looking-at ffap-gopher-regexp)
(let ((var (intern
(downcase
"Strings matching this are coerced to ftp file names by ffap.
That is, ffap just prepends \"/\". Set to nil to disable.")
-(defun ffap-file-at-point nil
+(defun ffap-file-at-point ()
"Return filename from around point if it exists, or nil.
Existence test is skipped for names that look remote.
If the filename is not obvious, it also tries `ffap-alist',
-which may actually result in an url rather than a filename."
+which may actually result in an URL rather than a filename."
;; Note: this function does not need to look for url's, just
;; filenames. On the other hand, it is responsible for converting
;; a pseudo-url "site.com://dir" to an ftp file name
((and abs (ffap-file-remote-p name)))
;; Ok, not remote, try the existence test even if it is absolute:
((and abs (ffap-file-exists-string name)))
+ ;; Try stripping off line numbers.
+ ((and abs (string-match ":[0-9]" name)
+ (ffap-file-exists-string (substring name 0 (match-beginning 0)))))
;; If it contains a colon, get rid of it (and return if exists)
((and (string-match path-separator name)
(setq name (ffap-string-at-point 'nocolon))
;; contents before attempting to complete filenames.
(defun ffap-read-file-or-url (prompt guess)
- "Read file or url from minibuffer, with PROMPT and initial GUESS."
+ "Read file or URL from minibuffer, with PROMPT and initial GUESS."
(or guess (setq guess default-directory))
(let (dir)
;; Tricky: guess may have or be a local directory, like "w3/w3.elc"
guess))
(defun ffap-read-url-internal (string pred action)
- "Complete url's from history, treating given string as valid."
- (let ((hist (ffap-soft-value "url-global-history-hash-table")))
+ "Complete URLs from history, treating given string as valid."
+ (let ((hist (ffap-symbol-value 'url-global-history-hash-table)))
(cond
((not action)
(or (try-completion string hist pred) string))
;; We must inform complete about whether our completion function
;; will do filename style completion.
-(defun ffap-complete-as-file-p nil
+(defun ffap-complete-as-file-p ()
;; Will `minibuffer-completion-table' complete the minibuffer
;; contents as a filename? Assumes the minibuffer is current.
;; Note: t and non-nil mean somewhat different reasons.
\f
;;; Main Entrance (`find-file-at-point' == `ffap'):
-(defun ffap-guesser nil
+(defun ffap-guesser ()
"Return file or URL or nil, guessed from text around point."
(or (and ffap-url-regexp
(ffap-fixup-url (or (ffap-url-at-point)
See also the variables `ffap-dired-wildcards', `ffap-newfile-prompt',
and the functions `ffap-file-at-point' and `ffap-url-at-point'."
(interactive)
- (if (and (interactive-p)
+ (if (and (called-interactively-p 'interactive)
(if ffap-require-prefix (not current-prefix-arg)
current-prefix-arg))
;; Do exactly the ffap-file-finder command, even the prompting:
;;;###autoload
(defun ffap-menu (&optional rescan)
- "Put up a menu of files and urls mentioned in this buffer.
+ "Put up a menu of files and URLs mentioned in this buffer.
Then set mark, jump to choice, and try to fetch it. The menu is
cached in `ffap-menu-alist', and rebuilt by `ffap-menu-rescan'.
The optional RESCAN argument \(a prefix, interactively\) forces
(message "No choice made!") ; possible with menus
nil)))
-(defun ffap-menu-rescan nil
+(defun ffap-menu-rescan ()
"Search buffer for `ffap-menu-regexp' to build `ffap-menu-alist'.
Applies `ffap-menu-text-plist' text properties at all matches."
(interactive)
;;;###autoload
(defun ffap-at-mouse (e)
- "Find file or url guessed from text around mouse click.
+ "Find file or URL guessed from text around mouse click.
Interactively, calls `ffap-at-mouse-fallback' if no guess is found.
Return value:
* if a guess string is found, return it (after finding it)
(find-file-at-point guess)
guess) ; success: return non-nil
(ffap-highlight t)))
- ((interactive-p)
+ ((called-interactively-p 'interactive)
(if ffap-at-mouse-fallback
(call-interactively ffap-at-mouse-fallback)
- (message "No file or url found at mouse click.")
+ (message "No file or URL found at mouse click.")
nil)) ; no fallback, return nil
;; failure: return nil
)))
;; at least two new user variables, and there is no w3-fetch-noselect.
;; So instead, we just fake it with a slow save-window-excursion.
-(defun ffap-other-window nil
+(defun ffap-other-window ()
"Like `ffap', but put buffer in another window.
Only intended for interactive use."
(interactive)
(current-buffer)))
value))
-(defun ffap-other-frame nil
+(defun ffap-other-frame ()
"Like `ffap', but put buffer in another frame.
Only intended for interactive use."
(interactive)
(let ((ffap-file-finder 'find-alternate-file))
(call-interactively 'ffap)))
+(defun ffap-alternate-file-other-window ()
+ "Like `ffap' and `find-alternate-file-other-window'.
+Only intended for interactive use."
+ (interactive)
+ (let ((ffap-file-finder 'find-alternate-file-other-window))
+ (call-interactively 'ffap)))
+
+(defun ffap-literally ()
+ "Like `ffap' and `find-file-literally'.
+Only intended for interactive use."
+ (interactive)
+ (let ((ffap-file-finder 'find-file-literally))
+ (call-interactively 'ffap)))
+
+(defalias 'find-file-literally-at-point 'ffap-literally)
+
\f
;;; Bug Reporter:
;; If you do not like these bindings, write versions with whatever
;; bindings you would prefer.
-(defun ffap-ro-mode-hook nil
+(defun ffap-ro-mode-hook ()
"Bind `ffap-next' and `ffap-menu' to M-l and M-m, resp."
(local-set-key "\M-l" 'ffap-next)
(local-set-key "\M-m" 'ffap-menu)
)
-(defun ffap-gnus-hook nil
+(defun ffap-gnus-hook ()
"Bind `ffap-gnus-next' and `ffap-gnus-menu' to M-l and M-m, resp."
(set (make-local-variable 'ffap-foo-at-bar-prefix) "news") ; message-id's
;; Note "l", "L", "m", "M" are taken:
(eval form)
(pop-to-buffer sb))))
-(defun ffap-gnus-next nil
+(defun ffap-gnus-next ()
"Run `ffap-next' in the gnus article buffer."
(interactive) (ffap-gnus-wrapper '(ffap-next nil t)))
-(defun ffap-gnus-menu nil
+(defun ffap-gnus-menu ()
"Run `ffap-menu' in the gnus article buffer."
(interactive) (ffap-gnus-wrapper '(ffap-menu)))
;;;###autoload
(defun dired-at-point (&optional filename)
- "Start Dired, defaulting to file at point. See `ffap'."
+ "Start Dired, defaulting to file at point. See `ffap'.
+If `dired-at-point-require-prefix' is set, the prefix meaning is reversed."
(interactive)
- (if (and (interactive-p)
+ (if (and (called-interactively-p 'interactive)
(if dired-at-point-require-prefix
(not current-prefix-arg)
current-prefix-arg))
(let ((ffap-directory-finder 'list-directory))
(call-interactively 'dired-at-point)))
+\f
+;;; Hooks to put in `file-name-at-point-functions':
+
+;;;###autoload
+(progn (defun ffap-guess-file-name-at-point ()
+ "Try to get a file name at point.
+This hook is intended to be put in `file-name-at-point-functions'."
+ (when (fboundp 'ffap-guesser)
+ ;; Logic from `ffap-read-file-or-url' and `dired-at-point-prompter'.
+ (let ((guess (ffap-guesser)))
+ (setq guess
+ (if (or (not guess)
+ (and (fboundp 'ffap-url-p)
+ (ffap-url-p guess))
+ (and (fboundp 'ffap-file-remote-p)
+ (ffap-file-remote-p guess)))
+ guess
+ (abbreviate-file-name (expand-file-name guess))))
+ (when guess
+ (if (file-directory-p guess)
+ (file-name-as-directory guess)
+ guess))))))
+
\f
;;; Offer default global bindings (`ffap-bindings'):
Of course if you do not like these bindings, just roll your own!")
;;;###autoload
-(defun ffap-bindings nil
+(defun ffap-bindings ()
"Evaluate the forms in variable `ffap-bindings'."
(interactive)
(eval (cons 'progn ffap-bindings)))
\f
+(provide 'ffap)
-;; arch-tag: 9dd3e88a-5dec-4607-bd57-60ae9ede8ebc
;;; ffap.el ends here