emacs-devel
[Top][All Lists]
Advanced

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

Re: [Emacs-diffs] master e0ee41d: Allow customizing the display of proje


From: Basil L. Contovounesios
Subject: Re: [Emacs-diffs] master e0ee41d: Allow customizing the display of project file names when reading
Date: Wed, 15 May 2019 18:46:50 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

address@hidden (Dmitry Gutov) writes:

> branch: master
> commit e0ee41d155b210327eb9c9ad5334f80ed59439f4
> Author: Dmitry Gutov <address@hidden>
> Commit: Dmitry Gutov <address@hidden>
>
>     Allow customizing the display of project file names when reading
>     
>     To hopefully resolve a long-running discussion
>     (https://lists.gnu.org/archive/html/emacs-devel/2019-05/msg00162.html).
>     
>     * lisp/progmodes/project.el (project-read-file-name-function):
>     New variable.
>     (project--read-file-absolute, project--read-file-cpd-relative):
>     New functions, possible values for the above.
>     (project-find-file-in): Use the introduced variable.
>     (project--completing-read-strict): Retain just the logic that fits
>     the name.

[...]

> diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
> index 7c8ca15..ddb4f33 100644
> --- a/lisp/progmodes/project.el
> +++ b/lisp/progmodes/project.el
> @@ -470,55 +464,72 @@ recognized."
>                  (project-external-roots pr))))
>      (project-find-file-in (thing-at-point 'filename) dirs pr)))
>  
> +(defcustom project-read-file-name-function #'project--read-file-cpd-relative
> +  "Function to call to read a file name from a list.
> +For the arguments list, see `project--read-file-cpd-relative'."
> +  :type '(repeat (choice (const :tag "Read with completion from relative 
> names"
> +                                project--read-file-cpd-relative)
> +                         (const :tag "Read with completion from absolute 
> names"
> +                                project--read-file-absolute)
> +                         (function :tag "custom function" nil))))
> +
> +(defun project--read-file-cpd-relative (prompt
> +                                        all-files &optional predicate
> +                                        hist default)
> +  (let* ((common-parent-directory
> +          (let ((common-prefix (try-completion "" all-files)))
> +            (if (> (length common-prefix) 0)
> +                (file-name-directory common-prefix))))
> +         (cpd-length (length common-parent-directory))
> +         (prompt (if (zerop cpd-length)
> +                     prompt
> +                   (concat prompt (format " in %s" 
> common-parent-directory))))
> +         (substrings (mapcar (lambda (s) (substring s cpd-length)) 
> all-files))
> +         (new-collection (project--file-completion-table substrings))
> +         (res (project--completing-read-strict prompt
> +                                               new-collection
> +                                               predicate
> +                                               hist default)))
> +    (concat common-parent-directory res)))

Sorry if this has been discussed before, and maybe it's just me, but I
don't think it makes sense to offer internal double hyphen functions as
alternatives for a user option, let alone to point the user to such an
internal function which lacks a docstring, "for the argument list".

Thanks,

-- 
Basil



reply via email to

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