From 9126b62d5745817e215c69cc4593180400aaadba Mon Sep 17 00:00:00 2001 From: Thierry Pouplier Date: Fri, 17 Jul 2026 21:14:58 -0400 Subject: [PATCH] refactor: inline append-bookmark-to-plan into transfer-to-project --- doom/.config/doom/README.org | 35 +++++++++++++++-------------------- doom/.config/doom/config.el | 35 +++++++++++++++-------------------- 2 files changed, 30 insertions(+), 40 deletions(-) diff --git a/doom/.config/doom/README.org b/doom/.config/doom/README.org index 36f96d9..5d11fc4 100644 --- a/doom/.config/doom/README.org +++ b/doom/.config/doom/README.org @@ -3583,22 +3583,7 @@ Returns alist ((NAME . URL) ...) where URL is the link target." (setq gortium/project-bookmark-names (mapcar #'car bookmarks)) (nreverse bookmarks)))))) -(defun gortium/append-bookmark-to-plan (name url) - "Add a bookmark NAME with URL to the project's .bookmarks file. -Saves only project bookmarks without contaminating global list." - (when (projectile-project-p) - (let* ((proj-file (expand-file-name ".bookmarks" (projectile-project-root))) - (saved-alist (copy-tree bookmark-alist))) - ;; Save globals first, then load project bookmarks - (bookmark-save) - (if (file-exists-p proj-file) - (bookmark-load proj-file t) - (setq bookmark-alist nil)) - (bookmark-store name `((filename . ,url)) nil) - (bookmark-save nil proj-file) - ;; Restore globals - (setq bookmark-alist saved-alist) - (message "Bookmark added to .bookmarks")))) + (defun gortium/remove-bookmark-from-plan (name) "Remove a bookmark entry from * Bookmarks in the Plan file." @@ -3694,17 +3679,27 @@ Project bookmarks are deleted from the .bookmarks file in the project root." (write-region (point-min) (point-max) plan-file nil 'silent))))) (defun gortium/transfer-to-project () - "Transfer a global bookmark to the current project's Plan file." + "Transfer a global bookmark to the current project's .bookmarks." (interactive) (if (projectile-project-p) (let* ((name (completing-read "Transfer to project: " (bookmark-all-names) nil t)) - (file (bookmark-location name))) + (file (bookmark-location name)) + (proj-file (expand-file-name ".bookmarks" (projectile-project-root)))) (when (and name file (y-or-n-p (format "Transfer '%s' to project? " name))) - (gortium/append-bookmark-to-plan name file) + ;; Save globals, add to .bookmarks, restore globals + (let ((saved-alist (copy-tree bookmark-alist))) + (bookmark-save) + (if (file-exists-p proj-file) + (bookmark-load proj-file t) + (setq bookmark-alist nil)) + (bookmark-store name `((filename . ,file)) nil) + (bookmark-save nil proj-file) + (setq bookmark-alist saved-alist)) + ;; Delete from globals (bookmark-delete name) (bookmark-save) (message "Transferred '%s' to project %s" name - (or (gortium/project-tag) "")))) + (or (gortium//project-tag) "")))) (user-error "Not in a Projectile project"))) (defun gortium/transfer-to-global () diff --git a/doom/.config/doom/config.el b/doom/.config/doom/config.el index fed9e3f..1163ae1 100644 --- a/doom/.config/doom/config.el +++ b/doom/.config/doom/config.el @@ -2650,22 +2650,7 @@ Returns alist ((NAME . URL) ...) where URL is the link target." (setq gortium/project-bookmark-names (mapcar #'car bookmarks)) (nreverse bookmarks)))))) -(defun gortium/append-bookmark-to-plan (name url) - "Add a bookmark NAME with URL to the project's .bookmarks file. -Saves only project bookmarks without contaminating global list." - (when (projectile-project-p) - (let* ((proj-file (expand-file-name ".bookmarks" (projectile-project-root))) - (saved-alist (copy-tree bookmark-alist))) - ;; Save globals first, then load project bookmarks - (bookmark-save) - (if (file-exists-p proj-file) - (bookmark-load proj-file t) - (setq bookmark-alist nil)) - (bookmark-store name `((filename . ,url)) nil) - (bookmark-save nil proj-file) - ;; Restore globals - (setq bookmark-alist saved-alist) - (message "Bookmark added to .bookmarks")))) + (defun gortium/remove-bookmark-from-plan (name) "Remove a bookmark entry from * Bookmarks in the Plan file." @@ -2761,17 +2746,27 @@ Project bookmarks are deleted from the .bookmarks file in the project root." (write-region (point-min) (point-max) plan-file nil 'silent))))) (defun gortium/transfer-to-project () - "Transfer a global bookmark to the current project's Plan file." + "Transfer a global bookmark to the current project's .bookmarks." (interactive) (if (projectile-project-p) (let* ((name (completing-read "Transfer to project: " (bookmark-all-names) nil t)) - (file (bookmark-location name))) + (file (bookmark-location name)) + (proj-file (expand-file-name ".bookmarks" (projectile-project-root)))) (when (and name file (y-or-n-p (format "Transfer '%s' to project? " name))) - (gortium/append-bookmark-to-plan name file) + ;; Save globals, add to .bookmarks, restore globals + (let ((saved-alist (copy-tree bookmark-alist))) + (bookmark-save) + (if (file-exists-p proj-file) + (bookmark-load proj-file t) + (setq bookmark-alist nil)) + (bookmark-store name `((filename . ,file)) nil) + (bookmark-save nil proj-file) + (setq bookmark-alist saved-alist)) + ;; Delete from globals (bookmark-delete name) (bookmark-save) (message "Transferred '%s' to project %s" name - (or (gortium/project-tag) "")))) + (or (gortium//project-tag) "")))) (user-error "Not in a Projectile project"))) (defun gortium/transfer-to-global ()