emacs update cache complete
This commit is contained in:
@@ -706,13 +706,25 @@ empty list if the cache doesn’t exist.
|
|||||||
#+begin_src emacs-lisp :tangle ./config.el
|
#+begin_src emacs-lisp :tangle ./config.el
|
||||||
(defvar my/org-agenda-cache-file "~/Documents/Notes/.cache"
|
(defvar my/org-agenda-cache-file "~/Documents/Notes/.cache"
|
||||||
"Path to the org-agenda cache file.")
|
"Path to the org-agenda cache file.")
|
||||||
|
|
||||||
|
(defvar my/org-always-included-agenda-files
|
||||||
|
'("~/Documents/Notes/20220823172331-chores.org")
|
||||||
|
"Org files to always include in the agenda, even if no TODOs are found.")
|
||||||
|
|
||||||
(defun my/update-org-agenda-cache ()
|
(defun my/update-org-agenda-cache ()
|
||||||
"Scan Org files and cache only those that contain TODOs or checkboxes."
|
"Scan Org files and cache those with TODOs, checkboxes, or timestamped entries."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((org-dir "~/Documents/Notes/")
|
(let* ((org-dir "~/Documents/Notes/")
|
||||||
(files (directory-files-recursively org-dir "\\.org$"))
|
(files (directory-files-recursively org-dir "\\.org$"))
|
||||||
(todo-files '())
|
(todo-files '())
|
||||||
(regex "\\*+[ \t]+\\(TODO\\|PROJ\\|ART\\|IDEA\\|HOLD\\|\\[ \\]\\|\\[-\\]\\|\\[\\?\\]\\)"))
|
(regex (concat
|
||||||
|
;; Standard TODO entries and checkboxes
|
||||||
|
"\\*+[ \t]+\\(TODO\\|PROJ\\|ART\\|IDEA\\|HOLD\\|\\[ \\]\\|\\[-\\]\\|\\[\\?\\]\\)"
|
||||||
|
;; Org scheduling keywords
|
||||||
|
"\\|SCHEDULED:"
|
||||||
|
"\\|DEADLINE:"
|
||||||
|
;; Standalone timestamps like <2025-04-14 Mon>
|
||||||
|
"\\|<[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}")))
|
||||||
(dolist (file files)
|
(dolist (file files)
|
||||||
(message "Scanning: %s" file)
|
(message "Scanning: %s" file)
|
||||||
(condition-case err
|
(condition-case err
|
||||||
@@ -720,27 +732,29 @@ empty list if the cache doesn’t exist.
|
|||||||
(insert-file-contents file)
|
(insert-file-contents file)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(when (re-search-forward regex nil t)
|
(when (re-search-forward regex nil t)
|
||||||
(message " -> TODO found in: %s" file)
|
(message " -> Relevant entry found in: %s" file)
|
||||||
(push file todo-files)))
|
(push file todo-files)))
|
||||||
(error (message "Error reading %s: %s" file err))))
|
(error (message "Error reading %s: %s" file err))))
|
||||||
(setq todo-files (delete-dups todo-files))
|
(setq todo-files (delete-dups (append todo-files my/org-always-included-agenda-files)))
|
||||||
(if todo-files
|
(if todo-files
|
||||||
(progn
|
(progn
|
||||||
(message "Writing %d TODO files to cache" (length todo-files))
|
(message "Writing %d agenda-relevant files to cache" (length todo-files))
|
||||||
(with-temp-file my/org-agenda-cache-file
|
(with-temp-file my/org-agenda-cache-file
|
||||||
(prin1 todo-files (current-buffer))))
|
(prin1 todo-files (current-buffer))))
|
||||||
(message "No TODOs found — not writing cache."))))
|
(message "No relevant entries found — not writing cache."))))
|
||||||
|
|
||||||
(defun my/load-org-agenda-from-cache ()
|
(defun my/load-org-agenda-from-cache ()
|
||||||
"Load org-agenda-files from .cache, or fallback to an empty list."
|
"Load org-agenda-files from the cache, or fallback to an empty list."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((file my/org-agenda-cache-file))
|
(let ((file my/org-agenda-cache-file))
|
||||||
(if (and (file-exists-p file)
|
(if (and (file-readable-p file)
|
||||||
(> (nth 7 (file-attributes file)) 0)) ; size > 0
|
(> (nth 7 (file-attributes file)) 0)) ; file size > 0
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert-file-contents file)
|
(insert-file-contents file)
|
||||||
(read (current-buffer)))
|
(read (current-buffer)))
|
||||||
(message "Agenda cache not found or empty")
|
(message "Agenda cache not found or empty")
|
||||||
nil)))
|
nil)))
|
||||||
|
|
||||||
(after! org
|
(after! org
|
||||||
(setq org-agenda-files (my/load-org-agenda-from-cache)))
|
(setq org-agenda-files (my/load-org-agenda-from-cache)))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
download.enable = true;
|
download.enable = true;
|
||||||
ffmpreg.enable = true;
|
ffmpreg.enable = true;
|
||||||
ffmpeg4discord.enable = true;
|
ffmpeg4discord.enable = true;
|
||||||
|
update-org-agenda-cache.enable = true;
|
||||||
};
|
};
|
||||||
servers.drpp.enable = true;
|
servers.drpp.enable = true;
|
||||||
}
|
}
|
||||||
|
|||||||
22
modules/scripts/update-org-agenda-cache.nix
Normal file
22
modules/scripts/update-org-agenda-cache.nix
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
imports = [ ./base.nix ];
|
||||||
|
config.my.scripts.update-org-agenda-cache = {
|
||||||
|
enable = lib.mkDefault false;
|
||||||
|
install = config.my.emacs.enable;
|
||||||
|
service = config.my.emacs.enable;
|
||||||
|
name = "update-org-agenda-cache";
|
||||||
|
timer = "*:0/30";
|
||||||
|
description = "runs a function which builds a cache file.";
|
||||||
|
package = pkgs.writeScriptBin "update-org-agenda-cache" ''
|
||||||
|
#!/usr/bin/env nix-shell
|
||||||
|
#! nix-shell -i bash -p bash
|
||||||
|
${config.services.emacs.package}/bin/emacsclient --eval '(my/update-org-agenda-cache)'
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user