help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: DEFUN in Emacs's C-code. Can I give "prompt" an arbitrary lisp expre


From: Kevin Rodgers
Subject: Re: DEFUN in Emacs's C-code. Can I give "prompt" an arbitrary lisp expression?
Date: Thu, 14 Oct 2004 16:18:24 -0600
User-agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]