* Line editor with dynamic prompt
@ 2014-10-28 16:15 Whitfield Diffie
2014-10-29 3:44 ` Michael Heerdegen
2014-10-29 7:46 ` Pascal J. Bourguignon
0 siblings, 2 replies; 3+ messages in thread
From: Whitfield Diffie @ 2014-10-28 16:15 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org
[-- Attachment #1: Type: text/plain, Size: 396 bytes --]
The attached program --- whose calling sequence is
(lineedit prompt-base starting-string position-in-string)
displays the length of the string and the position of point in the
string as part of the prompt; it changes as point moves or the string
is edited.
Does anyone know how to do this without having to write the line
editor by hand?
Whit
[-- Attachment #2: lineedit.el --]
[-- Type: application/octet-stream, Size: 3214 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Line editor with dynamic prompt
2014-10-28 16:15 Line editor with dynamic prompt Whitfield Diffie
@ 2014-10-29 3:44 ` Michael Heerdegen
2014-10-29 7:46 ` Pascal J. Bourguignon
1 sibling, 0 replies; 3+ messages in thread
From: Michael Heerdegen @ 2014-10-29 3:44 UTC (permalink / raw)
To: help-gnu-emacs
Whitfield Diffie <whitfield.diffie@gmail.com> writes:
> Does anyone know how to do this without having to write the line
> editor by hand?
What do you mean by "this"? The same thing but maybe more elegant,
doing this without the minibuffer involved, or only the message
feedback?
Michael.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Line editor with dynamic prompt
2014-10-28 16:15 Line editor with dynamic prompt Whitfield Diffie
2014-10-29 3:44 ` Michael Heerdegen
@ 2014-10-29 7:46 ` Pascal J. Bourguignon
1 sibling, 0 replies; 3+ messages in thread
From: Pascal J. Bourguignon @ 2014-10-29 7:46 UTC (permalink / raw)
To: help-gnu-emacs
Whitfield Diffie <whitfield.diffie@gmail.com> writes:
> The attached program --- whose calling sequence is
>
> (lineedit prompt-base starting-string position-in-string)
>
> displays the length of the string and the position of point in the
> string as part of the prompt; it changes as point moves or the string
> is edited.
>
> Does anyone know how to do this without having to write the line
> editor by hand?
Yes, somebody knows how to do it without having to write the line editor
by hand.
The question is why you need to input the string from the minibuffer.
This is an operation that is modal. Emacs is a mostly modless editor
and user interface framework.
The idea is to let the user choose what he is editing at any time.
When the user types some key chord that correspond to commands that
require more information, there may be some modal interaction and
editing occuring in the minibuffer. For example, C-x C-f will require
the user to edit the path of the file to be visited in the minibuffer.
For those small modal editing operations, it has not been deemed useful
to provide the length of input and cursor position.
If you let the user edit this string in a normal buffer, then you can
use the minor modes line-number-mode and column-number-mode to see the
current line and column displayed in the mode line. I suppose you could
write a similar minor mode that would also display the line length.
To process the input you would bind a command to a key, perhaps RET or
C-RET or something else, and this command could collect the string from
the buffer
Otherwise, you may perhaps do something. Those modal operations
(read-from-minibufffer, read-string, read-file-name etc) are implemented
in C, you wouldn't want to modify them (you'd have to recompile emacs).
You can use them with the minibuffer-with-setup-hook to configure the
minibuffer however you want. For example:
(defun minibuffer-meat ()
(interactive)
(local-set-key (kbd "!") (lambda () (interactive) (insert "!!!"))))
(minibuffer-with-setup-hook (function minibuffer-meat)
(read-string "TRY> ")) C-u C-e C-x Hello world! RET
returns:
"Hello world!!!"
You can also use directly minibuffer-setup-hook and
minibuffer-exit-hook.
In those hooks, you could set things up so that the minibuffer contents
(probably not the prompt) is edited to contain the position and length
of the string, or you could display it in the mode line.
With:
(defun my-minibuffer-postcommand ()
(save-excursion
(message "length = %d"
(- (progn (end-of-line) (point))
(progn (beginning-of-line) (point))))))
(defun my-minibuffer-setup-meat ()
(add-hook 'post-command-hook 'my-minibuffer-postcommand))
(defun my-minibuffer-exit-meat ()
(remove-hook 'post-command-hook 'my-minibuffer-postcommand))
(add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-meat)
(add-hook 'minibuffer-exit-hook 'my-minibuffer-exit-meat)
(minibuffer-with-setup-hook (function minibuffer-meat)
(read-string "TRY> ")) C-u C-x C-e hello SPC RET
will display in *Message* (and also in the minibuffer, oops):
length = 0
length = 1
length = 2
length = 3
length = 4
length = 5
length = 6
and will return:
"hello "
(remove-hook 'minibuffer-setup-hook 'my-minibuffer-setup-meat)
(remove-hook 'minibuffer-exit-hook 'my-minibuffer-exit-meat)
--
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-10-29 7:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-28 16:15 Line editor with dynamic prompt Whitfield Diffie
2014-10-29 3:44 ` Michael Heerdegen
2014-10-29 7:46 ` Pascal J. Bourguignon
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).