whompmacs/doc/helpers.org

4.5 KiB

WHOMP Emacs Helper Functions

This document provides an overview and documentation of various helper functions used in the WHOMP Emacs configuration.

Dashboard Helper Functions

whomp/dashboard-insert-logo-title

(defun whomp/dashboard-insert-logo-title (banner)
  "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 (stringp banner)
      (insert (propertize banner 'face 'dashboard-banner-logo-title))
    (dolist (line banner)
      (insert (propertize line 'face 'dashboard-banner-logo-title))
      (insert "\n"))))

This function inserts a banner into the dashboard buffer. If `banner` is a single string, it is displayed in the center. If it is a list of strings, they are displayed with line breaks.

Example usage:

(whomp/dashboard-insert-logo-title "Welcome to Emacs")
(whomp/dashboard-insert-logo-title '("Welcome to Emacs" "Have a great day!"))

whomp/dashboard-build-logo-title

(defun whomp/dashboard-build-logo-title (lst)
  "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"))

This function builds a list of strings from `lst` to display as the banner by reversing `lst` and concatenating it into a single string with line breaks.

Example usage:

(whomp/dashboard-build-logo-title '("Line 1" "Line 2" "Line 3"))
;; Output: "Line 3\nLine 2\nLine 1"

whomp/random-string-from-list

(defun whomp/random-string-from-list (strings)
  "Return a random string from STRINGS."
  (let ((index (random (length strings))))
    (nth index strings)))

This function returns a random string from the list `strings`.

Example usage:

(whomp/random-string-from-list '("Option 1" "Option 2" "Option 3"))

General Helper Functions

whomp/ensure-directory-exists

(defun whomp/ensure-directory-exists (dir)
  "Ensure the directory DIR exists. If not, create it."
  (unless (file-directory-p dir)
    (make-directory dir t)))

This function ensures that the directory `dir` exists, creating it if necessary.

Example usage:

(whomp/ensure-directory-exists "~/my/new/directory")

whomp/list-files-with-extension

(defun whomp/list-files-with-extension (dir extension)
  "Recursively list all files in DIR with the given EXTENSION.
This function is suitable for setting `org-agenda-files`."
  (let ((files '()))
    (dolist (file (directory-files-recursively dir (concat "\\." extension "\\'")))
      (push file files))
    (nreverse files)))

This function recursively lists all files in `dir` with the given `extension`, suitable for use with `org-agenda-files`.

Example usage:

(whomp/list-files-with-extension "~/my/org-files" "org")

Org Mode Helper Functions

whomp/org-capture-get-unique-filename

(defun whomp/org-capture-get-unique-filename ()
  "Generate a unique filename for Org-capture.
The filename is based on the current timestamp."
  (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))

This function generates a unique filename for Org-capture based on the current timestamp.

Example usage:

(whomp/org-capture-get-unique-filename)

whomp/org-agenda-files-update

(defun whomp/org-agenda-files-update ()
  "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/tasks.org`."
  (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/tasks.org"))

This function updates the `org-agenda-files` variable to include all `.org` files in the `~/.org-agenda` directory, and sets the `org-timeblock-inbox-file` to `~/.org-agenda/tasks.org`.

Example usage:

(whomp/org-agenda-files-update)