如何将elisp函数或命令传递给函数参数?

时间:2014-07-22 00:49:03

标签: function emacs parameters elisp

我想编写一个自定义函数来执行以下工作:

(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)

这是我的演示代码,但它不起作用。 你对此有更好的了解吗?

(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))

0 个答案:

没有答案