G'day! it's my "learn some more Elisp" day.
I'm trying to make a shortcut that opens my main org file. I've made it this far
(global-set-key (kbd "C-c h") 'switch-to-most-recent-org-file)
(defun switch-to-most-recent-org-file ()
(interactive)
(message "hi"))
Instead of (message "hi")
, I want emacs to switch to the .org file
in the Buffer List. Sometimes there will be multiple .org files in
the Buffer List, in that case go for the one at the top.
(message "hi")
? If the answer is "I tried X, Y, and Z, but I'm stuck," then say so so people can help. If the answer is "nothing," however, please do some basic background research before posting a question. Start with the elisp manual nodes on Switching to a Buffer in a Window and The Buffer List. I found these nodes via google searches.buffer-list
is not being processed withmapc
in the right order, then you can reverse the order with(nreverse (buffer-list))
-- If you want the second to the most recent assuming that you are already in anorg-mode
buffer, then you'll need to tweak the example:(let (found) (catch 'done (mapc (lambda (x) (when (with-current-buffer x (eq major-mode 'org-mode)) (switch-to-buffer x) (setq found t) (throw 'done nil))) (buffer-list)) (unless found (message "not found"))))
I'm not writing an answer, because I don't have much free time.