I need to be able to parse a string like the following:
M-: (forward-word 4) RET
and execute it from elisp.
For that purpose I'm trying to use execute-kbd-macro
and edmacro-parse-keys
but I'm a little bit surprised as these functions won't be executed in the current buffer (with current buffer, i.e. using with-current-buffer
), please take a look:
(defun execute-macro-in-the-current-buffer ()
(interactive)
(with-current-buffer (get-buffer-create "*test-buffer*")
(erase-buffer)
(insert "Lorem Ipsum is simply dummy text of the printing and typesetting industry.")
(goto-char 0)
(execute-kbd-macro
(edmacro-parse-keys "M->") t)))
When I execute it then my point moves to the end of the current buffer but not of the buffer *test-buffer*
as I was expected. But why? What is wrong?
May be I need another way to parse a string and execute it? Which one?
"M-: (forward-word 4) RET"
? Out of curiosity, why? What are you really trying to do?M-x replace-string RET foo RET bar RET
,C-c g t C-n C-n C-l book RET
,C-SPC M-> M-x delete-region RET
etc. I.e. any possible command. I'm currently experimenting with a new package. Purpose of it is the integration testing for Emacs packages. Now I'm parsing an instruction and would like to apply it to another buffer but that doesn't work for me.M-x
(execute-extended-command
) parsesM-x
input. The code forM-:
(eval-expression
) parsesM-:
input. They parse different syntax. You need to specify the syntax of the various strings you want to parse, otherwise this question is too broad (or unclear), IMO, and risks being closed. "I need to be able to parse* a string like the following" means nothing, unless you specify what "like" means here.