• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.9.5/emacs-92/emacs/lisp/

Lines Matching +defs:file +defs:regexp

1 ;;; ffap.el --- find file (or url) at point
12 ;; This file is part of GNU Emacs.
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
33 ;; Command find-file-at-point replaces find-file. With a prefix, it
34 ;; behaves exactly like find-file. Without a prefix, it first tries
35 ;; to guess a default file or URL from the text around the point
41 ;; For the default installation, add this line to your .emacs file:
47 ;; C-x C-f find-file-at-point (abbreviated as ffap)
49 ;; C-x C-v ffap-alternate-file
81 ;; (setq ffap-url-regexp nil) ; disable URL features in ffap
82 ;; (setq ffap-shell-prompt-regexp nil) ; disable shell prompt stripping
87 ;; the file and URL references within a buffer.
100 ;; * let "/dir/file#key" jump to key (tag or regexp) in /dir/file
101 ;; * find file of symbol if TAGS is loaded (like above)
104 ;; * notice "machine.dom blah blah blah dir/file" (how?)
106 ;; * regexp options for ffap-string-at-point, like font-lock (MCOOK)
107 ;; * v19: could replace `ffap-locate-file' with a quieter `locate-library'
123 "Find file or URL at point."
142 (defcustom ffap-shell-prompt-regexp
147 "Paths matching this regexp are stripped off the shell prompt
151 regexp)
154 (defcustom ffap-ftp-regexp
158 "*File names matching this regexp are treated as remote ffap.
162 regexp)
166 "*If non-nil, convert `file:' URL to local file name before prompting."
171 "*If non-nil, convert `ftp:' URL to remote file name before prompting.
172 This is ignored if `ffap-ftp-regexp' is nil."
177 "*User name in ftp file names generated by `ffap-host-to-path'.
183 (defcustom ffap-rfs-regexp
184 ;; Remote file access built into file system? HP rfa or Andrew afs:
186 ;; afs only: (and (file-exists-p "/afs") "\\`/afs/.")
187 "*Matching file names are treated as remote. Use nil to disable."
188 :type 'regexp
191 (defvar ffap-url-regexp
193 ;; This regexp is not exhaustive, it just matches common cases.
196 "news\\(post\\)?:\\|mailto:\\|file:" ; no host ok
221 ;; enabler in your .emacs file.
224 "*A regexp matching filename wildcard characters, or nil.
226 If `find-file-at-point' gets a filename matching this pattern,
228 `find-file' with non-nil WILDCARDS argument, which expands
229 wildcards and visits multiple files. To visit a file whose name
231 by setting `find-file-wildcards'. If `find-file-at-point' gets a
239 ;; regexp -- probably not useful
250 ;; better handled by `find-file-not-found-hooks'.
251 "*Whether `find-file-at-point' prompts about a nonexistent file."
257 "*If set, reverses the prefix argument to `find-file-at-point'.
263 (defcustom ffap-file-finder 'find-file
264 "*The command called by `find-file-at-point' to find a file."
267 (put 'ffap-file-finder 'risky-local-variable t)
314 (defcustom ffap-next-regexp
316 ;; (and ffap-url-regexp (string-match "\\\\`" ffap-url-regexp)
317 ;; (concat "\\<" (substring ffap-url-regexp 2))))
319 ;; It pays to put a big fancy regexp here, since ffap-guesser is
320 ;; much more time-consuming than regexp searching:
323 :type 'regexp
333 "Move point to next file or URL, and return it as a string.
337 Only considers strings that match `ffap-next-regexp'."
342 ffap-next-regexp lim 'move)
350 "Search buffer for next file or URL, and run ffap.
368 (find-file-at-point (ffap-prompter guess)))
374 "Like `ffap-next', but search with `ffap-url-regexp'."
376 (let ((ffap-next-regexp ffap-url-regexp))
473 ;; (file-error "connection failed" "permission denied"
475 ;; (file-error "connection failed" "host is unreachable"
477 ;; (file-error "connection failed" "address already in use"
491 (defun ffap-replace-file-component (fullname name)
503 (fset 'ffap-replace-file-component found)
505 ;; (ffap-replace-file-component "/who@foo.com:/whatever" "/new")
507 (defun ffap-file-suffix (file)
509 (let ((pos (string-match "\\.[^./]*\\'" file)))
510 (and pos (substring file pos nil))))
513 "List of suffixes tried by `ffap-file-exists-string'.")
515 (defun ffap-file-exists-string (file &optional nomodify)
516 ;; Early jka-compr versions modified file-exists-p to return the
518 ;; broke the interface of file-exists-p, so it was later dropped.
520 "Return FILE (maybe modified) if the file exists, else nil.
525 ((not file) nil) ; quietly reject nil
526 ((file-exists-p file) file) ; try unmodified first
529 ((not (rassq 'jka-compr-handler file-name-handler-alist)) nil)
530 ((member (ffap-file-suffix file) ffap-compression-suffixes) nil)
534 (if (file-exists-p (setq try (concat file (car list))))
539 (defun ffap-file-remote-p (filename)
541 ;; (ffap-file-remote-p "/user@foo.bar.com:/pub")
542 ;; (ffap-file-remote-p "/cssun.mathcs.emory.edu://dir")
543 ;; (ffap-file-remote-p "/ffap.el:80")
544 (or (and ffap-ftp-regexp
545 (string-match ffap-ftp-regexp filename)
553 (and ffap-rfs-regexp
554 (string-match ffap-rfs-regexp filename)
575 ;; Convert a hostname into an url, an ftp file name, or nil.
577 ((not (and ffap-url-regexp (stringp mach))) nil)
585 (ffap-ftp-regexp (ffap-host-to-filename mach))
588 (defvar ffap-newsgroup-regexp "^[[:lower:]]+\\.[-+[:lower:]_0-9.]+$"
597 (string-match ffap-newsgroup-regexp string)
624 (and ffap-url-regexp (string-match ffap-url-regexp string)
630 "Return URL as a local file, or nil. Ignores `ffap-url-regexp'."
631 (and (string-match "\\`\\(file\\|ftp\\):/?\\([^/]\\|\\'\\)" url)
634 "Return URL as a remote file, or nil. Ignores `ffap-url-regexp'."
635 (and (string-match "\\`\\(ftp\\|file\\)://\\([^:/]+\\):?\\(/.*\\)" url)
642 "Clean up URL and return it, maybe as a file name."
646 ((and ffap-url-unwrap-remote ffap-ftp-regexp
674 ;; "//" entries using file-name-as-directory.
682 ;;(and (file-directory-p dir) (not (member dir ret)) ...)
698 (not (file-directory-p (car tem)))
707 (and (file-exists-p dir)
708 (ffap-all-subdirs-loop (expand-file-name dir) (or depth -1))))
719 ((not (file-directory-p d)) nil)
720 ((file-symlink-p d) (list d))
743 (defun ffap-locate-file (file &optional nosuffix path dir-ok)
746 ;; compression-suffixes search moved to ffap-file-exists-string.
748 Returns path to file that \(load FILE\) would load, or nil.
756 This uses ffap-file-exists-string, which may try adding suffixes from
759 (or dir-ok (setq dir-ok (equal "" (file-name-nondirectory file))))
760 (if (file-name-absolute-p file)
761 (setq path (list (file-name-directory file))
762 file (file-name-nondirectory file)))
772 (setq try (ffap-file-exists-string
773 (expand-file-name
774 (concat file (car suffixes)) (car path))))
775 (if (and try (or dir-ok (not (file-directory-p try))))
816 "Alist of \(KEY . FUNCTION\) pairs parsed by `ffap-file-at-point'.
817 If string NAME at point (maybe \"\") is not a file or url, these pairs
820 KEY is a string, it should matches NAME as a regexp.
821 On a match, \(FUNCTION NAME\) is called and should return a file, an
848 (let* ((dir (or (file-name-directory name) default-directory))
849 (cmp (file-name-completion (file-name-nondirectory name) dir)))
852 (defun ffap-home (name) (ffap-locate-file name t '("~")))
855 (ffap-locate-file
867 (defun ffap-el (name) (ffap-locate-file name t))
873 (ffap-locate-file name '(".el"))))
879 (ffap-locate-file name t ffap-c-path))
884 (ffap-locate-file name t ffap-fortran-path))
911 (ffap-locate-file name '(".tex" "") ffap-tex-path))
916 (ffap-locate-file name '(".cls" ".sty" ".tex" "") ffap-tex-path))
920 (ffap-locate-file name t ffap-tex-path))
932 (ffap-locate-file name t ffap-bib-path))
942 (file-exists-p
944 (expand-file-name
964 (file-name-as-directory
986 (file "--:$+<>@-Z_[:lower:]~*?" "<@" "@>;.,!:")
998 `file', `url', `machine', and `nocolon'.
1012 If MODE is not found, we use `file' instead of MODE.
1018 (assq 'file ffap-string-at-point-mode-alist))))
1069 ffap-url-regexp
1094 (not (string-match "~" (expand-file-name (concat "~" name))))
1101 (defvar ffap-gopher-regexp
1111 (if (looking-at ffap-gopher-regexp)
1113 (while (and (looking-at ffap-gopher-regexp) (not (bobp)))
1115 (or (looking-at ffap-gopher-regexp) (forward-line 1))
1117 (while (looking-at ffap-gopher-regexp)
1136 (defvar ffap-ftp-sans-slash-regexp
1138 ffap-ftp-regexp
1140 ;; Icky regexp avoids: default: 123: foo::bar cs:pub
1143 "Strings matching this are coerced to ftp file names by ffap.
1146 (defun ffap-file-at-point nil
1153 ;; a pseudo-url "site.com://dir" to an ftp file name
1160 (substitute-in-file-name string))
1163 (abs (file-name-absolute-p name))
1172 ((and (not abs) (ffap-file-exists-string name)))
1175 (ffap-file-exists-string (substring name 0 (match-beginning 0)))))
1177 ;; if the ffap-shell-prompt-regexp is non-nil.
1178 ((and ffap-shell-prompt-regexp
1179 (not abs) (string-match ffap-shell-prompt-regexp name)
1180 (ffap-file-exists-string (substring name (match-end 0)))))
1182 ((and abs (ffap-file-remote-p name)))
1184 ((and abs (ffap-file-exists-string name)))
1188 (ffap-file-exists-string name)))
1201 (ffap-url-p try) ; not a file!
1202 (ffap-file-remote-p try)
1203 (ffap-file-exists-string try))))))
1205 ;; Try adding a leading "/" (common omission in ftp file names).
1210 ffap-ftp-sans-slash-regexp
1211 (string-match ffap-ftp-sans-slash-regexp oname)
1212 (ffap-file-remote-p (concat "/" oname))))
1215 ;; absolute and relative file name on that remote host.
1216 ((let* (ffap-rfs-regexp ; suppress
1219 ((ffap-file-remote-p default-directory))
1232 (ffap-file-exists-string
1233 (ffap-replace-file-component
1235 (ffap-file-exists-string
1236 (ffap-replace-file-component remote-dir name))))))
1240 (ffap-file-exists-string (file-name-directory
1241 (directory-file-name name)))
1247 (not (ffap-file-exists-string dir))
1248 (not (equal dir (setq dir (file-name-directory
1249 (directory-file-name dir)))))))
1250 (ffap-file-exists-string dir)))
1255 ;;; Prompting (`ffap-read-file-or-url'):
1257 ;; We want to complete filenames as in read-file-name, but also url's
1258 ;; which read-file-name-internal would truncate at the "//" string.
1259 ;; The solution here is to replace read-file-name-internal with
1260 ;; `ffap-read-file-or-url-internal', which checks the minibuffer
1263 (defun ffap-read-file-or-url (prompt guess)
1264 "Read file or url from minibuffer, with PROMPT and initial GUESS."
1271 (or (ffap-file-remote-p guess)
1273 (abbreviate-file-name (expand-file-name guess))
1275 (setq dir (file-name-directory guess))))
1276 (let ((minibuffer-completing-file-name t)
1277 (completion-ignore-case read-file-name-completion-ignore-case))
1281 'ffap-read-file-or-url-internal
1285 (list 'file-name-history)
1286 (and buffer-file-name
1287 (abbreviate-file-name buffer-file-name)))))
1288 ;; Do file substitution like (interactive "F"), suggested by MCOOK.
1289 (or (ffap-url-p guess) (setq guess (substitute-in-file-name guess)))
1306 (defun ffap-read-file-or-url-internal (string dir action)
1313 (read-file-name-internal string dir action)))
1321 (defun ffap-complete-as-file-p nil
1325 (if (eq minibuffer-completion-table 'ffap-read-file-or-url-internal)
1327 (and minibuffer-completing-file-name '(t)))) ;list
1331 (if (boundp 'PC-completion-as-file-name-predicate)
1333 (setq PC-completion-as-file-name-predicate 'ffap-complete-as-file-p)))
1377 ;;; Main Entrance (`find-file-at-point' == `ffap'):
1380 "Return file or URL or nil, guessed from text around point."
1381 (or (and ffap-url-regexp
1384 (ffap-file-at-point) ; may yield url!
1388 ;; Does guess and prompt step for find-file-at-point.
1394 (ffap-read-file-or-url
1395 (if ffap-url-regexp "Find file or URL: " "Find file: ")
1403 (defun find-file-at-point (&optional filename)
1405 If `ffap-url-regexp' is not nil, the FILENAME may also be an URL.
1406 With a prefix, this command behaves exactly like `ffap-file-finder'.
1409 and the functions `ffap-file-at-point' and `ffap-url-at-point'."
1414 ;; Do exactly the ffap-file-finder command, even the prompting:
1416 (call-interactively ffap-file-finder))
1428 find-file-wildcards
1429 ;; Check if it's find-file that supports wildcards arg
1430 (memq ffap-file-finder '(find-file find-alternate-file)))
1431 (funcall ffap-file-finder (expand-file-name filename) t))
1433 (file-exists-p filename)
1435 (funcall ffap-file-finder
1436 ;; expand-file-name fixes "~/~/.emacs" bug sent by CHUCKR.
1437 (expand-file-name filename)))
1438 ;; User does not want to find a non-existent file:
1439 ((signal 'file-error (list "Opening file buffer"
1440 "no such file or directory"
1443 ;; Shortcut: allow {M-x ffap} rather than {M-x find-file-at-point}.
1445 (defalias 'ffap 'find-file-at-point)
1451 (defvar ffap-menu-regexp nil
1452 "*If non-nil, overrides `ffap-next-regexp' during `ffap-menu'.
1473 a rebuild. Searches with `ffap-menu-regexp'."
1486 (if ffap-url-regexp "Find file or URL" "Find file")
1500 (find-file-at-point (car choice)))
1543 "Search buffer for `ffap-menu-regexp' to build `ffap-menu-alist'.
1546 (let ((ffap-next-regexp (or ffap-menu-regexp ffap-next-regexp))
1556 'file)))
1597 "Find file or url guessed from text around mouse click.
1619 (find-file-at-point guess)
1625 (message "No file or url found at mouse click.")
1700 (defun ffap-alternate-file ()
1701 "Like `ffap' and `find-alternate-file'.
1704 (let ((ffap-file-finder 'find-alternate-file))
1714 ;; of file! Could use lisp-mnt from Emacs 19, but that would depend
1715 ;; on being able to find the ffap.el source file.
1785 "Start Dired, defaulting to file at point. See `ffap'."
1800 ((file-exists-p filename)
1801 (if (file-directory-p filename)
1803 (expand-file-name filename))
1805 (concat (expand-file-name filename) "*"))))
1806 ((and (file-writable-p
1807 (or (file-name-directory (directory-file-name filename))
1812 ((error "No such file or directory `%s'" filename)))))
1815 ;; Does guess and prompt step for find-file-at-point.
1818 (ffap-read-file-or-url
1819 (if ffap-url-regexp "Dired file or URL: " "Dired file: ")
1825 (ffap-file-remote-p guess))
1827 (setq guess (abbreviate-file-name
1828 (expand-file-name guess)))
1831 ((file-directory-p guess)
1832 (file-name-as-directory guess))
1834 ((file-regular-p guess)
1835 (file-name-directory guess))
1889 (global-set-key "\C-x\C-f" 'find-file-at-point)
1891 (global-set-key "\C-x\C-v" 'ffap-alternate-file)