feat: convert-to-node accepts project-tag and context-tag

This commit is contained in:
2026-07-17 21:44:08 -04:00
parent 956df5c22c
commit bab4a818b6
2 changed files with 34 additions and 32 deletions

View File

@@ -3415,16 +3415,15 @@ CONTEXT-TAG is the mu4e/agenda context (e.g. 'TDNDE', 'Perso')."
(message "ExoKortex Node '%s' created in %s with tag '%s' (context: %s)."
node-name category tag context-tag)))
(defun gortium/convert-to-node (node-dirs)
(defun gortium/convert-to-node (node-dirs &optional project-tag context-tag)
"Retrofit existing workspace directories into tracked ExoKortex nodes.
If folders are explicitly marked in Dirvish/Dired, it batch-processes all of them.
Otherwise, prompts for a single directory, defaulting to the item under the cursor."
Otherwise, prompts for a single directory, defaulting to the item under the cursor.
Optional PROJECT-TAG and CONTEXT-TAG can be given to create .projectile and .dir-locals.el."
(interactive
(list
(let* ((dired-elements (when (derived-mode-p 'dired-mode)
(dired-get-marked-files nil nil nil t)))
;; Dired returns (t . ("path")) if exactly ONE file is marked explicitly,
;; or a flat list if multiple are marked.
(has-explicit-marks (or (and (listp dired-elements) (> (length dired-elements) 1))
(and (consp dired-elements) (eq (car dired-elements) t))))
(marked-dirs (when has-explicit-marks
@@ -3433,8 +3432,9 @@ Otherwise, prompts for a single directory, defaulting to the item under the curs
(cdr dired-elements)
dired-elements)))))
(if marked-dirs
marked-dirs
;; Fallback: No explicit marks found, prompt for a single target
(list marked-dirs
(read-string "Project tag (blank to skip): ")
(completing-read "Context tag: " (quote ("TDNDE" "Perso" "")) nil t))
(let* ((cursor-path (when (derived-mode-p 'dired-mode)
(dired-get-filename nil t)))
(initial-path (cond
@@ -3443,22 +3443,23 @@ Otherwise, prompts for a single directory, defaulting to the item under the curs
(cursor-path
(file-name-directory cursor-path))
(t default-directory))))
(list (read-directory-name "Directory to convert: " nil initial-path t initial-path)))))))
(list (list (read-directory-name "Directory to convert: " nil initial-path t initial-path))
(read-string "Project tag (blank to skip): ")
(completing-read "Context tag: " (quote ("TDNDE" "Perso" "")) nil t)))))))
;; Execution Block
(let ((count 0)
last-org-file)
(dolist (dir node-dirs)
(let* ((node-dir (expand-file-name dir))
(node-name (file-name-nondirectory (directory-file-name node-dir)))
(org-file (gortium/ensure-node-structure node-dir "Audit existing assets and reconcile tracking nodes")))
(org-file (gortium/ensure-node-structure node-dir
"Audit existing assets and reconcile tracking nodes"
(unless (string-empty-p project-tag) project-tag)
(unless (string-empty-p context-tag) context-tag))))
(setq last-org-file org-file)
(cl-incf count)))
;; Contextual UI Feedback
(if (= count 1)
(progn
(message "Directory successfully converted to ExoKortex node."))
(message "Directory successfully converted to ExoKortex node.")
(message "Successfully batch-converted %d directories to ExoKortex nodes!" count))))
#+end_src

View File

@@ -2499,16 +2499,15 @@ CONTEXT-TAG is the mu4e/agenda context (e.g. 'TDNDE', 'Perso')."
(message "ExoKortex Node '%s' created in %s with tag '%s' (context: %s)."
node-name category tag context-tag)))
(defun gortium/convert-to-node (node-dirs)
(defun gortium/convert-to-node (node-dirs &optional project-tag context-tag)
"Retrofit existing workspace directories into tracked ExoKortex nodes.
If folders are explicitly marked in Dirvish/Dired, it batch-processes all of them.
Otherwise, prompts for a single directory, defaulting to the item under the cursor."
Otherwise, prompts for a single directory, defaulting to the item under the cursor.
Optional PROJECT-TAG and CONTEXT-TAG can be given to create .projectile and .dir-locals.el."
(interactive
(list
(let* ((dired-elements (when (derived-mode-p 'dired-mode)
(dired-get-marked-files nil nil nil t)))
;; Dired returns (t . ("path")) if exactly ONE file is marked explicitly,
;; or a flat list if multiple are marked.
(has-explicit-marks (or (and (listp dired-elements) (> (length dired-elements) 1))
(and (consp dired-elements) (eq (car dired-elements) t))))
(marked-dirs (when has-explicit-marks
@@ -2517,8 +2516,9 @@ Otherwise, prompts for a single directory, defaulting to the item under the curs
(cdr dired-elements)
dired-elements)))))
(if marked-dirs
marked-dirs
;; Fallback: No explicit marks found, prompt for a single target
(list marked-dirs
(read-string "Project tag (blank to skip): ")
(completing-read "Context tag: " (quote ("TDNDE" "Perso" "")) nil t))
(let* ((cursor-path (when (derived-mode-p 'dired-mode)
(dired-get-filename nil t)))
(initial-path (cond
@@ -2527,22 +2527,23 @@ Otherwise, prompts for a single directory, defaulting to the item under the curs
(cursor-path
(file-name-directory cursor-path))
(t default-directory))))
(list (read-directory-name "Directory to convert: " nil initial-path t initial-path)))))))
(list (list (read-directory-name "Directory to convert: " nil initial-path t initial-path))
(read-string "Project tag (blank to skip): ")
(completing-read "Context tag: " (quote ("TDNDE" "Perso" "")) nil t)))))))
;; Execution Block
(let ((count 0)
last-org-file)
(dolist (dir node-dirs)
(let* ((node-dir (expand-file-name dir))
(node-name (file-name-nondirectory (directory-file-name node-dir)))
(org-file (gortium/ensure-node-structure node-dir "Audit existing assets and reconcile tracking nodes")))
(org-file (gortium/ensure-node-structure node-dir
"Audit existing assets and reconcile tracking nodes"
(unless (string-empty-p project-tag) project-tag)
(unless (string-empty-p context-tag) context-tag))))
(setq last-org-file org-file)
(cl-incf count)))
;; Contextual UI Feedback
(if (= count 1)
(progn
(message "Directory successfully converted to ExoKortex node."))
(message "Directory successfully converted to ExoKortex node.")
(message "Successfully batch-converted %d directories to ExoKortex nodes!" count))))
(defun gortium/read-dir-local (var)