[I apologize for the poor title, but couldn't come up with a better one.]
bin chen asked on Google+:
How to input relative path of (buffer-file-name) in minibuffer after
M-!
in #emacs?
I thought if the buffer-file-name
is saved in a register, it should be accessible by invoking insert-register
(C-x r i) while at the shell-command
prompt.
(defun save-buffer-file-name-in-register ()
(set-register ?F (buffer-file-name))
(set-register ?D (file-name-directory buffer-file-name)))
(defadvice shell-command (before save-buffer-file-name)
"Save buffer-file-name to register F before running shell-command"
(save-buffer-file-name-in-register))
(ad-activate 'shell-command)
When I invoke shell-command
(M-!) followed by insert-register
(C-x r i), I get the error message: Register does not contain any text
.
But when I run list-registers
I do see that the registers F
and D
are set with the appropriate values. If I run the shell-command
again, I can access the values from the registers previously saved.
Is it possible that the registers are being set too late for the first time? How can I fix the code to do what I want?
Edit: Changed around
to before
(Thanks to @phils)