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

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

bug#56380: 29.0.50; completing-read: INITIAL-INPUT arg


From: Michael Heerdegen
Subject: bug#56380: 29.0.50; completing-read: INITIAL-INPUT arg
Date: Mon, 04 Jul 2022 14:18:55 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Hello,

The docstring of `completing-read' says the argument INITIAL-INPUT is
deprecated - yet there are over 30 nontrivial uses in Emacs' own Elisp
sources.  So, although we currently don't want that this argument is
used just to insert a default input, it's sometimes not possible to
avoid using it.

Here is an attempt to improve the documentation:

From e2a4e843c262416b7b866203a7e636265beb4673 Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <michael_heerdegen@web.de>
Date: Mon, 27 Jun 2022 15:42:58 +0200
Subject: [PATCH] completing-read: Clarify why to avoid INITIAL-INPUT

* src/minibuf.c (completing-read): Don't say INITIAL-INPUT is
deprecated because it's necessary to use it in some cases.
Mention M-n and M-p as well as `minibuffer-with-setup-hook'.

Co-authored-by: Drew Adams <drew.adams@oracle.com>
---
 src/minibuf.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/minibuf.c b/src/minibuf.c
index c2e270a450..2ad74e4d38 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -2026,10 +2026,11 @@ DEFUN ("completing-read", Fcompleting_read, 
Scompleting_read, 2, 8, 0,
   initial input is STRING, but point is placed at _zero-indexed_
   position POSITION in STRING.  (*Note* that this is different from
   `read-from-minibuffer' and related functions, which use one-indexing
-  for POSITION.)  This feature is deprecated--it is best to pass nil
-  for INITIAL-INPUT and supply the default value DEF instead.  The
-  user can yank the default value into the minibuffer easily using
-  \\<minibuffer-local-map>\\[next-history-element].
+  for POSITION.)  Don't use this argument to insert a default value --
+  use DEF for that.  You can use INITIAL-INPUT, for example, to insert
+  a prefix common to all completion candidates.  See
+  `minibuffer-with-setup-hook' for a general method to prepare the
+  minibuffer.

 HIST, if non-nil, specifies a history list and optionally the initial
   position in the list.  It can be a symbol, which is the history list
@@ -2044,6 +2045,9 @@ DEFUN ("completing-read", Fcompleting_read, 
Scompleting_read, 2, 8, 0,
   of a history list.  If HIST is t, history is not recorded.

 DEF, if non-nil, is the default value or the list of default values.
+  These can be yanked into the minibuffer using \
+\\<minibuffer-local-map>\\[next-history-element] and \
+\\[previous-history-element].

 If INHERIT-INPUT-METHOD is non-nil, the minibuffer inherits the
   current input method and the setting of `enable-multibyte-characters'.
--
2.30.2

This patch is the result of a discussion in emacs dev:

  https://yhetil.org/emacs-devel/87v8smt9lp.fsf@web.de/

Further things mentioned in that discussion:

1.  Likewise we want to improve the docstrings of `read-string' and
`read-from-minibuffer'.  And as well (Arash Esbati):

  Emacs Lisp reference the text/descriptions in

   @node Text from Minibuffer
   @section Reading Text Strings with the Minibuffer

   @node Initial Input
   @section Initial Input

   @node Minibuffer Completion
   @subsection Completion and the Minibuffer

2.  Add a minor mode that automatically inserts a DEF into the
minibuffer, and add a defcustom to allow users to enable that mode in
their configuration.  Some people simply prefer that behavior.  This
would allow people to avoid using INITIAL-INPUT to get what they want.

3. Stefan Monnier:

  [...] the `initial-input` arg should be changed into `setup-function`
  (so we don't have to use the hideous `minibuffer-with-setup-function`
  hack) and using a string there should be deprecated (the rare places
  where inserting an initial string makes sense can use a setup-function
  instead).

  Also the prompt handling should be changed so that it automatically
  inserts the default into the prompt.  Doing that in a reliable and
  backward compatible way is not completely straightforward, tho, so maybe
  a simpler solution is to introduce a whole new function instead.

  Then a user-customization could also be used to choose between the
  current default (where the default is added to the prompt) or the other
  option of always inserting the default as initial value (pre-selected
  so it can be deleted with a quick DEL).


TIA,

Michael.


In GNU Emacs 29.0.50 (build 13, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, 
cairo version 1.16.0)
 of 2022-07-03 built on drachen
Repository revision: 0de355d8ee729ed6fec3ea379258d4a1f1d49021
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Debian GNU/Linux 11 (bullseye)


reply via email to

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