I want to write a custom function to do bellowing work:
(defun my-org-agenda-switch-or-build ()
"Switch to *Org Agenda* buffer, if not available, then build it."
(interactive)
(if (get-buffer "*Org Agenda*")
(switch-to-buffer "*Org Agenda*")
(command-execute 'org-agenda-list)
(bury-buffer)
(switch-to-buffer "*Org Agenda*")
))
;;; start Org Agenda at Emacs startup, and put in end of buffer list:
;; (add-hook 'emacs-startup-hook 'my-eshell-start-or-switch)
(define-key my-org-prefix-map (kbd "o") 'my-org-agenda-switch-or-build)
And here is my demo code, but it does not work. Do you have better idea about this?
(defun my-func/open-and-switch-to-buffer (the-command the-buffer-name &optional whether-switch-to-buffer)
"Open a `COMMAND', and switch to that `BUFFER' depend on `OPTION'."
;; (interactive)
(if (get-buffer the-buffer-name)
(progn
(,the-command)
(bury-buffer))
(let (whether-switch-to-buffer (and t whether-switch-to-buffer))
(and whether-switch-to-buffer (switch-to-buffer the-buffer-name)))))
(define-key my-org-prefix-map (kbd "o") (my-func/open-and-switch-to-buffer 'org-agenda-list "*Org Agenda*" t))