From 994216e32a0e968b4840537946c187377350408f Mon Sep 17 00:00:00 2001 From: Thierry Pouplier Date: Fri, 17 Jul 2026 16:52:35 -0400 Subject: [PATCH] fix: completing-read for project bookmarks, no alist contamination --- doom/.config/doom/README.org | 50 ++++++++++-------------------------- doom/.config/doom/config.el | 50 ++++++++++-------------------------- 2 files changed, 26 insertions(+), 74 deletions(-) diff --git a/doom/.config/doom/README.org b/doom/.config/doom/README.org index 9efc603..290aa6b 100644 --- a/doom/.config/doom/README.org +++ b/doom/.config/doom/README.org @@ -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" diff --git a/doom/.config/doom/config.el b/doom/.config/doom/config.el index fd6b2f7..babb210 100644 --- a/doom/.config/doom/config.el +++ b/doom/.config/doom/config.el @@ -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"