[已解决]Org agenda无法自动载入

大家好,我参照的子龙大大的配置,我在配置中添加了org agenda 的一段代码

(setq org-agenda-files (file-expand-wildcards "~/.emacs.d/org/*.org"))

,但是每次C-h v后,返还的信息是

org-agenda-files is a variable defined in ‘org.el’. Its value is nil

在agenda页面看不到当前已经安排的日程。当我再次执行这一段代码后,就返还信息 ("~/org/gtd.org") 这样才可以查看当前已安排的日程,请问大家,这是什么原因呢?我已经查了很多资料和网页,都找不到答案,特来请教,请指点,谢谢!


版本: GNU Emacs 25.0.93.1 (x86_64-w64-mingw32) of 2016-04-23 Org-mode version 8.3.4 (8.3.4-79-gbd4948-elpa @ c:/Emacs/.emacs.d/elpa/org-20160606/)

有可能setq之后又被其他配置覆盖了?

可以试试把这段代码加到整个 emacs 配置的最后再试试,或者等子龙来解答下。

把这个代码用 with-eval-after-load 包起来吧,或者在设置这个变量之前,手动 (require 'org)

谢谢大大的回复。你的方法我按照视频里试过,是无效的。 看到您的回复前,我狠狠地测试,连最小配置都不能正常显示agenda。老是要运行一次(setq org-agenda-files (file-expand-wildcards "~/.emacs.d/org/*.org"))。 然后我找到了一个主题,

emacs - org-agenda buffer no longer shows agenda items - Stack Overflow
Ensure you don’t have org-agenda-files set in a “customize” block in your .Emacs file. This is a common source of errors.

他上面说,注意自己的配置里有否阻碍了该参数设置的生效。这样我找到了.emacs配置中,有一行'(org-agenda-files nil)',马上注释掉,然后世界安静了,打开Emacs后,C-c a a ,显示最新的日程。

奇怪的是,自已没有设置过这个参数啊,不知道哪里跑出来的。问题已经解决,谢谢大家。

那是 Custom 加的,要是我没记错的话,Custom 默认把数据添加到你的 init file 的结尾,这样很不好,你应该设置 custom-file 让其保存至一个单独的文件中,比如

(setq custom-file (locate-user-emacs-file "custom.el"))
(load custom-file :no-error :no-message)

另外,这段配置在你的 init file 中所处的位置也应该有讲究,一般放到开头或者结尾,取决于你认为谁的优先级高。

1 个赞

请参考 @xuchunyang 的回复,应该指出了你的问题。

我每次都是直接改配置,没用过 Custom

1 个赞

我一般也不用 Custom,但是有时候不得不用,就是有些配置不可能手写,比如 package-selected-packagessafe-local-variable-values。我目前的 custom.el 中的内容:

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(custom-enabled-themes (quote (sanityinc-tomorrow-eighties)))
 '(custom-safe-themes
   (quote
    ("628278136f88aa1a151bb2d6c8a86bf2b7631fbea5f0f76cba2a0079cd910f7d" default)))
 '(package-selected-packages
   (quote
    (youdao-dictionary quack emms no-littering grab-mac-link yagist gist stream irfc cmake-mode region-state company-irony irony-eldoc irony geiser epm cal-china-x lua-mode yaml-mode xmlgen whitespace-cleanup-mode wgrep-helm validate use-package undo-tree twittering-mode tldr sx spinner spacemacs-theme slime shut-up rust-mode ruby-tools robe rainbow-mode rainbow-delimiters quickrun queue projectile pinyin-search persistent-soft paredit-menu page-break-lines package-utils osx-dictionary org-plus-contrib org-alert nlinum magit launch kanji-mode ipretty intero hydra htmlize hl-todo helm-zhihu-daily helm-unicode helm-open-github helm-mu helm-ls-git helm-github-stars helm-descbinds helm-ag gitignore-mode github-notifier gitconfig-mode git-timemachine git-messenger git-gutter gh-md flyspell-popup f exec-path-from-shell eshell-z eshell-git-prompt eshell-did-you-mean elisp-slime-nav e2ansi drag-stuff dockerfile-mode docker diff-hl cycle-quotes counsel color-theme-sanityinc-tomorrow color-identifiers-mode circe chess bonjourmadame bongo bing-dict beacon auto-overlays ascii-art-to-unicode ansi ampc aggressive-indent ag ack ace-window ace-link 4clojure)))
 '(safe-local-variable-values
   (quote
    ((eval and
           (bound-and-true-p aggressive-indent-mode)
           (aggressive-indent-mode -1))
     (run-cmd . "gcc -Wall -lmpc hello-mpc.c && ./a.out")))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )