* How to prompt for string?
@ 2006-02-17 4:58 jacksneckhurts
2006-02-17 5:50 ` Pascal Bourguignon
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: jacksneckhurts @ 2006-02-17 4:58 UTC (permalink / raw)
I'm trying to teach myself emacs Lisp, but can't figure out how to
prompt for a string. I found the "read-key-sequence-vector" function,
but that only takes in one character. Does anyone know how to prompt
for a string? Thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to prompt for string?
2006-02-17 4:58 How to prompt for string? jacksneckhurts
@ 2006-02-17 5:50 ` Pascal Bourguignon
2006-02-17 7:00 ` jacksneckhurts
2006-02-17 16:18 ` Dirk-Jan.Binnema
2006-02-17 16:44 ` Kevin Rodgers
2006-02-17 19:58 ` Peter Dyballa
2 siblings, 2 replies; 8+ messages in thread
From: Pascal Bourguignon @ 2006-02-17 5:50 UTC (permalink / raw)
jacksneckhurts@yahoo.com writes:
> I'm trying to teach myself emacs Lisp, but can't figure out how to
> prompt for a string. I found the "read-key-sequence-vector" function,
> but that only takes in one character. Does anyone know how to prompt
> for a string? Thanks.
I don't know. Or do you think I'm a super genius?
Let's see:
M-x apropos RET read RET
C-v
C-s read-string RET C-s C-s C-s
Yep, seems like this could be useful:
read-string
Function: Read a string from the minibuffer, prompting with string PROMPT.
C-h f read-string RET
Yep, sounds promizing.
--
__Pascal Bourguignon__ http://www.informatimago.com/
"You cannot really appreciate Dilbert unless you read it in the
original Klingon"
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to prompt for string?
2006-02-17 5:50 ` Pascal Bourguignon
@ 2006-02-17 7:00 ` jacksneckhurts
2006-02-17 18:18 ` Kevin Rodgers
2006-02-17 16:18 ` Dirk-Jan.Binnema
1 sibling, 1 reply; 8+ messages in thread
From: jacksneckhurts @ 2006-02-17 7:00 UTC (permalink / raw)
You are a genius! Now I can conquor the world.
I've been beating my head against my computer trying to find that
function. Thanks!
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: How to prompt for string?
2006-02-17 5:50 ` Pascal Bourguignon
2006-02-17 7:00 ` jacksneckhurts
@ 2006-02-17 16:18 ` Dirk-Jan.Binnema
1 sibling, 0 replies; 8+ messages in thread
From: Dirk-Jan.Binnema @ 2006-02-17 16:18 UTC (permalink / raw)
You can use 'interactive', which uses to some 'magic' chars to specify
what to prompt for.
(interactive "r\nsSummary:")
The 'r' will get you the region (begin and and), and 's' will get you
a string. The function with the interactive when then be called as
if it were called with these parameters.
My Example:
;; remove parts of old email, and replace with [snip: ... ]
(defun snip-mail (r-begin r-end summary)
(interactive "r\nsSummary:")
(let ((line-num (count-lines r-begin r-end)))
(delete-region r-begin r-end)
(insert (format "[snip%s (%d line%s)]\n"
(if (= 0 (length summary)) "" (concat ": " summary))
line-num
(if (= line-num 1) "" "s")))))
Best wishes,
Dirk.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to prompt for string?
2006-02-17 4:58 How to prompt for string? jacksneckhurts
2006-02-17 5:50 ` Pascal Bourguignon
@ 2006-02-17 16:44 ` Kevin Rodgers
2006-02-17 19:58 ` Peter Dyballa
2 siblings, 0 replies; 8+ messages in thread
From: Kevin Rodgers @ 2006-02-17 16:44 UTC (permalink / raw)
jacksneckhurts@yahoo.com wrote:
> I'm trying to teach myself emacs Lisp, but can't figure out how to
> prompt for a string. I found the "read-key-sequence-vector" function,
> but that only takes in one character. Does anyone know how to prompt
> for a string? Thanks.
,----[ C-h f read-string RET ]
| read-string is a built-in function.
| (read-string PROMPT &optional INITIAL-INPUT HISTORY DEFAULT-VALUE
INHERIT-INPUT-METHOD)
|
| Read a string from the minibuffer, prompting with string PROMPT.
| If non-nil, second arg INITIAL-INPUT is a string to insert before reading.
| The third arg HISTORY, if non-nil, specifies a history list
| and optionally the initial position in the list.
| See `read-from-minibuffer' for details of HISTORY argument.
| Fourth arg DEFAULT-VALUE is the default value. If non-nil, it is used
| for history commands, and as the value to return if the user enters
| the empty string.
| Fifth arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits
| the current input method and the setting of enable-multibyte-characters.
`----
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to prompt for string?
2006-02-17 7:00 ` jacksneckhurts
@ 2006-02-17 18:18 ` Kevin Rodgers
0 siblings, 0 replies; 8+ messages in thread
From: Kevin Rodgers @ 2006-02-17 18:18 UTC (permalink / raw)
jacksneckhurts@yahoo.com wrote:
> You are a genius! Now I can conquor the world.
Calm down, friend.
> I've been beating my head against my computer trying to find that
> function. Thanks!
In the Emacs Lisp manual, `i prompt' takes you directly to the Using
Interactive node, which you should read. That node has this example:
(interactive
(list (region-beginning) (region-end)
(read-string "Foo: " nil 'my-history)))
The Using Interactive node ought to have a link to the Minibuffers
node, which I'll report as a bug. In the meantime, read that section
as well -- I think you'll be impressed.
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to prompt for string?
2006-02-17 4:58 How to prompt for string? jacksneckhurts
2006-02-17 5:50 ` Pascal Bourguignon
2006-02-17 16:44 ` Kevin Rodgers
@ 2006-02-17 19:58 ` Peter Dyballa
2006-02-18 7:24 ` Drew Adams
2 siblings, 1 reply; 8+ messages in thread
From: Peter Dyballa @ 2006-02-17 19:58 UTC (permalink / raw)
Cc: help-gnu-emacs
Am 17.02.2006 um 05:58 schrieb jacksneckhurts@yahoo.com:
> I'm trying to teach myself emacs Lisp, but can't figure out how to
> prompt for a string. I found the "read-key-sequence-vector" function,
> but that only takes in one character. Does anyone know how to prompt
> for a string?
Yes, there seem to be a few! I remember that calendar prompts me a
few times when I want to go to some date. And there are these
functions to change an encoding, C-x RET f for example. Let's see how
they do it!
C-h k C-x RET f opens a *Help* buffer with a hyper link to mule.el. I
follow it. Oufff, it opens in another window! I do not need to
remember the function's name! Oh -- the cursor is already positioned
at the function's start ... shall I manage to remember this
behaviour? But, what is a life without constant sorrows?! I'm glad
that I've chosen a bad example: no obvious output or input, but ...
it's prompting me with "Coding system for saving file (default nil):
" -- let's search for this sentence! Ah, there it is -- the first
line of code of this function set-buffer-file-coding-system, very
strange:
(interactive "zCoding system for saving file (default nil): \nP")
OK, that's one guess. Let's see how a veteran does it in Calendar!
(interactive (list (calendar-read-date))) -- a function in
calendar.el. Hey, GNU Emacs even takes me to my private copy with
German text! Here two functions, calendar-read and completing-read
are doing the job of prompting, while taking the first argument as
the prompt's text. The first one uses (read-minibuffer prompt initial-
contents), the latter uses a function in `C source code'. (completing-
read PROMPT TABLE &optional PREDICATE REQUIRE-MATCH INITIAL-INPUT
HIST DEF INHERIT-INPUT-METHOD). Aha.
Two "applications" and three ways to prompt for an input! That's
efficiency.
--
Greetings
Pete
Got Mole problems?
Call Avogadro 6.02 x 10^23
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: How to prompt for string?
2006-02-17 19:58 ` Peter Dyballa
@ 2006-02-18 7:24 ` Drew Adams
0 siblings, 0 replies; 8+ messages in thread
From: Drew Adams @ 2006-02-18 7:24 UTC (permalink / raw)
Others have pointed you to the doc and various functions that prompt for and
read a string. To find lots of functions that read input (including
strings), use `M-x apropos string'.
Think too about the nature of the string - is it arbitrary? There are
functions to read strings that represent various objects, such as numbers.
An important consideration is whether the string be is restricted to a given
candidate set of strings. Or, can it be arbitrary yet there exists a useful
set of candidate "suggestions"?
If there is some notion of a set of candidate strings, even if they are only
suggestions and other strings are also accepted, then consider using
function `completing-read', which prompts and reads a string allowing users
to complete partial input against matching candidates (using TAB).
For strings that represent file and directory names, a similar,
read-a-string-with-completion function is `read-file-name'.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2006-02-18 7:24 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-17 4:58 How to prompt for string? jacksneckhurts
2006-02-17 5:50 ` Pascal Bourguignon
2006-02-17 7:00 ` jacksneckhurts
2006-02-17 18:18 ` Kevin Rodgers
2006-02-17 16:18 ` Dirk-Jan.Binnema
2006-02-17 16:44 ` Kevin Rodgers
2006-02-17 19:58 ` Peter Dyballa
2006-02-18 7:24 ` Drew Adams
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.