This comes from ffap (find file at point), as the name might suggest. Specifically, find-file
uses read-file-name
to read its input, which in turn calls read-file-name-default
unless overridden through the variable read-file-name-function
. read-file-name-default
calls the auxiliary function read-file-name--defaults
to build the initial inputs: current directory, file name at point (if non-nil), and current file name (if non-nil). The file name at point is the first function from file-name-at-point-functions
that returns non-nil, and this list of functions contains ffap-guess-file-name-at-point
by default. For our purposes, this function is a wrapper around ffap-file-at-point
.
To completely turn off the file-name-at-point feature of find-file
and other functions that prompt for a file name, you can advise read-file-name--defaults
or read-file-name-default
or read-file-name
. Untested:
(defadvice read-file-name
(around read-file-name-no-ffap activate)
(let ((file-name-at-point-functions nil))
ad-do-it))
To skip not-really-a-file-name strings such as /**
, from all uses of ffap-file-at-point
, you can advise ffap-file-at-point
.
(defadvice ffap-file-at-point
(after ffap-file-at-point-false-positives activate compile)
"Omit certain false positives from the guesses."
(if (save-match-data
(and ad-return-value
;; If it doesn't have at least one letter, it's probably
;; not a file name.
(not (string-match "[A-Za-z]" ad-return-value))))
(setq ad-return-value nil)))
(This answer uses the “classic” advice interface that's compatible with older Emacs version. If you don't care about old versions, you may want to port them to the modern advice interface.)