[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: read-from-minibuffer and friends.
From: |
Luc Teirlinck |
Subject: |
Re: read-from-minibuffer and friends. |
Date: |
Sun, 14 Dec 2003 18:23:18 -0600 (CST) |
Richard Stallman wrote:
I think ideally all these functions should handle INITIAL
in the same way. If it is easy to do that, please do it.
I would guess the best way is to move the handling of INITIAL
from Fread_from_minibuffer into read_minibuf.
Attached is a patch that does exactly that. `read_minibuf' only does
something different after the patch in cases where it threw an error
before, so there should be no danger of breaking existing code. If
the patch seems OK, I could install it as soon as Savannah starts
functioning again.
===File ~/minibuf.c-diff====================================
*** minibuf.c.~1.262.~ Wed Nov 5 22:05:19 2003
--- minibuf.c Sun Dec 14 10:39:56 2003
***************
*** 404,413 ****
return make_buffer_string (prompt_end, PT, 1);
}
! /* Read from the minibuffer using keymap MAP, initial contents INITIAL
! (a string), putting point minus BACKUP_N bytes from the end of INITIAL,
prompting with PROMPT (a string), using history list HISTVAR
! with initial position HISTPOS. (BACKUP_N should be <= 0.)
Normally return the result as a string (the text that was read),
but if EXPFLAG is nonzero, read it and return the object read.
--- 404,418 ----
return make_buffer_string (prompt_end, PT, 1);
}
! /* Read from the minibuffer using keymap MAP and initial contents INITIAL,
! putting point minus BACKUP_N bytes from the end of INITIAL,
prompting with PROMPT (a string), using history list HISTVAR
! with initial position HISTPOS. INITIAL should be a string or a
! cons of a string and an integer. BACKUP_N should be <= 0, or
! Qnil, which is equivalent to 0. If INITIAL is a cons, BACKUP_N is
! ignored and replaced with an integer that puts point N characters
! from the beginning of INITIAL, where N is the CDR of INITIAL, or at
! the beginning of INITIAL if N <= 0.
Normally return the result as a string (the text that was read),
but if EXPFLAG is nonzero, read it and return the object read.
***************
*** 419,425 ****
If ALLOW_PROPS is nonzero, we do not throw away text properties.
! if INHERIT_INPUT_METHOD is nonzeor, the minibuffer inherit the
current input method. */
static Lisp_Object
--- 424,430 ----
If ALLOW_PROPS is nonzero, we do not throw away text properties.
! if INHERIT_INPUT_METHOD is nonzero, the minibuffer inherits the
current input method. */
static Lisp_Object
***************
*** 441,446 ****
--- 446,452 ----
Lisp_Object mini_frame, ambient_dir, minibuffer, input_method;
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
Lisp_Object enable_multibyte;
+ int pos = INTEGERP (backup_n) ? XINT (backup_n) : 0;
/* String to add to the history. */
Lisp_Object histstring;
***************
*** 456,461 ****
--- 462,488 ----
cancel_hourglass ();
#endif
+ if (!NILP (initial))
+ {
+ if (CONSP (initial))
+ {
+ backup_n = Fcdr (initial);
+ initial = Fcar (initial);
+ CHECK_STRING (initial);
+ if (!NILP (backup_n))
+ {
+ CHECK_NUMBER (backup_n);
+ /* Convert to distance from end of input. */
+ if (XINT (backup_n) < 1)
+ /* A number too small means the beginning of the string. */
+ pos = - SCHARS (initial);
+ else
+ pos = XINT (backup_n) - 1 - SCHARS (initial);
+ }
+ }
+ else
+ CHECK_STRING (initial);
+ }
val = Qnil;
ambient_dir = current_buffer->directory;
input_method = Qnil;
***************
*** 482,488 ****
if (noninteractive)
{
! val = read_minibuf_noninteractive (map, initial, prompt, backup_n,
expflag, histvar, histpos, defalt,
allow_props, inherit_input_method);
UNGCPRO;
--- 509,516 ----
if (noninteractive)
{
! val = read_minibuf_noninteractive (map, initial, prompt,
! make_number (pos),
expflag, histvar, histpos, defalt,
allow_props, inherit_input_method);
UNGCPRO;
***************
*** 633,640 ****
if (!NILP (initial))
{
Finsert (1, &initial);
! if (INTEGERP (backup_n))
! Fforward_char (backup_n);
}
clear_message (1, 1);
--- 661,667 ----
if (!NILP (initial))
{
Finsert (1, &initial);
! Fforward_char (make_number (pos));
}
clear_message (1, 1);
***************
*** 884,891 ****
which INITIAL-CONTENTS corresponds to).
Positions are counted starting from 1 at the beginning of the list.
Sixth arg DEFAULT-VALUE is the default value. If non-nil, it is available
! for history commands; but `read-from-minibuffer' does NOT return
DEFAULT-VALUE
! if the user enters empty input! It returns the empty string.
Seventh arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits
the current input method and the setting of `enable-multibyte-characters'.
If the variable `minibuffer-allow-text-properties' is non-nil,
--- 911,919 ----
which INITIAL-CONTENTS corresponds to).
Positions are counted starting from 1 at the beginning of the list.
Sixth arg DEFAULT-VALUE is the default value. If non-nil, it is available
! for history commands; but, unless READ is non-nil, `read-from-minibuffer'
! does NOT return DEFAULT-VALUE if the user enters empty input! It returns
! the empty string.
Seventh arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits
the current input method and the setting of `enable-multibyte-characters'.
If the variable `minibuffer-allow-text-properties' is non-nil,
***************
*** 895,927 ****
Lisp_Object prompt, initial_contents, keymap, read, hist, default_value;
Lisp_Object inherit_input_method;
{
- int pos = 0;
Lisp_Object histvar, histpos, position, val;
struct gcpro gcpro1;
- position = Qnil;
-
CHECK_STRING (prompt);
- if (!NILP (initial_contents))
- {
- if (CONSP (initial_contents))
- {
- position = Fcdr (initial_contents);
- initial_contents = Fcar (initial_contents);
- }
- CHECK_STRING (initial_contents);
- if (!NILP (position))
- {
- CHECK_NUMBER (position);
- /* Convert to distance from end of input. */
- if (XINT (position) < 1)
- /* A number too small means the beginning of the string. */
- pos = - SCHARS (initial_contents);
- else
- pos = XINT (position) - 1 - SCHARS (initial_contents);
- }
- }
-
if (NILP (keymap))
keymap = Vminibuffer_local_map;
else
--- 923,932 ----
***************
*** 944,950 ****
GCPRO1 (default_value);
val = read_minibuf (keymap, initial_contents, prompt,
! make_number (pos), !NILP (read),
histvar, histpos, default_value,
minibuffer_allow_text_properties,
!NILP (inherit_input_method));
--- 949,955 ----
GCPRO1 (default_value);
val = read_minibuf (keymap, initial_contents, prompt,
! Qnil, !NILP (read),
histvar, histpos, default_value,
minibuffer_allow_text_properties,
!NILP (inherit_input_method));
***************
*** 960,967 ****
Lisp_Object prompt, initial_contents;
{
CHECK_STRING (prompt);
- if (!NILP (initial_contents))
- CHECK_STRING (initial_contents);
return read_minibuf (Vminibuffer_local_map, initial_contents,
prompt, Qnil, 1, Qminibuffer_history,
make_number (0), Qnil, 0, 0);
--- 965,970 ----
***************
*** 1012,1020 ****
Lisp_Object prompt, initial, inherit_input_method;
{
CHECK_STRING (prompt);
- if (! NILP (initial))
- CHECK_STRING (initial);
-
return read_minibuf (Vminibuffer_local_ns_map, initial, prompt, Qnil,
0, Qminibuffer_history, make_number (0), Qnil, 0,
!NILP (inherit_input_method));
--- 1015,1020 ----
============================================================