我想在emacs中设置一个键,对缓冲区中的文件执行shell命令,并在不提示的情况下恢复缓冲区.shell命令是: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"
Run Code Online (Sandbox Code Playgroud)
完全是elisp新手.从emacs手册中,这里是revert-buffer的定义:
Command: revert-buffer &optional ignore-auto noconfirm preserve-modes
Run Code Online (Sandbox Code Playgroud)
谢谢!
您看到的实际错误是因为您错误地指定了global-set-key,即函数调用.你想要的是:
(global-set-key (kbd "C-S-e") '(lambda () (revert-buffer t t t)))
Run Code Online (Sandbox Code Playgroud)
您funcall实际上在评估.emacs何时加载时,这是导致错误的原因.
然后,为了获得整个事情,您可以创建一个命令,如:
(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)
Run Code Online (Sandbox Code Playgroud)
显然,自定义命令,并根据需要添加错误检查.