refactor: inline append-bookmark-to-plan into transfer-to-project
This commit is contained in:
@@ -3583,22 +3583,7 @@ Returns alist ((NAME . URL) ...) where URL is the link target."
|
|||||||
(setq gortium/project-bookmark-names (mapcar #'car bookmarks))
|
(setq gortium/project-bookmark-names (mapcar #'car bookmarks))
|
||||||
(nreverse 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)
|
(defun gortium/remove-bookmark-from-plan (name)
|
||||||
"Remove a bookmark entry from * Bookmarks in the Plan file."
|
"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)))))
|
(write-region (point-min) (point-max) plan-file nil 'silent)))))
|
||||||
|
|
||||||
(defun gortium/transfer-to-project ()
|
(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)
|
(interactive)
|
||||||
(if (projectile-project-p)
|
(if (projectile-project-p)
|
||||||
(let* ((name (completing-read "Transfer to project: " (bookmark-all-names) nil t))
|
(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)))
|
(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-delete name)
|
||||||
(bookmark-save)
|
(bookmark-save)
|
||||||
(message "Transferred '%s' to project %s" name
|
(message "Transferred '%s' to project %s" name
|
||||||
(or (gortium/project-tag) ""))))
|
(or (gortium//project-tag) ""))))
|
||||||
(user-error "Not in a Projectile project")))
|
(user-error "Not in a Projectile project")))
|
||||||
|
|
||||||
(defun gortium/transfer-to-global ()
|
(defun gortium/transfer-to-global ()
|
||||||
|
|||||||
@@ -2650,22 +2650,7 @@ Returns alist ((NAME . URL) ...) where URL is the link target."
|
|||||||
(setq gortium/project-bookmark-names (mapcar #'car bookmarks))
|
(setq gortium/project-bookmark-names (mapcar #'car bookmarks))
|
||||||
(nreverse 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)
|
(defun gortium/remove-bookmark-from-plan (name)
|
||||||
"Remove a bookmark entry from * Bookmarks in the Plan file."
|
"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)))))
|
(write-region (point-min) (point-max) plan-file nil 'silent)))))
|
||||||
|
|
||||||
(defun gortium/transfer-to-project ()
|
(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)
|
(interactive)
|
||||||
(if (projectile-project-p)
|
(if (projectile-project-p)
|
||||||
(let* ((name (completing-read "Transfer to project: " (bookmark-all-names) nil t))
|
(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)))
|
(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-delete name)
|
||||||
(bookmark-save)
|
(bookmark-save)
|
||||||
(message "Transferred '%s' to project %s" name
|
(message "Transferred '%s' to project %s" name
|
||||||
(or (gortium/project-tag) ""))))
|
(or (gortium//project-tag) ""))))
|
||||||
(user-error "Not in a Projectile project")))
|
(user-error "Not in a Projectile project")))
|
||||||
|
|
||||||
(defun gortium/transfer-to-global ()
|
(defun gortium/transfer-to-global ()
|
||||||
|
|||||||
Reference in New Issue
Block a user