fix: completing-read for project bookmarks, no alist contamination
This commit is contained in:
@@ -3682,51 +3682,27 @@ Project bookmarks go to .bookmarks file in project root."
|
||||
(message "No project bookmarks to transfer."))))
|
||||
|
||||
;; Bindings
|
||||
(defun gortium/list-global-bookmarks ()
|
||||
"Show global bookmarks, saving project changes first."
|
||||
(interactive)
|
||||
(let ((proj-root (and (projectile-project-p) (projectile-project-root))))
|
||||
(when proj-root
|
||||
(let ((proj-file (expand-file-name ".bookmarks" proj-root)))
|
||||
(when (file-exists-p proj-file)
|
||||
;; Save any pending project bookmark changes
|
||||
(let ((current-file bookmark-default-file))
|
||||
(setq bookmark-default-file proj-file)
|
||||
(ignore-errors (bookmark-save))
|
||||
(setq bookmark-default-file current-file))))))
|
||||
;; Reload globals and show menu
|
||||
(bookmark-load bookmark-default-file t)
|
||||
(bookmark-bmenu-list))
|
||||
|
||||
(defun gortium/list-project-bookmarks ()
|
||||
"Show project bookmarks from .bookmarks in project root."
|
||||
"Pick and jump to a project bookmark via completing-read.
|
||||
Never touches global bookmark-alist."
|
||||
(interactive)
|
||||
(if (not (projectile-project-p))
|
||||
(user-error "Not in a project")
|
||||
(let* ((proj-file (expand-file-name ".bookmarks" (projectile-project-root)))
|
||||
(saved-alist (copy-tree bookmark-alist))
|
||||
(saved-file bookmark-default-file))
|
||||
(if (not (file-exists-p proj-file))
|
||||
(proj-bms (and (file-exists-p proj-file)
|
||||
(with-temp-buffer
|
||||
(insert-file-contents proj-file)
|
||||
(ignore-errors (read (current-buffer)))))))
|
||||
(if (not proj-bms)
|
||||
(message "No .bookmarks file in this project.")
|
||||
;; Save any pending global changes
|
||||
(bookmark-save)
|
||||
;; Switch to project bookmarks
|
||||
(setq bookmark-default-file proj-file)
|
||||
(bookmark-load proj-file t)
|
||||
(bookmark-bmenu-list)
|
||||
(with-current-buffer "*Bookmark List*"
|
||||
(add-hook 'kill-buffer-hook
|
||||
(lambda ()
|
||||
;; Save project changes
|
||||
(ignore-errors (bookmark-save))
|
||||
;; Restore global
|
||||
(setq bookmark-default-file saved-file)
|
||||
(setq bookmark-alist saved-alist))
|
||||
nil t))))))
|
||||
(let* ((names (mapcar (lambda (b) (if (consp b) (car b) b)) proj-bms))
|
||||
(choice (completing-read "Project bookmark: " names nil t)))
|
||||
(when choice
|
||||
;; Temporarily set bookmark-alist to project bookmarks for the jump
|
||||
(let ((bookmark-alist proj-bms))
|
||||
(bookmark-jump choice))))))))
|
||||
|
||||
(map! :leader
|
||||
:desc "List global bookmarks"
|
||||
"RET" #'gortium/list-global-bookmarks
|
||||
:desc "Set bookmark (global/project)"
|
||||
"b m" #'gortium/bookmark-set
|
||||
:desc "List project bookmarks"
|
||||
|
||||
@@ -2752,51 +2752,27 @@ Project bookmarks go to .bookmarks file in project root."
|
||||
(message "No project bookmarks to transfer."))))
|
||||
|
||||
;; Bindings
|
||||
(defun gortium/list-global-bookmarks ()
|
||||
"Show global bookmarks, saving project changes first."
|
||||
(interactive)
|
||||
(let ((proj-root (and (projectile-project-p) (projectile-project-root))))
|
||||
(when proj-root
|
||||
(let ((proj-file (expand-file-name ".bookmarks" proj-root)))
|
||||
(when (file-exists-p proj-file)
|
||||
;; Save any pending project bookmark changes
|
||||
(let ((current-file bookmark-default-file))
|
||||
(setq bookmark-default-file proj-file)
|
||||
(ignore-errors (bookmark-save))
|
||||
(setq bookmark-default-file current-file))))))
|
||||
;; Reload globals and show menu
|
||||
(bookmark-load bookmark-default-file t)
|
||||
(bookmark-bmenu-list))
|
||||
|
||||
(defun gortium/list-project-bookmarks ()
|
||||
"Show project bookmarks from .bookmarks in project root."
|
||||
"Pick and jump to a project bookmark via completing-read.
|
||||
Never touches global bookmark-alist."
|
||||
(interactive)
|
||||
(if (not (projectile-project-p))
|
||||
(user-error "Not in a project")
|
||||
(let* ((proj-file (expand-file-name ".bookmarks" (projectile-project-root)))
|
||||
(saved-alist (copy-tree bookmark-alist))
|
||||
(saved-file bookmark-default-file))
|
||||
(if (not (file-exists-p proj-file))
|
||||
(proj-bms (and (file-exists-p proj-file)
|
||||
(with-temp-buffer
|
||||
(insert-file-contents proj-file)
|
||||
(ignore-errors (read (current-buffer)))))))
|
||||
(if (not proj-bms)
|
||||
(message "No .bookmarks file in this project.")
|
||||
;; Save any pending global changes
|
||||
(bookmark-save)
|
||||
;; Switch to project bookmarks
|
||||
(setq bookmark-default-file proj-file)
|
||||
(bookmark-load proj-file t)
|
||||
(bookmark-bmenu-list)
|
||||
(with-current-buffer "*Bookmark List*"
|
||||
(add-hook 'kill-buffer-hook
|
||||
(lambda ()
|
||||
;; Save project changes
|
||||
(ignore-errors (bookmark-save))
|
||||
;; Restore global
|
||||
(setq bookmark-default-file saved-file)
|
||||
(setq bookmark-alist saved-alist))
|
||||
nil t))))))
|
||||
(let* ((names (mapcar (lambda (b) (if (consp b) (car b) b)) proj-bms))
|
||||
(choice (completing-read "Project bookmark: " names nil t)))
|
||||
(when choice
|
||||
;; Temporarily set bookmark-alist to project bookmarks for the jump
|
||||
(let ((bookmark-alist proj-bms))
|
||||
(bookmark-jump choice))))))))
|
||||
|
||||
(map! :leader
|
||||
:desc "List global bookmarks"
|
||||
"RET" #'gortium/list-global-bookmarks
|
||||
:desc "Set bookmark (global/project)"
|
||||
"b m" #'gortium/bookmark-set
|
||||
:desc "List project bookmarks"
|
||||
|
||||
Reference in New Issue
Block a user