Elisp: command to call the current file

I want to set the key in emacs to execute a shell command in a file in the buffer and return the buffer without a request. Shell command: p4 edit 'currentfilename.ext'

 (global-set-key [\CE] (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 revert-buffer definition:

 Command: revert-buffer &optional ignore-auto noconfirm preserve-modes 

Thanks!

+6
emacs elisp
source share
2 answers

The actual error you see is that you incorrectly specified a global key set, namely a function call. Do you want to:

 (global-set-key (kbd "CSe") '(lambda () (revert-buffer ttt))) 

In fact, you appreciated funcall when your .emacs loaded, which caused the error.

Then, to get all this, you can create a command, for example:

 (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 ttt)) (global-set-key (kbd "CSe") 'call-something-on-current-buffers-file) 

Obviously configure the command and add error checking if you want.

+5
source share

Perhaps the use of a secondary mode - "automatic return" - is an option. Just turn it on in the current buffer:

 Mx "auto-revert-mode" 

and always make sure that the buffer is saved before executing the external command.

0
source share

All Articles