Subject: Aw: Re: Re: Re: bug#7229: 23.1; ido guess and ffap bug

From: "Thibault Kruse" <[email-masked]>
Date: Sat, 13 Jul 2013 10:01:33 +0200 (CEST)

Ok, so what I get with what you tell me is that:

C-x C-f never uses ffap

C-u C-x C-f   always uses ffap (and thus also has the false positives for '/**' and '/>' )

So as a user I'd have to learn and remember another keyboard shortcut to use when I want to have ido with ffap, is that the idea?

Personally, that idea might work for me (though I don't love it), but that leaves the rest of the world with bad defaults.

On a related note, I found this:

http://www.emacswiki.org/emacs/FindFileAtPoint

See "Ignore '/'" for a workaround by someone else to fix related problems.

Also looking at ffap.el sourcecode:

http://bzr.savannah.gnu.org/lh/emacs/emacs-23/annotate/head:/lisp/ffap.el

;; Immediate rejects (/ and // and /* are too common in C/C++):

((member name '("" "/" "//" "/*" ".")) nil)

So really ffap already breaks consistency for convenience, but only considers C/C++ coders. And '/' is not considered a valid completion prefix, though '/>' is considered a valid prefix and resolves to the only existing parent '/'. That's all a bit weird in ffap. If '/' itself is not valid, then maybe '/' should never be returned as suggestion by ffap (as in />, or /foo where /foo does not exist)?

Actually the way I fixed the problem in 7229 is this (sorry i took some time to remember, it has been 3 years):

(defadvice ffap-file-at-point (around bugfix-ffap  activate)
"returns nil when point is somewhere we do not want to guess filenames"
(require 'thingatpt)
;;; prevent in javadoc style comments
(unless (or
;; ignore shebang lines, we are there very often and mostly do not want to open the executable
(thing-at-point-looking-at "#!/[a-zA-Z0-9:_.-/]+")
;; ignore /**...* comment starts (Java-like languages, files name /*** are possible, but really unlikely)
(thing-at-point-looking-at "/[\\*]+")
;; for xml modes, don't attemt to ffap-file-at-point when point is on </foo> or after <foo />, because we never want that.
(and (member major-mode '(sgml-mode nxml-mode))
;; don't care about <somenode/> and </somenode>
(or (thing-at-point-looking-at "</?[a-zA-Z_][a-zA-Z0-9:_.-]*>?")
(thing-at-point-looking-at "/>"))))
ad-do-it))

So my advice would be to update the ffap ffap-file-at-point functions immediate rejects to include several more common false positive cases outside C/C++. My "patch" above also fixes shebang lines like "#! /usr/bin/python" which is highly annoying when working with several python scripts, and ido was constantly suggesting to open the python executable.

Another shortcut (like C-u C-x C-f) should IMHO only be necessary for forcing ffap to not reject anything, for those corner cases when a user has unusual work to do.

Again, it is a design decision, not a bug. I believe emacs users will be happier if C-x C-f with ido-ffap uses heuristics to avoid common false positives, rather than having to learn another shortcut.

Gesendet: Samstag, 13. Juli 2013 um 03:25 Uhr
Von: "Leo Liu" <[email-masked]>
An: "Thibault Kruse" <[email-masked]>
Cc: [email-masked]
Betreff: Re: Aw: Re: Re: bug#7229: 23.1; ido guess and ffap bug

On 2013-07-12 15:52 +0800, Thibault Kruse wrote:
> I tried:
> emacs -q --no-site-file
> M-x ido-mode
> M-x ielm
> pasted the lines you gave
> switch to scratch buffer
> typed "~/local" which exists
> press C-x C-f

Instead of C-x C-f, Try C-u C-x C-f.

> no prefix is used, ido just shows ~
> debugger also indicates the prefix var is nil

Please please write to the bug address [email-masked] instead of
my email.

Leo