I want to access any current file quickly. Therefore I want to build a function that put a file the register.
I've started with this function:
(defun tmp-register ()
""" put the current buffer in the temporary register """
(interactive)
(set-register , ?q (file . buffer-file-name))
)
but it fails as expected as I need a string instead of buffer-file-name
. Do you see a way around this?
Update
I have tweaked some code from Sacha Chua here. I've come up with this. I don't understand it entirely yet and it can probably be improved. Do you have something else in mind?
(defun tmp-register ()
""" put the current buffer in the temporary register """
(interactive)
(my/defshortcut ?q buffer-file-name)
)
(defvar my/refile-map (make-sparse-keymap))
(defmacro my/defshortcut (key file)
`(progn
(set-register ,key (cons 'file ,file))
(define-key my/refile-map
(char-to-string ,key)
(lambda (prefix)
(interactive "p")
(let ((org-refile-targets '(((,file) :maxlevel . 6)))
(current-prefix-arg (or current-prefix-arg '(4))))
(call-interactively 'org-refile))))))
(global-set-key (kbd "<f12>") 'tmp-register)
"""
is not a string delimiter in elisp.(set-register , ?q (file . buffer-file-name))
is wrong: (1) it uses a comma outside of backquoting and (2) it provides 3 args, not 2, toset-register
.