elisp: call command on current file

房东的猫 提交于 2019-12-04 03:19:36

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.

Maybe using the minor mode "auto-revert-mode" is an option. Just enable it on the current buffer:

M-x "auto-revert-mode"

and always ensure the buffer is saved, before executing an external command.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!