Closed ssskkkky closed 4 years ago
Can you give me an example that doesn't use an org agenda buffer? Unless you think the org agenda buffer is relevant?
Also, can you describe what happens when you run the code, and how it is different from what you expected to happen?
(defun test()
(interactive)
(let ((file "~/testt"))
(setq test-buffer (if (file-exists-p file)
(get-file-buffer file)
(error "No such file %s" file)))
(with-current-buffer test-buffer
(with-simulated-input
"a"
(test2)))))
(defun test2()
(and (read-char) (insert "test")))
When I call function test in a file buffer named abc or whatever, rather than insert the string "test" to the ~/testt file buffer which was expected , it insert the words in the current buffer.
Ok, thank you. I'll take a look at this when I have the time.
For my own reference, here is a more self-contained test case:
(with-temp-buffer
(list
;; Returns the temp buffer
(current-buffer)
(progn
(with-simulated-input
"a"
(read-char))
;; Returns the buffer that was current when evaluation began
(current-buffer))))
Ok, it looks like this is a bug (or perhaps an intended behavior?) in execute-kbd-macro
:
(with-temp-buffer
(list
;; Returns the temp buffer
(current-buffer)
(progn
(execute-kbd-macro "hello")
;; Returns the buffer that was current when evaluation began
(current-buffer))))
don't know perhaps.
I've fixed it with a workaround that sets the buffer correctly before executing BODY. Please let me know if the latest master works for you.
And here's the root cause: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=37396#8
It works. Thanks.
It seems like that it didn't change the buffer when it's in a (with-current buffer) expression try this: