Function: find-file-at-point

find-file-at-point is an autoloaded, interactive and byte-compiled function defined in ffap.el.gz.

Signature

(find-file-at-point &optional FILENAME)

Documentation

Find FILENAME, guessing a default from text around point.

If ffap-url-regexp is not nil, the FILENAME may also be an URL. With a prefix, this command behaves exactly like ffap-file-finder. If ffap-require-prefix is set, the prefix meaning is reversed. See also the variables ffap-dired-wildcards, ffap-newfile-prompt, ffap-url-unwrap-local(var)/ffap-url-unwrap-local(fun), ffap-url-unwrap-remote(var)/ffap-url-unwrap-remote(fun), ffap-file-name-with-spaces, and the functions ffap-file-at-point and ffap-url-at-point.

Probably introduced at or before Emacs version 28.1.

Key Bindings

Aliases

ffap

Source Code

;; Defined in /usr/src/emacs/lisp/ffap.el.gz
;;;###autoload
(defun find-file-at-point (&optional filename)
  "Find FILENAME, guessing a default from text around point.
If `ffap-url-regexp' is not nil, the FILENAME may also be an URL.
With a prefix, this command behaves exactly like `ffap-file-finder'.
If `ffap-require-prefix' is set, the prefix meaning is reversed.
See also the variables `ffap-dired-wildcards', `ffap-newfile-prompt',
`ffap-url-unwrap-local', `ffap-url-unwrap-remote',
`ffap-file-name-with-spaces', and the functions `ffap-file-at-point'
and `ffap-url-at-point'."
  (interactive)
  (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:
      (let (current-prefix-arg)		; we already interpreted it
	(call-interactively ffap-file-finder))
    (or filename (setq filename (ffap-prompter)))
    (let ((url (ffap-url-p filename)))
      (cond
       (url
	(let (current-prefix-arg)
	  (funcall ffap-url-fetcher url)))
       ((and ffap-pass-wildcards-to-dired
	     ffap-dired-wildcards
	     (string-match ffap-dired-wildcards filename))
	(funcall ffap-directory-finder filename))
       ((and ffap-dired-wildcards
	     (string-match ffap-dired-wildcards filename)
	     find-file-wildcards
	     ;; Check if it's find-file that supports wildcards arg
	     (memq ffap-file-finder '(find-file find-alternate-file)))
	(funcall ffap-file-finder (expand-file-name filename) t))
       ((or (not ffap-newfile-prompt)
	    (file-exists-p filename)
	    (y-or-n-p "File does not exist, create buffer? "))
	(find-file
	 ;; expand-file-name fixes "~/~/.emacs" bug sent by CHUCKR.
	 (expand-file-name filename)))
       ;; User does not want to find a non-existent file:
       ((signal 'file-missing (list "Opening file buffer"
				    "No such file or directory"
				    filename)))))))