unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* read-from-minibuffer INITIAL-CONTENTS/DEFAULT-VALUE
@ 2019-07-13  0:05 Lars Ingebrigtsen
  2019-07-13  6:40 ` Drew Adams
  0 siblings, 1 reply; 2+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-13  0:05 UTC (permalink / raw)
  To: emacs-devel

Historically, Emacs has used to put text in INITIAL-CONTENTS for a bunch
of commands, but has, over the years, moved to putting the defaults in
DEFAULT-VALUE so that the user has to type `M-n' to get at them.

Overall, I think this is a good change...  but for a bunch of commands,
I really would like to have what's in DEFAULT-VALUE to be in
INITIAL-CONTENTS instead.  It's a lot more ergonomic (for me) for a
number of commands, and reading a bunch of bug reports over the years,
apparently for a number of users as well.

So it would be nice if there was a way to tweak this.

An obvious way would be to offer an option that would just put
DEFAULT-VALUE in INITIAL-CONTENTS always.  It'd be trivial to implement,
and I'm sure somebody would want this for all commands.

An if somebody wants this action for some commands only, they could add
:around advice to the commands in question.

Or we could allow tweaking this in the symbol plists.

Any opinions?

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




^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: read-from-minibuffer INITIAL-CONTENTS/DEFAULT-VALUE
  2019-07-13  0:05 read-from-minibuffer INITIAL-CONTENTS/DEFAULT-VALUE Lars Ingebrigtsen
@ 2019-07-13  6:40 ` Drew Adams
  0 siblings, 0 replies; 2+ messages in thread
From: Drew Adams @ 2019-07-13  6:40 UTC (permalink / raw)
  To: Lars Ingebrigtsen, emacs-devel

> Historically, Emacs has used to put text in INITIAL-CONTENTS for a bunch
> of commands, but has, over the years, moved to putting the defaults in
> DEFAULT-VALUE so that the user has to type `M-n' to get at them.
> 
> Overall, I think this is a good change...  but for a bunch of commands,
> I really would like to have what's in DEFAULT-VALUE to be in
> INITIAL-CONTENTS instead.  It's a lot more ergonomic (for me) for a
> number of commands, and reading a bunch of bug reports over the years,
> apparently for a number of users as well.
> 
> So it would be nice if there was a way to tweak this.
> 
> An obvious way would be to offer an option that would just put
> DEFAULT-VALUE in INITIAL-CONTENTS always.  It'd be trivial to implement,
> and I'm sure somebody would want this for all commands.
> 
> An if somebody wants this action for some commands only, they could add
> :around advice to the commands in question.
> 
> Or we could allow tweaking this in the symbol plists.
> 
> Any opinions?

I argued for this long ago, and since 2005 Icicles has
had such an option.  It controls the treatment of the
default value (or the first default value, if the default
value is a list): whether it is shown in the prompt,
substituted for an empty INITIAL-INPUT, and so on.

The default value of the option is `t', which gives
behavior like that of vanilla Emacs.

-------

icicle-default-value is a variable defined in `icicles-opt.el'.
Its value is insert-end

Original value was t

Documentation:
How to treat the default value when reading minibuffer input.
These are the possible option values:

  nil               - Do not insert default value or add it to prompt.
  t                 - Add default value to `completing-read' prompt.
                      Do not insert it.
  `insert-start'    - Insert default value and leave cursor at start.
  `insert-end'      - Insert default value and leave cursor at end.
  `preselect-start' - Insert and preselect default value;
                      leave cursor at beginning.
  `preselect-end'   - Insert and preselect default value;
                      leave cursor at end.

This option controls how a non-nil default-value argument to functions
such as `completing-read', `read-file-name', `read-from-minibuffer',
and `read-string' is handled.

When it is non-nil and the initial-input argument is nil or "", the
default value can be inserted into the minibuffer as the initial
input.

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

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

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

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

Adding the default value to the prompt corresponds to the more or less
conventional behavior of vanilla Emacs.  But vanilla Emacs does not do
this systematically for `completing-read' (or for any of the
input-reading functions).  Instead, it hard-codes default values into
prompts in the commands that call these functions.

By design, Icicles commands never add the default value to the prompt
themselves.  This includes Icicles versions of standard commands that
might do so.  Icicles instead tries to give you the choice, using
option `icicle-default-value'.

Function `completing-read' is the only input-reading function for
which Icicles adds the default value to the prompt (for option value
`t').  Other such functions, like `(icicle-)read-from-minibuffer' and
`(icicle-)read-file-name', treat empty input (just `RET') specially -
see their doc for details.

Inserting the default value in the minibuffer as the initial input has
the advantage of not requiring you to use `M-n' to retrieve it.  It
has the disadvantage of making you use `M-p' (or do something else) to
get rid of the default value in the minibuffer if you do not want to
use or edit it.

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

If the default value is inserted in the minibuffer, the value of this
option also determines whether or not the inserted text is
preselected, and where the cursor is left: at the beginning or end of
the text.

Preselection can be useful in Delete Selection mode or PC Selection
mode.  It makes it easy to replace the value by typing characters, or
delete it by hitting `C-d' or `DEL' (backspace).  However, all of the
initial input is lost if you type or hit `C-d' or `DEL'.  That is
inconvenient if you want to keep most of it and edit it only slightly.

My own preference for the option value is `insert-end', but the
default value is `t', which is closest to what vanilla Emacs does.

You can customize this variable.

-------

If you use `t' as the value of `icicle-default-value' then you
can use option `icicle-default-in-prompt-format-function' to
format the text that shows the (first) default value in the
prompt.  The option value is a function that accepts the
default value (a string) and returns a string that is prepended
to the first occurrence of ": " in the prompt.  This option has
no effect unless `icicle-default-value' is `t'.  The default
value is (lambda (default) (format " (%s)" default)).

-------

https://lists.gnu.org/archive/html/emacs-devel/2010-05/msg00462.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-13  6:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-13  0:05 read-from-minibuffer INITIAL-CONTENTS/DEFAULT-VALUE Lars Ingebrigtsen
2019-07-13  6:40 ` Drew Adams

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).