zze*_*man 3 emacs elisp function
我对 elisp 比较陌生,我不知道如何表达我的问题以在 Google 上找到答案
我想定义一个函数:
我尝试过的是
(defun test ()
(switch-to-buffer-other-window "*test*")
(erase-buffer)
(insert "hello from *test*")
(kill-this-buffer))
(test)
Run Code Online (Sandbox Code Playgroud)
但这并没有按照我想要的方式工作。
为了清楚起见,下面是我希望该函数执行的操作的图像分解:
初始设置
函数test被执行
焦点保留在初始缓冲区上,然后指定的缓冲区*test*获得焦点并q按下键盘
窗口配置现在没有*test*,焦点返回到初始缓冲区
我计划使用此函数将我的个人键绑定打印到缓冲区中*test*,这样我就不必打开我的.emacs来查看它们
您可能正在寻找宏with-help-window:
(defun test ()
(interactive)
(with-help-window "*test*"
(princ "hello from test")))
Run Code Online (Sandbox Code Playgroud)
如果您希望能够使用insert而不是princ,那么您可以使用:
(defun test ()
(interactive)
(with-help-window "*test*"
(with-current-buffer "*test*"
(princ "hello from test"))))
Run Code Online (Sandbox Code Playgroud)
(如果您使用的旧版 Emacs 没有,with-help-window那么您可以使用with-output-to-temp-buffer它。)
(这interactive只是为了让您可以轻松测试它。)
| 归档时间: |
|
| 查看次数: |
2127 次 |
| 最近记录: |