1

For example there is a function:

(defun testb (buf)
  (interactive "bTest: ")
  buf)

The question is how emacs internally reads a buffer for such interactive form?

Looks like it doesn't use read-buffer(or it calls the read-buffer as a C function(and doesn't look at symbol-function)?).

(flet ((read-buffer (&rest args) (current-buffer)))
  (call-interactively #'testb))

1 Answer 1

1

It uses Lisp function read-buffer. The interactive spec you show is equivalent to this one:

(interactive (list (read-buffer "Test: " nil t)))

See the Elisp manual, node Using Interactive.

I guess you're referring to the fact that you got this error, or similar, which you get when you try to use flet on a built-in function. And yes, read-buffer is a subr, i.e., implemented in C. (symbol-function 'read-buffer) returns the built-in function #<subr read-buffer>.

 Use ‘labels’, not ‘flet’, to rebind macro names
Sign up to request clarification or add additional context in comments.

4 Comments

> I guess you're referring to the fact that you got this error < Hmm... What error? I refer to the fact that rebinding the symbol-function of read-buffer have no effect on calling a function with interactive form that reads buffer.
When I evaluate the flet sexp you wrote using Emacs 25.2 (after loading library cl.el), I get that error, saying that you cannot use flet on a subr.
Ah, OK.) What about labels and letf? (strange, but I don't see any error messages. How did you evaluate the code?)
I used Emacs 25.2, put the code in *scratch*, loaded cl.el, and evaluated the code using C-x C-e. (The error msg says to use labels. But read-buffer is not really a macro.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.