elisp:对当前文件的调用命令 [英] elisp: call command on current file
问题描述
p4 edit'currentfilename.ext'
global-set-key [\CE](funcall'revert-buffer 1 1 1))
;;我以上尝试使用非零
;;调用revert-buffer参数(现在忽略shell命令) - 获取init错误:
;; init文件中的错误:错误:缓冲区似乎没有与任何文件相关联
全新的到elisp。从 emacs手册,这里是revert-buffer的定义:
命令:revert-buffer&可选ignore-auto noconfirm保留模式
谢谢!
看到的是因为您已经指定了全局设置键错误,即函数调用。你想要的是:
(global-set-key(kbdCSe)'(lambda()(revert-buffer ttt)))
你有 funcall
实际上是评估你的.emacs加载的时间,这是什么导致的错误。
然后,为了得到整个事情,你可以创建一个命令,如:
(defun call-something-on-current-buffers-file()
在当前文件上运行命令并恢复缓冲区
(交互式)
(shell-command
(格式/home/tjackson/bin/dummy.sh%s
(shell-quote-argument(buffer-文件名))))
(revert-buffer ttt))
(全局设置密钥(kbdCSe)'call-something-on-current-buffers-file)
显然,自定义命令,如果需要,添加错误检查。
I want to set a key in emacs to perform a shell command on the file in the buffer, and revert the buffer without prompting. The shell command is: p4 edit 'currentfilename.ext'
(global-set-key [\C-E] (funcall 'revert-buffer 1 1 1))
;; my attempt above to call revert-buffer with a non-nil
;; argument (ignoring the shell command for now) -- get an init error:
;; Error in init file: error: "Buffer does not seem to be associated with any file"
Completely new to elisp. From the emacs manual, here is the definition of revert-buffer:
Command: revert-buffer &optional ignore-auto noconfirm preserve-modes
Thanks!
The actual error you're seeing is because you've specified the global-set-key incorrectly, namely the function call. What you want is:
(global-set-key (kbd "C-S-e") '(lambda () (revert-buffer t t t)))
You had the funcall
actually evaluating when your .emacs was loading, which is what caused the error.
Then, to get the whole thing, you can create a command like:
(defun call-something-on-current-buffers-file ()
"run a command on the current file and revert the buffer"
(interactive)
(shell-command
(format "/home/tjackson/bin/dummy.sh %s"
(shell-quote-argument (buffer-file-name))))
(revert-buffer t t t))
(global-set-key (kbd "C-S-e") 'call-something-on-current-buffers-file)
Obviously customize the command, and add error checking if you want.
这篇关于elisp:对当前文件的调用命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!