;;; ffap.el --- find file (or url) at point
-;; Copyright (C) 1995, 1996, 1997, 2000, 2002, 2003, 2004,
-;; 2005, 2006 Free Software Foundation, Inc.
+;; Copyright (C) 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2004,
+;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
;; Author: Michelangelo Grigni <mic@mathcs.emory.edu>
-;; Maintainer: Rajesh Vaidheeswarran <rv@gnu.org>
+;; Maintainer: FSF
;; Created: 29 Mar 1993
;; Keywords: files, hypermedia, matching, mouse, convenience
;; X-URL: ftp://ftp.mathcs.emory.edu/pub/mic/emacs/
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;;
;; It pays to put a big fancy regexp here, since ffap-guesser is
;; much more time-consuming than regexp searching:
- "[/:.~a-zA-Z]/\\|@[a-zA-Z][-a-zA-Z0-9]*\\."
+ "[/:.~[:alpha:]]/\\|@[[:alpha:]][-[:alnum:]]*\\."
"*Regular expression governing movements of `ffap-next'."
:type 'regexp
:group 'ffap)
;; (ffap-machine-p "mathcs" 5678 nil 'ping)
;; (ffap-machine-p "foo.bonk" nil nil 'ping)
;; (ffap-machine-p "foo.bonk.com" nil nil 'ping)
- (if (or (string-match "[^-a-zA-Z0-9.]" host) ; Illegal chars (?)
+ (if (or (string-match "[^-[:alnum:].]" host) ; Invalid chars (?)
(not (string-match "[^0-9]" host))) ; 1: a number? 2: quick reject
nil
(let* ((domain
"In remote FULLNAME, replace path with NAME. May return nil."
;; Use ange-ftp or efs if loaded, but do not load them otherwise.
(let (found)
- (mapcar
+ (mapc
(function (lambda (sym) (and (fboundp sym) (setq found sym))))
'(
efs-replace-path-component
(ffap-ftp-regexp (ffap-host-to-filename mach))
))
-(defvar ffap-newsgroup-regexp "^[a-z]+\\.[-+a-z_0-9.]+$"
+(defvar ffap-newsgroup-regexp "^[[:lower:]]+\\.[-+[:lower:]_0-9.]+$"
"Strings not matching this fail `ffap-newsgroup-p'.")
(defvar ffap-newsgroup-heads ; entirely inadequate
'("alt" "comp" "gnu" "misc" "news" "sci" "soc" "talk")
(setq heads nil))
(error nil)))
(or ret (not heads)
- (let ((head (string-match "\\`\\([a-z]+\\)\\." string)))
+ (let ((head (string-match "\\`\\([[:lower:]]+\\)\\." string)))
(and head (setq head (substring string 0 (match-end 1)))
(member head heads)
(setq ret string))))
("" . ffap-completable) ; completion, slow on some systems
("\\.info\\'" . ffap-info) ; gzip.info
("\\`info/" . ffap-info-2) ; info/emacs
- ("\\`[-a-z]+\\'" . ffap-info-3) ; (emacs)Top [only in the parentheses]
+ ("\\`[-[:lower:]]+\\'" . ffap-info-3) ; (emacs)Top [only in the parentheses]
("\\.elc?\\'" . ffap-el) ; simple.el, simple.elc
(emacs-lisp-mode . ffap-el-mode) ; rmail, gnus, simple, custom
;; (lisp-interaction-mode . ffap-el-mode) ; maybe
("\\.bib\\'" . ffap-bib) ; search ffap-bib-path
("\\`\\." . ffap-home) ; .emacs, .bashrc, .profile
("\\`~/" . ffap-lcd) ; |~/misc/ffap.el.Z|
- ("^[Rr][Ff][Cc][- #]?\\([0-9]+\\)" ; no $
+ ;; This uses 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 $
. ffap-rfc) ; "100% RFC2100 compliant"
(dired-mode . ffap-dired) ; maybe in a subdirectory
)
"/pub/gnu/emacs/elisp-archive/"))
(substring name 2))))
+(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."
+ :type '(repeat directory)
+ :version "23.1"
+ :group 'ffap)
+
(defvar ffap-rfc-path
- (concat (ffap-host-to-filename "ds.internic.net") "/rfc/rfc%s.txt"))
+ (concat (ffap-host-to-filename "ftp.rfc-editor.org") "/in-notes/rfc%s.txt"))
(defun ffap-rfc (name)
- (format ffap-rfc-path
- (substring name (match-beginning 1) (match-end 1))))
+ (let ((num (match-string 1 name)))
+ (or (ffap-locate-file (format "rfc%s.txt" num) t ffap-rfc-directories)
+ (format ffap-rfc-path num))))
\f
;;; At-Point Functions:
;; Slightly controversial decisions:
;; * strip trailing "@" and ":"
;; * no commas (good for latex)
- (file "--:$+<>@-Z_a-z~*?" "<@" "@>;.,!:")
+ (file "--:\\\\$+<>@-Z_[:lower:]~*?" "<@" "@>;.,!:")
;; An url, or maybe a email/news message-id:
- (url "--:=&?$+@-Z_a-z~#,%;*" "^A-Za-z0-9" ":;.,!?")
+ (url "--:=&?$+@-Z_[:lower:]~#,%;*" "^[:alnum:]" ":;.,!?")
;; Find a string that does *not* contain a colon:
- (nocolon "--9$+<>@-Z_a-z~" "<@" "@>;.,!?")
+ (nocolon "--9$+<>@-Z_[:lower:]~" "<@" "@>;.,!?")
;; A machine:
- (machine "-a-zA-Z0-9." "" ".")
+ (machine "-[:alnum:]." "" ".")
;; Mathematica paths: allow backquotes
- (math-mode ",-:$+<>@-Z_a-z~`" "<" "@>;.,!?`:")
+ (math-mode ",-:$+<>@-Z_[:lower:]~`" "<" "@>;.,!?`:")
)
"Alist of \(MODE CHARS BEG END\), where MODE is a symbol,
possibly a major-mode name, or one of the symbol
;; Older: (apply 'copy-region-as-kill ffap-string-at-point-region)
(message "Copied to kill ring: %s" str))))
+;; 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."
;; Could use w3's url-get-url-at-point instead. Both handle "URL:",
(let ((name (ffap-string-at-point 'url)))
(cond
((string-match "^url:" name) (setq name (substring name 4)))
- ((and (string-match "\\`[^:</>@]+@[^:</>@]+[a-zA-Z0-9]\\'" name)
+ ((and (string-match "\\`[^:</>@]+@[^:</>@]+[[:alnum:]]\\'" name)
;; "foo@bar": could be "mailto" or "news" (a Message-ID).
;; Without "<>" it must be "mailto". Otherwise could be
;; either, so consult `ffap-foo-at-bar-prefix'.
"mailto")))
(and prefix (setq name (concat prefix ":" name))))))
((ffap-newsgroup-p name) (setq name (concat "news:" name)))
- ((and (string-match "\\`[a-z0-9]+\\'" name) ; <mic> <root> <nobody>
+ ((and (string-match "\\`[[:alnum:]]+\\'" name) ; <mic> <root> <nobody>
(equal (ffap-string-around) "<>")
;; (ffap-user-p name):
(not (string-match "~" (expand-file-name (concat "~" name))))
(error nil))
string))
(abs (file-name-absolute-p name))
- (default-directory default-directory))
+ (default-directory default-directory)
+ (oname name))
(unwind-protect
(cond
;; Immediate rejects (/ and // and /* are too common in C/C++):
(not abs) (string-match ffap-shell-prompt-regexp name)
(ffap-file-exists-string (substring name (match-end 0)))))
;; Accept remote names without actual checking (too slow):
- ((if abs
- (ffap-file-remote-p name)
- ;; Try adding a leading "/" (common omission in ftp file names):
- (and
- ffap-ftp-sans-slash-regexp
- (string-match ffap-ftp-sans-slash-regexp name)
- (ffap-file-remote-p (concat "/" 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)))
;; If it contains a colon, get rid of it (and return if exists)
(ffap-file-remote-p try)
(ffap-file-exists-string try))))))
try))
+ ;; Try adding a leading "/" (common omission in ftp file names).
+ ;; Note that this uses oname, which still has any colon part.
+ ;; This should have a lower priority than the alist stuff,
+ ;; else it matches things like "ffap.el:1234:56:Warning".
+ ((and (not abs)
+ ffap-ftp-sans-slash-regexp
+ (string-match ffap-ftp-sans-slash-regexp oname)
+ (ffap-file-remote-p (concat "/" oname))))
;; Alist failed? Try to guess an active remote connection
;; from buffer variables, and try once more, both as an
;; absolute and relative file name on that remote host.
))
(setq dir (file-name-directory guess))))
(let ((minibuffer-completing-file-name t)
- (completion-ignore-case read-file-name-completion-ignore-case))
- (setq guess
- (completing-read
- prompt
- 'ffap-read-file-or-url-internal
- dir
- nil
- (if dir (cons guess (length dir)) guess)
- (list 'file-name-history)
- (and buffer-file-name
- (abbreviate-file-name buffer-file-name)))))
+ (completion-ignore-case read-file-name-completion-ignore-case)
+ (fnh-elem (cons ffap-url-regexp 'url-file-handler)))
+ ;; Explain to `rfn-eshadow' that we can use URLs here.
+ (push fnh-elem file-name-handler-alist)
+ (unwind-protect
+ (setq guess
+ (completing-read
+ prompt
+ 'ffap-read-file-or-url-internal
+ dir
+ nil
+ (if dir (cons guess (length dir)) guess)
+ (list 'file-name-history)
+ (and buffer-file-name
+ (abbreviate-file-name buffer-file-name))))
+ ;; Remove the special handler manually. We used to just let-bind
+ ;; file-name-handler-alist to preserve its value, but that caused
+ ;; other modifications to be lost (e.g. when Tramp gets loaded
+ ;; during the completing-read call).
+ (setq file-name-handler-alist (delq fnh-elem file-name-handler-alist))))
;; Do file substitution like (interactive "F"), suggested by MCOOK.
(or (ffap-url-p guess) (setq guess (substitute-in-file-name guess)))
;; Should not do it on url's, where $ is a common (VMS?) character.
\f
;;; Bug Reporter:
-(defun ffap-bug nil
- "Submit a bug report for the ffap package."
- ;; Important: keep the version string here in synch with that at top
- ;; of file! Could use lisp-mnt from Emacs 19, but that would depend
- ;; on being able to find the ffap.el source file.
- (interactive)
- (require 'reporter)
- (let ((reporter-prompt-for-summary-p t))
- (reporter-submit-bug-report
- "Michelangelo Grigni <mic@mathcs.emory.edu>"
- "ffap"
- (mapcar 'intern (all-completions "ffap-" obarray 'boundp)))))
-
-(fset 'ffap-submit-bug 'ffap-bug) ; another likely name
+(define-obsolete-function-alias 'ffap-bug 'report-emacs-bug "23.1")
+(define-obsolete-function-alias 'ffap-submit-bug 'report-emacs-bug "23.1")
\f
;;; Hooks for Gnus, VM, Rmail:
(defvar gnus-summary-buffer)
(defvar gnus-article-buffer)
+;; This code is called from gnus.
+(declare-function gnus-summary-select-article "gnus-sum"
+ (&optional all-headers force pseudo article))
+
+(declare-function gnus-configure-windows "gnus-win"
+ (setting &optional force))
+
(defun ffap-gnus-wrapper (form) ; used by both commands below
(and (eq (current-buffer) (get-buffer gnus-summary-buffer))
(gnus-summary-select-article)) ; get article of current line
;; Extra complication for the temporary highlighting.
(unwind-protect
(ffap-read-file-or-url
- (if ffap-url-regexp "Dired file or URL: " "Dired file: ")
+ (cond
+ ((eq ffap-directory-finder 'list-directory)
+ "List directory (brief): ")
+ (ffap-url-regexp "Dired file or URL: ")
+ (t "Dired file: "))
(prog1
(setq guess (or guess
(let ((guess (ffap-guesser)))