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

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

RE: [External] : Re: completing-read depricated initial-input


From: Drew Adams
Subject: RE: [External] : Re: completing-read depricated initial-input
Date: Fri, 24 Jun 2022 00:10:31 +0000

> I haven't really followed that thread, but IMO 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).

No comment on all of that.  At least not until
it becomes something real to worry about. ;-)

> 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).

Possible insertion of the default value, and its
possible addition to the prompt, should be handled
more generally than just for completion.

Ideally the choice should belong mainly to users,
and it should apply to pretty much all minibuffer
reading functions that allow for a default value.
_____

FWIW, Icicle mode handles this with user option
`icicle-default-value'.

When the value's non-`nil' and arg INITIAL-INPUT
of minibuffer-reading functions is `nil' or "",
the DEFAULT-VALUE argument can be inserted into
the minibuffer as initial input.

For `completing-read', `read-file-name'[*], and
`read-string', if the option value is `t' then the
default value is added to the prompt as a hint.

Adding the default value to the prompt corresponds
to a more or less conventional behavior of vanilla
Emacs.  But Emacs doesn't do that systematically.
Instead, it hard-codes default values into prompts
here and there.  It's up to the particular command
to decide about this - ad hoc.

By design, individual Icicles commands never add
the default value to a prompt themselves.  Instead,
option `icicle-default-value' controls the behavior.

Non-`nil' and non-`t' inserts the default value
into the minibuffer as the initial value.

`nil' neither inserts the default value nor adds
it to the prompt.

(If the value is `t' or `nil', you can always use
`M-n' to insert the default value manually.) 

If you often want to use or edit the default value,
then consider setting `icicle-default-value' to
non-`nil' and non-`t'.  If you rarely do so, then
consider using `nil' or `t'.

A non-`nil', non-`t' value also controls whether
or not the inserted default value is preselected
(as the active region), and where to leave the
cursor: at its beginning or end.

Preselecting the value can be useful in Delete
Selection mode, because it makes it easy to
replace that value by typing characters, or delete
it by hitting `DEL' or `C-d'.  (However, all of
the initial input is deleted with `C-d' or `DEL',
which is inconvenient if you just want to edit it
slightly.)

Summary of values:

 Don't insert default into minibuffer:

   nil  - Don't add to prompt.
   t    - Add to prompt if `completing-read',
          `read-file-name', or `read-string'.

 Do insert default into minibuffer:

   `insert-start'    - Leave cursor at start.
   `insert-end'      - Leave cursor at end.
   `preselect-start' - Preselect and put cursor
                       at beginning.
   `preselect-end'   - Preselect and put cursor
                       at end.

`t' is the default.  (I use `insert-end'.)
_____

When Icicles automatically puts the default value
into the prompt, as a hint, it also replaces it
there if put there already by some command, so
the hint format will be systematically the same.

Option `icicle-default-in-prompt-format-function'
defines the format to use.  By default it's this:
 (lambda (default) (format " (%s)" default))

Function `icicle-handle-default-for-prompt' does
the work:
__

 (icicle-handle-default-for-prompt PROMPT DEFAULT INCLUDE)

 Return PROMPT, possibly changed to format or remove the DEFAULT value.
 Argument INCLUDE:
  * nil means do not include DEFAULT in prompt.  Remove it if there.
  * non-nil means include DEFAULT, formatted according to
    `icicle-default-in-prompt-format-function'.

 In the existing PROMPT before modification, recognizes inclusion of
 a default value according to these possible patterns:

  `minibuffer-default-in-prompt-regexps'
  "(default ___):"
  "(default is ___):"
  " [___] "
__

Icicles just reuses vanilla Emacs variable
`minibuffer-default-in-prompt-regexps', which is
defined for `minibuffer-electric-default-mode'.

  A list of regexps matching the parts of minibuffer
  prompts showing defaults.
  When 'minibuffer-electric-default-mode' is active,
  these regexps are used to identify the portions of
  prompts to elide.

(`minibuffer-electric-default-mode'e tries to show
a default value in a prompt only when hitting RET
yields that value.  If you edit the minibuffer text
so it's no longer the default value, the default's
removed from the prompt.)
____________________


[*]: However, for `read-file-name', if option
`insert-default-directory' is non-`nil' then, to
avoid duplication:

* If the default value is the same as the value of
  `default-directory' then it's not added to the
  prompt.

* If the default value is added to the prompt then
  it's first made relative to `default-directory'.



reply via email to

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