* DEFUN in Emacs's C-code. Can I give "prompt" an arbitrary lisp expression?
@ 2004-10-14 20:17 Alan Mackenzie
2004-10-14 20:46 ` Stefan Monnier
2004-10-14 22:18 ` Kevin Rodgers
0 siblings, 2 replies; 3+ messages in thread
From: Alan Mackenzie @ 2004-10-14 20:17 UTC (permalink / raw)
[N.B. "prompt" in an Emacs C-code DEFUN is what would be created by
`(interactive ...)' in a command written in lisp.]
Right now, I'm unhappy with the command `rename-buffer', because M-x
rename-buffer prompts with an empty string. I'd far rather it prompted
with the current name of the buffer, allowing me to edit the name, rather
than requiring me to enter the entire name from scratch.
Why do I want this? Because I often want to change names like
"longbuffername.el<2>" to "longbuffername.el", and that much typing is
tedious ;-). Besides, the analogous `find-alternate-file' prompts with
the name of the current file.
rename-buffer's interactive form is "sRename buffer (to new name): \nP".
I'd like to change it to this lisp form:
(let ((n (buffer-name (current-buffer))))
(read-string "New buffer name: " n nil n t))
[OK, I'd need to think about the P on the end, but that's inessential for
now]. Can I do this directly in emacs/src/buffer.c, somehow? I tried
this by just inserting the lisp form (not within string quotes), but got
only compiler errors.
Also, there appears to be no command/function `set-interactive-form' to
match `interactive-form'. Pity. ;-)
Now presumably I could do what I want by advising the function, somehow.
But it would be nice to hack the interactive form directly in the C
source.
Thanks in advance for any help.
--
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: DEFUN in Emacs's C-code. Can I give "prompt" an arbitrary lisp expression?
2004-10-14 20:17 DEFUN in Emacs's C-code. Can I give "prompt" an arbitrary lisp expression? Alan Mackenzie
@ 2004-10-14 20:46 ` Stefan Monnier
2004-10-14 22:18 ` Kevin Rodgers
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2004-10-14 20:46 UTC (permalink / raw)
> Why do I want this? Because I often want to change names like
> "longbuffername.el<2>" to "longbuffername.el", and that much typing is
Try uniquify.
> [OK, I'd need to think about the P on the end, but that's inessential for
> now]. Can I do this directly in emacs/src/buffer.c, somehow?
No.
I think that interactive built-in functions are generally a bad idea for
this reason.
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: DEFUN in Emacs's C-code. Can I give "prompt" an arbitrary lisp expression?
2004-10-14 20:17 DEFUN in Emacs's C-code. Can I give "prompt" an arbitrary lisp expression? Alan Mackenzie
2004-10-14 20:46 ` Stefan Monnier
@ 2004-10-14 22:18 ` Kevin Rodgers
1 sibling, 0 replies; 3+ messages in thread
From: Kevin Rodgers @ 2004-10-14 22:18 UTC (permalink / raw)
Alan Mackenzie wrote:
> Right now, I'm unhappy with the command `rename-buffer', because M-x
> rename-buffer prompts with an empty string. I'd far rather it prompted
> with the current name of the buffer, allowing me to edit the name, rather
> than requiring me to enter the entire name from scratch.
>
> Why do I want this? Because I often want to change names like
> "longbuffername.el<2>" to "longbuffername.el", and that much typing is
> tedious ;-). Besides, the analogous `find-alternate-file' prompts with
> the name of the current file.
In this situation, you can just use find-alternate-file: C-x C-v RET
> rename-buffer's interactive form is "sRename buffer (to new name): \nP".
> I'd like to change it to this lisp form:
>
> (let ((n (buffer-name (current-buffer))))
> (read-string "New buffer name: " n nil n t))
Is it really necessary to provide both INITIAL-INPUT and DEFAULT
arguments to read-string? And INHERIT-INPUT-METHOD?
> [OK, I'd need to think about the P on the end, but that's inessential for
> now].
It maps to current-prefix-arg.
> Can I do this directly in emacs/src/buffer.c, somehow? I tried
> this by just inserting the lisp form (not within string quotes), but got
> only compiler errors.
>
> Also, there appears to be no command/function `set-interactive-form' to
> match `interactive-form'. Pity. ;-)
Agreed.
> Now presumably I could do what I want by advising the function, somehow.
Yes:
(defun rename-buffer (before interactive-default-newname activate)
"Provide a default when prompting for NEWNAME."
(interactive (let ((buffer-name (buffer-name (current-buffer))))
(read-string "New buffer name: " buffer-name)
(list buffer-name current-prefix-arg))))
> But it would be nice to hack the interactive form directly in the C
> source.
I don't understand what is nice about that approach; you'd have to
recompile Emacs.
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-10-14 22:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-14 20:17 DEFUN in Emacs's C-code. Can I give "prompt" an arbitrary lisp expression? Alan Mackenzie
2004-10-14 20:46 ` Stefan Monnier
2004-10-14 22:18 ` Kevin Rodgers
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).