diff --git a/doom/.config/doom/README.org b/doom/.config/doom/README.org index 3d28a96..bb18fff 100644 --- a/doom/.config/doom/README.org +++ b/doom/.config/doom/README.org @@ -3415,26 +3415,26 @@ 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 - (cl-remove-if-not #'file-directory-p + (cl-remove-if-not #'file-directory-p (if (eq (car-safe dired-elements) t) (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))))))) - - ;; Execution Block + (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))))))) + (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 diff --git a/doom/.config/doom/config.el b/doom/.config/doom/config.el index e5322ec..49f415e 100644 --- a/doom/.config/doom/config.el +++ b/doom/.config/doom/config.el @@ -2499,26 +2499,26 @@ 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 - (cl-remove-if-not #'file-directory-p + (cl-remove-if-not #'file-directory-p (if (eq (car-safe dired-elements) t) (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))))))) - - ;; Execution Block + (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))))))) + (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)