branch: elpa/javelin
commit bc5bc00020fc9935da9464422b0318192591cffc
Author: Gal Buki <[email protected]>
Commit: Gal Buki <[email protected]>
update-bookmark-on-jump
---
README.md | 10 ++++++++++
javelin.el | 15 ++++++++++++---
2 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 4c112119d2..c930b4db2d 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,8 @@ In `packages.el`:
In `config.el`:
```elisp
(use-package! javelin
+ :custom
+ (javelin-update-bookmark t)
:config
(global-javelin-minor-mode 1))
```
@@ -31,6 +33,8 @@ In `config.el`:
```elisp
(use-package javelin
:ensure t
+ :custom
+ (javelin-update-bookmark t)
:config
(global-javelin-minor-mode 1))
```
@@ -44,6 +48,12 @@ In `config.el`:
| `M-0 1` to `M-0 9` | Delete position |
| `M--` | Quick menu to select from all javelined buffers |
+## Configuration
+
+| Variable | Description |
+|----------|-------------|
+| `javelin-update-bookmark` | When non-nil, automatically update cursor
position when jumping between javelin positions. Default is `nil`. |
+
## Key Features
- Jump to any pinned buffer with a single keystroke (M-1 through M-9)
diff --git a/javelin.el b/javelin.el
index 93117ed114..155961e782 100644
--- a/javelin.el
+++ b/javelin.el
@@ -59,6 +59,10 @@ The namespace helps isolate javelin positions for different
contexts."
(defcustom javelin-disable-confirmation nil
"If non-nil, skip confirmation prompts for destructive actions."
:type 'boolean)
+
+(defcustom javelin-update-bookmark nil
+ "When non-nil, automatically save cursor position when switching javelins."
+ :type 'boolean)
;;; --- Customizable variables ---
(defconst javelin--bookmark-prefix "javelin:"
@@ -83,7 +87,7 @@ The namespace helps isolate javelin positions for different
contexts."
(defun javelin--get-project-root ()
"Get the project root.
Returns the project root path as a string, or nil if there is no project."
- (when-let ((proj (project-current)))
+ (when-let* ((proj (project-current)))
(expand-file-name (project-root proj))))
(defun javelin--get-project-name ()
@@ -107,7 +111,7 @@ Returns nil if not in a git repository."
(defun javelin--bookmark-namespace ()
"Namespace for javelin bookmark names."
(let ((project-name (or (javelin--get-project-name)
javelin-default-positions-namespace)))
- (if-let ((branch (and javelin-separate-by-branch
(javelin--get-branch-name))))
+ (if-let* ((branch (and javelin-separate-by-branch
(javelin--get-branch-name))))
(format "%s#%s" project-name branch)
project-name)))
@@ -165,6 +169,11 @@ Returns nil if not in a git repository."
"Go to specific file or buffer of the javelin by JAVELIN-NUMBER."
(interactive "nJavelin position: ")
(javelin--ensure-bookmarks-loaded)
+ ;; Update current buffer's cursor position if enabled
+ (when-let* ((_ javelin-update-bookmark)
+ (current-pos (javelin--position-for-current-buffer)))
+ (bookmark-set (javelin--bookmark-name current-pos))
+ (javelin--bookmark-save-silent))
(let ((name (javelin--bookmark-name javelin-number)))
(if (bookmark-get-bookmark name 'noerror)
(bookmark-jump name)
@@ -498,7 +507,7 @@ DIRECTION should be 1 for next, -1 for previous."
(complete-with-action action candidate-strings string
pred)))))
(if (null candidates)
(message "No javelin positions set.")
- (when-let ((selection (completing-read "Javelin to file: " collection)))
+ (when-let* ((selection (completing-read "Javelin to file: " collection)))
(let ((pos (cdr (assoc selection candidates))))
(javelin-go-to pos))))))