fix: transfer-to-global uses .bookmarks, not Plan file
This commit is contained in:
@@ -3672,17 +3672,32 @@ Project bookmarks go to .bookmarks file in project root."
|
|||||||
(defun gortium/transfer-to-global ()
|
(defun gortium/transfer-to-global ()
|
||||||
"Transfer a project bookmark to the global bookmarks list."
|
"Transfer a project bookmark to the global bookmarks list."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((bookmarks (gortium/read-plan-bookmarks))
|
(if (not (projectile-project-p))
|
||||||
(names (mapcar #'car bookmarks)))
|
(user-error "Not in a project")
|
||||||
(if names
|
(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))
|
(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)))
|
(when (and name url (y-or-n-p (format "Transfer '%s' to global? " name)))
|
||||||
(bookmark-store name `((filename . ,url)) t)
|
(bookmark-store name `((filename . ,url)) t)
|
||||||
(bookmark-save)
|
(bookmark-save)
|
||||||
(gortium/remove-bookmark-from-plan name)
|
;; Remove from .bookmarks — re-read, delete, save
|
||||||
(message "Transferred '%s' to global" name)))
|
(let ((saved-alist (copy-tree bookmark-alist)))
|
||||||
(message "No project bookmarks to transfer."))))
|
(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 ()
|
(defun gortium/list-project-bookmarks ()
|
||||||
"Show project bookmarks menu — restores globals after RET jump and on q."
|
"Show project bookmarks menu — restores globals after RET jump and on q."
|
||||||
|
|||||||
@@ -2739,17 +2739,32 @@ Project bookmarks go to .bookmarks file in project root."
|
|||||||
(defun gortium/transfer-to-global ()
|
(defun gortium/transfer-to-global ()
|
||||||
"Transfer a project bookmark to the global bookmarks list."
|
"Transfer a project bookmark to the global bookmarks list."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((bookmarks (gortium/read-plan-bookmarks))
|
(if (not (projectile-project-p))
|
||||||
(names (mapcar #'car bookmarks)))
|
(user-error "Not in a project")
|
||||||
(if names
|
(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))
|
(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)))
|
(when (and name url (y-or-n-p (format "Transfer '%s' to global? " name)))
|
||||||
(bookmark-store name `((filename . ,url)) t)
|
(bookmark-store name `((filename . ,url)) t)
|
||||||
(bookmark-save)
|
(bookmark-save)
|
||||||
(gortium/remove-bookmark-from-plan name)
|
;; Remove from .bookmarks — re-read, delete, save
|
||||||
(message "Transferred '%s' to global" name)))
|
(let ((saved-alist (copy-tree bookmark-alist)))
|
||||||
(message "No project bookmarks to transfer."))))
|
(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 ()
|
(defun gortium/list-project-bookmarks ()
|
||||||
"Show project bookmarks menu — restores globals after RET jump and on q."
|
"Show project bookmarks menu — restores globals after RET jump and on q."
|
||||||
|
|||||||
Reference in New Issue
Block a user