fix: bookmark-bmenu-list with file-switch, restore on quit

This commit is contained in:
2026-07-17 16:56:20 -04:00
parent 994216e32a
commit 84006b4412
2 changed files with 32 additions and 26 deletions

View File

@@ -3683,24 +3683,27 @@ Project bookmarks go to .bookmarks file in project root."
;; Bindings ;; Bindings
(defun gortium/list-project-bookmarks () (defun gortium/list-project-bookmarks ()
"Pick and jump to a project bookmark via completing-read. "Show project bookmark menu. Switches to .bookmarks, restores globals on quit."
Never touches global bookmark-alist."
(interactive) (interactive)
(if (not (projectile-project-p)) (if (not (projectile-project-p))
(user-error "Not in a project") (user-error "Not in a project")
(let* ((proj-file (expand-file-name ".bookmarks" (projectile-project-root))) (let* ((proj-file (expand-file-name ".bookmarks" (projectile-project-root)))
(proj-bms (and (file-exists-p proj-file) (saved-alist (copy-tree bookmark-alist))
(with-temp-buffer (saved-file bookmark-default-file))
(insert-file-contents proj-file) (if (not (file-exists-p proj-file))
(ignore-errors (read (current-buffer)))))))
(if (not proj-bms)
(message "No .bookmarks file in this project.") (message "No .bookmarks file in this project.")
(let* ((names (mapcar (lambda (b) (if (consp b) (car b) b)) proj-bms)) ;; Switch to project bookmarks
(choice (completing-read "Project bookmark: " names nil t))) (setq bookmark-default-file proj-file)
(when choice (bookmark-load proj-file t)
;; Temporarily set bookmark-alist to project bookmarks for the jump (bookmark-bmenu-list)
(let ((bookmark-alist proj-bms)) ;; Restore on quit
(bookmark-jump choice)))))))) (with-current-buffer "*Bookmark List*"
(add-hook 'kill-buffer-hook
(lambda ()
(ignore-errors (bookmark-save))
(setq bookmark-default-file saved-file)
(setq bookmark-alist saved-alist))
nil t))))))
(map! :leader (map! :leader
:desc "Set bookmark (global/project)" :desc "Set bookmark (global/project)"

View File

@@ -2753,24 +2753,27 @@ Project bookmarks go to .bookmarks file in project root."
;; Bindings ;; Bindings
(defun gortium/list-project-bookmarks () (defun gortium/list-project-bookmarks ()
"Pick and jump to a project bookmark via completing-read. "Show project bookmark menu. Switches to .bookmarks, restores globals on quit."
Never touches global bookmark-alist."
(interactive) (interactive)
(if (not (projectile-project-p)) (if (not (projectile-project-p))
(user-error "Not in a project") (user-error "Not in a project")
(let* ((proj-file (expand-file-name ".bookmarks" (projectile-project-root))) (let* ((proj-file (expand-file-name ".bookmarks" (projectile-project-root)))
(proj-bms (and (file-exists-p proj-file) (saved-alist (copy-tree bookmark-alist))
(with-temp-buffer (saved-file bookmark-default-file))
(insert-file-contents proj-file) (if (not (file-exists-p proj-file))
(ignore-errors (read (current-buffer)))))))
(if (not proj-bms)
(message "No .bookmarks file in this project.") (message "No .bookmarks file in this project.")
(let* ((names (mapcar (lambda (b) (if (consp b) (car b) b)) proj-bms)) ;; Switch to project bookmarks
(choice (completing-read "Project bookmark: " names nil t))) (setq bookmark-default-file proj-file)
(when choice (bookmark-load proj-file t)
;; Temporarily set bookmark-alist to project bookmarks for the jump (bookmark-bmenu-list)
(let ((bookmark-alist proj-bms)) ;; Restore on quit
(bookmark-jump choice)))))))) (with-current-buffer "*Bookmark List*"
(add-hook 'kill-buffer-hook
(lambda ()
(ignore-errors (bookmark-save))
(setq bookmark-default-file saved-file)
(setq bookmark-alist saved-alist))
nil t))))))
(map! :leader (map! :leader
:desc "Set bookmark (global/project)" :desc "Set bookmark (global/project)"