whompmacs/whomp/whomp-helpers.el

72 lines
2.6 KiB
EmacsLisp
Raw Normal View History

;;
;; Helper functions for the dashboard
;;
2024-07-12 23:32:01 +00:00
(defun whomp/dashboard-insert-logo-title (banner)
2024-07-10 08:52:22 +00:00
"Insert BANNER into the dashboard buffer.
BANNER can be a single string, which will be centered, or a list of strings,
which will be displayed with line breaks between them."
(insert "\n")
;; if banner is a single string, display it in the center
;; else if it is a list of strings, display them with line breaks
(if (stringp banner)
(insert (propertize banner 'face 'dashboard-banner-logo-title))
(dolist (line banner)
(insert (propertize line 'face 'dashboard-banner-logo-title))
(insert "\n"))))
2024-07-12 23:32:01 +00:00
(defun whomp/dashboard-build-logo-title (lst)
2024-07-10 08:52:22 +00:00
"Build a list of strings from LST to display as the banner.
LST is reversed and concatenated into a single string with line breaks."
(mapconcat 'identity (reverse lst) "\n"))
2024-07-12 23:32:01 +00:00
(defun whomp/random-string-from-list (strings)
2024-07-10 08:52:22 +00:00
"Return a random string from STRINGS."
(let ((index (random (length strings))))
(nth index strings)))
;;
;; Helper functions for general use
;;
2024-07-10 08:52:22 +00:00
;; Function to create a directory if it doesn't exist
2024-07-12 23:32:01 +00:00
(defun whomp/ensure-directory-exists (dir)
2024-07-10 08:52:22 +00:00
"Ensure the directory DIR exists. If not, create it."
(unless (file-directory-p dir)
(message "Creating missing directory: %s" dir)
2024-07-10 08:52:22 +00:00
(make-directory dir t)))
;; Function to list all files in a directory with a given extension
2024-07-12 23:32:01 +00:00
(defun whomp/list-files-with-extension (dir extension)
"Recursively list all files in DIR with the given EXTENSION, suitable for org-agenda-files."
(let ((files '()))
(dolist (file (directory-files-recursively dir (concat "\\." extension "\\'")))
(push file files))
(nreverse files)))
;;
;; Helper functions for org mode
;;
;; Function to get a unique filename for Org-capture
2024-07-12 23:32:01 +00:00
(defun whomp/org-capture-get-unique-filename ()
"Generate a unique filename for Org-capture."
(let ((filename (format "~/.org-agenda/syncup__issue__%s.org" (format-time-string "%Y%m%d%H%M%S"))))
(message "Inside function: Generated filename: %s" filename)
filename))
;; Function to update org-agenda-files
2024-07-12 23:32:01 +00:00
(defun whomp/org-agenda-files-update ()
2024-07-10 08:52:22 +00:00
"Update the `org-agenda-files` variable.
This function sets `org-agenda-files` and `org-timeblock-files` to the list of
all `.org` files in the `~/.org-agenda` directory, and sets
`org-timeblock-inbox-file` to `~/org/agenda/index.org`."
2024-07-12 23:32:01 +00:00
(setq org-agenda-files (whomp/list-files-with-extension "~/org/agenda" "org"))
(setq org-timeblock-files (whomp/list-files-with-extension "~/org/agenda" "org"))
(setq org-timeblock-inbox-file "~/org/agenda/index.org"))
2024-07-12 23:32:01 +00:00
(message "W.H.O.M.P. Loaded helper function library.")
(provide 'whomp-helpers)
;;; whomp-helpers.el ends here