You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Doom Emacs中自定义org-agenda-files切换函数报错求助

问题原因与解决方案

问题根源

你代码里的错误出在使用set函数给org-agenda-files赋值。在Emacs Lisp中:

  • set的第一个参数必须是符号(symbol),但你直接传入了org-agenda-files变量的当前值(一个列表),导致Emacs报错“Wrong type argument: symbolp”——它需要符号,却收到了列表。
  • 给变量赋值应该用setq(全局变量可用setq-default),setq的第一个参数直接写变量名(符号)即可,不需要额外引用。

修正后的代码

把所有set替换成setq,修改后的代码如下:

;; Defining contexts to be used
(after! org
  (defun org-focus-private() "Set focus on private things."
        (interactive)
        (setq org-agenda-files '("~/org/private.org")))

  (defun org-focus-work() "Set focus on work things."
        (interactive)
        (setq org-agenda-files '("~/org/work.org")))

  (defun org-focus-all() "Set focus on all things."
        (interactive)
        (setq org-agenda-files '("~/org/work.org"
                                "~/org/private.org")))
  )

额外优化建议

  • 切换上下文后自动打开Org Agenda:可以在每个函数末尾添加(org-agenda),示例:
    (defun org-focus-private() "Set focus on private things."
          (interactive)
          (setq org-agenda-files '("~/org/private.org"))
          (org-agenda))
    
  • 绑定快捷键提升效率:在config.el里添加以下代码,用<leader> o p/w/a快速切换:
    (map! :leader
          :desc "Focus Private Agenda" "o p" #'org-focus-private
          :desc "Focus Work Agenda" "o w" #'org-focus-work
          :desc "Focus All Agenda" "o a" #'org-focus-all)
    

内容的提问来源于stack exchange,提问作者Tiago Melo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 07:19:58