bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#16648: [PATCH] Improved ffap-completable


From: Lars Ingebrigtsen
Subject: bug#16648: [PATCH] Improved ffap-completable
Date: Wed, 24 Feb 2016 14:23:54 +1100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

E Sabof <esabof@gmail.com> writes:

> Assuming that point is at the word "The", and the complete filename
> follows. The current version will work when the default-directory
> contains one file "The first file.txt". But it won't if there is
> another file "The second file.txt", since file-name-completion will
> only give a partial completion.

I think the patch below looks reasonable, but I rarely use ffap, so I'm
not quite sure.  Anybody have an opinion?

Also, this patch is more than 15 lines, so we need FSF copyright
assignment papers before applying it.  Would you be willing so sign such
papers?

>
> diff --git a/lisp/ffap.el b/lisp/ffap.el
> index bb0f61d..4655639 100644
> --- a/lisp/ffap.el
> +++ b/lisp/ffap.el
> @@ -819,8 +819,28 @@ URL, or nil.  If nil, search the alist for further 
> matches.")
>
>  (defun ffap-completable (name)
>    (let* ((dir (or (file-name-directory name) default-directory))
> -      (cmp (file-name-completion (file-name-nondirectory name) dir)))
> -    (and cmp (concat dir cmp))))
> +         (completions (file-name-all-completions
> +                       (file-name-nondirectory name) dir))
> +         (looking-at-candidate
> +          (lambda (candidate)
> +            (string-equal (buffer-substring
> +                           (point)
> +                           (min (+ (point) (length candidate))
> +                                (point-max)))
> +                          candidate)))
> +         start)
> +    (when (and completions (cdr completions))
> +      (setq completions
> +            (or (cl-remove-if-not looking-at-candidate
> +                                  completions)
> +                (and (setq start (car (bounds-of-thing-at-point 'symbol)))
> +                     (/= start (point))
> +                     (save-excursion
> +                       (goto-char start)
> +                       (cl-remove-if-not looking-at-candidate
> +                                         completions))))))
> +    (when completions
> +      (concat dir (car completions)))))
>
>  (defun ffap-home (name) (ffap-locate-file name t '("~")))

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





reply via email to

[Prev in Thread] Current Thread [Next in Thread]