From d1c42338a786ffbfa219c14ad33ae069df3cbd16 Mon Sep 17 00:00:00 2001 From: Lucius Hu <1222865+lebensterben@users.noreply.github.com> Date: Thu, 5 Jan 2023 15:59:46 -0500 Subject: [PATCH] fix(spacemacs-buffer): fix retrieval org-agenda-files (#15871) In particular, we only need to call (org-agenda-files) (and hence load org) if the variable org-agenda-files is a single file name. Otherwise we can safely use the value of the said variable directly. This was not handled correctly before this commit. --- core/core-spacemacs-buffer.el | 45 ++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/core/core-spacemacs-buffer.el b/core/core-spacemacs-buffer.el index 51066a22b..6875ec774 100644 --- a/core/core-spacemacs-buffer.el +++ b/core/core-spacemacs-buffer.el @@ -1279,27 +1279,40 @@ SEQ, START and END are the same arguments as for `cl-subseq'" (insert spacemacs-buffer-list-separator))) (defun spacemacs-buffer//insert-recent-files (list-size) + "Insert recent file entries to spacemacs-buffer. + +LIST-SIZE is specified in `dotspacemacs-startup-lists' for recent entries." (unless recentf-mode (recentf-mode)) - (let ((agenda-files - (let ((default-directory - (or (bound-and-true-p org-directory) default-directory)) - (files - (if (or (not (fboundp 'org-agenda-files)) - (autoloadp (symbol-function 'org-agenda-files))) - (bound-and-true-p org-agenda-files) - (org-agenda-files)))) + (let (;; we need to remove `org-agenda-files' entries from recent files + (agenda-files + (when-let ((default-directory + (or (bound-and-true-p org-directory) "~/org")) + (files + (when (bound-and-true-p org-agenda-files) + (if (listp org-agenda-files) + ;; if it's a list, we take that value directly + org-agenda-files + ;; but if it's a string, it must be file where the list + ;; of agenda files are stored in that file and we have + ;;to load `org-agenda' to process the list. + (when (y-or-n-p "`org-agenda-files' is a string and \ +not a list. Load `org' and continue?") + (require 'org) + (org-agenda-files)))))) (mapcar #'expand-file-name files))) - (ignore-directory (or (and (boundp 'org-directory) - (expand-file-name org-directory)) + ;; we also need to skip sub-directories of `org-directory' + (ignore-directory (or (when (bound-and-true-p org-directory) + (expand-file-name org-directory)) "")) (recent-files-list)) (cl-loop for rfile in recentf-list - while (length< recent-files-list list-size) - collect (let ((full-path (expand-file-name rfile))) - (unless (or (string-prefix-p ignore-directory full-path) - (member full-path agenda-files)) - (add-to-list 'recent-files-list rfile t)))) - + while (> list-size 0) + do (let ((full-path (expand-file-name rfile))) + (unless (or (string-prefix-p ignore-directory full-path) + (member full-path agenda-files)) + (cl-pushnew rfile recent-files-list) + (setq list-size (1- list-size)))) + finally do (setq recent-files-list (nreverse recent-files-list))) (when (spacemacs-buffer//insert-file-list (spacemacs-buffer||propertize-heading (when dotspacemacs-startup-buffer-show-icons