diff --git a/doom/.config/doom/README.org b/doom/.config/doom/README.org index 098f9ed..e635036 100644 --- a/doom/.config/doom/README.org +++ b/doom/.config/doom/README.org @@ -3672,17 +3672,32 @@ Project bookmarks go to .bookmarks file in project root." (defun gortium/transfer-to-global () "Transfer a project bookmark to the global bookmarks list." (interactive) - (let* ((bookmarks (gortium/read-plan-bookmarks)) - (names (mapcar #'car bookmarks))) - (if names + (if (not (projectile-project-p)) + (user-error "Not in a project") + (let* ((proj-file (expand-file-name ".bookmarks" (projectile-project-root))) + (proj-bms (and (file-exists-p proj-file) + (with-temp-buffer + (insert-file-contents proj-file) + (ignore-errors (read (current-buffer)))))) + (names (mapcar (lambda (b) (if (consp b) (car b) b)) proj-bms))) + (if (not names) + (message "No project bookmarks to transfer.") (let* ((name (completing-read "Transfer to global: " names nil t)) - (url (cdr (assoc name bookmarks)))) + (entry (assoc name proj-bms)) + (url (alist-get 'filename (cdr entry)))) (when (and name url (y-or-n-p (format "Transfer '%s' to global? " name))) (bookmark-store name `((filename . ,url)) t) (bookmark-save) - (gortium/remove-bookmark-from-plan name) - (message "Transferred '%s' to global" name))) - (message "No project bookmarks to transfer.")))) + ;; Remove from .bookmarks — re-read, delete, save + (let ((saved-alist (copy-tree bookmark-alist))) + (setq bookmark-alist + (with-temp-buffer + (insert-file-contents proj-file) + (read (current-buffer)))) + (setq bookmark-alist (assq-delete-all name bookmark-alist)) + (bookmark-save nil proj-file) + (setq bookmark-alist saved-alist)) + (message "Transferred '%s' to global" name))))))) (defun gortium/list-project-bookmarks () "Show project bookmarks menu — restores globals after RET jump and on q." diff --git a/doom/.config/doom/config.el b/doom/.config/doom/config.el index 4b1b69e..f7deb98 100644 --- a/doom/.config/doom/config.el +++ b/doom/.config/doom/config.el @@ -2739,17 +2739,32 @@ Project bookmarks go to .bookmarks file in project root." (defun gortium/transfer-to-global () "Transfer a project bookmark to the global bookmarks list." (interactive) - (let* ((bookmarks (gortium/read-plan-bookmarks)) - (names (mapcar #'car bookmarks))) - (if names + (if (not (projectile-project-p)) + (user-error "Not in a project") + (let* ((proj-file (expand-file-name ".bookmarks" (projectile-project-root))) + (proj-bms (and (file-exists-p proj-file) + (with-temp-buffer + (insert-file-contents proj-file) + (ignore-errors (read (current-buffer)))))) + (names (mapcar (lambda (b) (if (consp b) (car b) b)) proj-bms))) + (if (not names) + (message "No project bookmarks to transfer.") (let* ((name (completing-read "Transfer to global: " names nil t)) - (url (cdr (assoc name bookmarks)))) + (entry (assoc name proj-bms)) + (url (alist-get 'filename (cdr entry)))) (when (and name url (y-or-n-p (format "Transfer '%s' to global? " name))) (bookmark-store name `((filename . ,url)) t) (bookmark-save) - (gortium/remove-bookmark-from-plan name) - (message "Transferred '%s' to global" name))) - (message "No project bookmarks to transfer.")))) + ;; Remove from .bookmarks — re-read, delete, save + (let ((saved-alist (copy-tree bookmark-alist))) + (setq bookmark-alist + (with-temp-buffer + (insert-file-contents proj-file) + (read (current-buffer)))) + (setq bookmark-alist (assq-delete-all name bookmark-alist)) + (bookmark-save nil proj-file) + (setq bookmark-alist saved-alist)) + (message "Transferred '%s' to global" name))))))) (defun gortium/list-project-bookmarks () "Show project bookmarks menu — restores globals after RET jump and on q."