* lisp/minibuffer.el (completion-file-name-affixation): New function.
(completion-file-name-table): Use it as 'affixation-function'.
* doc/emacs/help.texi (Name Help): Move doc of 'completions-detailed'
from here to...
* doc/emacs/mini.texi (Completion Options): ...here. Improve wording.
* etc/NEWS: Announce.
@xref{Narrow Completions}, and @ref{Symbol Properties,,,elisp,The
Emacs Lisp Reference Manual}.
-@vindex completions-detailed
- If the @code{completions-detailed} user option is non-@code{nil},
-some commands provide details about the possible values when
-displaying completions. For instance, @kbd{C-h o TAB} will then
-include the first line of the doc string, and will also say whether
-each symbol is a function or a variable (and so on). Which details
-are included varies depending on the command used.
-
@node Apropos
@section Apropos
@cindex apropos
highlighting. This feature uses the special text property
@code{cursor-face}.
+@vindex completions-detailed
+If the @code{completions-detailed} user option is non-@code{nil}, some
+commands that provide completion display extra details as annotations
+next to completion candidates in the @file{*Completions*} buffer.
+Which details are included varies between different commands. For
+instance, the completions list for @kbd{C-h o} (@pxref{Name Help})
+includes the first line of the doc string of each symbol, and says
+whether each symbol is a function or a variable (and so on). For file
+name completion, the extra details annotations include file modes,
+sizes, modification times and ownership information.
+
@node Minibuffer History
@section Minibuffer History
@cindex minibuffer history
and you can now customize the face 'completions-heading' to control
its appearance.
++++
+*** File name completions can now provide detailed candidate annotations.
+With non-nil user option 'completions-detailed', Emacs now displays
+extra details about file name completion candidates in the
+"*Completions*" buffer as completion annotations.
+
** Pcomplete
---
(completion-table-with-context
prefix table (substring string beg) nil action)))))))
+(defun completion-file-name-affixation (files)
+ "Return completion affixations for file list FILES."
+ (let ((max-file (seq-max (mapcar #'string-width files))))
+ (mapcar
+ (lambda (file)
+ (list
+ file
+ "" ; empty prefix
+ (if-let ((attrs
+ (ignore-errors
+ (file-attributes
+ (substitute-in-file-name
+ (concat minibuffer-completion-base file))
+ 'string))))
+ (propertize
+ (concat (propertize " " 'display
+ `(space :align-to ,(+ max-file 2)))
+ (file-attribute-modes attrs)
+ " "
+ (format "%8s" (file-size-human-readable
+ (file-attribute-size attrs)))
+ " "
+ (format-time-string
+ "%Y-%m-%d %T" (file-attribute-modification-time attrs))
+ " "
+ (file-attribute-user-id attrs)
+ ":"
+ (file-attribute-group-id attrs))
+ 'face 'completions-annotations)
+ "")))
+ files)))
+
(defun completion-file-name-table (string pred action)
"Completion table for file names."
(condition-case nil
(cond
- ((eq action 'metadata) '(metadata (category . file)))
+ ((eq action 'metadata)
+ `(metadata
+ (category . file)
+ ,@(when completions-detailed
+ '((affixation-function . completion-file-name-affixation)))))
((string-match-p "\\`~[^/\\]*\\'" string)
(completion-table-with-context "~"
(mapcar (lambda (u) (concat u "/"))