From e0264f03bb27de8e2545eac603e490f877a6022b Mon Sep 17 00:00:00 2001 From: Boruch Baum Date: Thu, 29 Apr 2021 21:14:37 -0400 Subject: [PATCH 1/2] New feature: bb-jump: quickly navigate directly to any bm --- bm.el | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/bm.el b/bm.el index c06597b..634439d 100644 --- a/bm.el +++ b/bm.el @@ -359,6 +359,11 @@ over overlays with lower priority. *Don't* use a negative number." "Face used to highlight bookmarks in the fringe if bookmark is persistent." :group 'bm) +(defface bm-file-name-face '((t :foreground "yellow")) + "File name's face for display in function `bm-jump'.") + +(defface bm-line-num-face '((t :foreground "green")) + "Line number's face for display in function `bm-jump'.") (defcustom bm-annotate-on-create nil "*Specify if bookmarks must be annotated when created. @@ -555,6 +560,42 @@ before bm is loaded.") (interactive) (customize-group 'bm)) +(defun bm-jump () + "Jump directly to any bookmark. +Presents the bookmark list in the form of completion candidates +in the minibuffer for quick navigation." + (interactive) + (let* ((minibuffer-history '("")) + (bookmarks (bm-overlays-lifo-order 'all)) + (file-line-width (bm-find-file-line-max-width bookmarks 'all)) + (format-string (format "%%-%ds %%-%ds" file-line-width bm-annotation-width)) + (elements + (mapcar + (lambda (bm) + (with-current-buffer (overlay-buffer bm) + (let ((annot (overlay-get bm 'annotation)) + (line-num (number-to-string + (+ 1 (count-lines (point-min) (overlay-start bm)))))) + (list (format "%s:%s" + (propertize (buffer-name) 'face 'bm-file-name-face) + (propertize line-num 'face 'bm-line-num-face)) + (or annot "") + bm)))) + bookmarks)) + (candidates + (mapcar (lambda (elem) + (list (format format-string (nth 0 elem) (nth 1 elem)) + (nth 2 elem))) + elements)) + decision) + (while (or (not decision) + (zerop (length decision))) + (setq decision + (completing-read + "Jump to bookmark: " + (mapcar 'car candidates) nil t))) + (when (setq decision (assoc decision candidates)) + (goto-char (overlay-start (cadr decision)))))) (defun bm-bookmark-annotate (&optional bookmark annotation) "Annotate bookmark at point or the BOOKMARK specified as parameter. @@ -624,7 +665,7 @@ Either the bookmark at point or the BOOKMARK specified as parameter." If ANNOTATION is provided use this, and do not prompt for input. Only used if `bm-annotate-on-create' is true. -TIME is useful when `bm-in-lifo-order' is not nil. +TIME is useful when `bm-in-lifo-order' is not nil. if TEMPORARY-BOOKMARK not nil,the bookmark will be removed when `bm-next' or `bm-previous' navigate to this bookmark." @@ -687,7 +728,7 @@ EV is the mouse event." (mouse-set-point ev) (bm-toggle))) - + (defun bm-modeline-info nil "Display information about the number of bookmarks in the current buffer. Format depends on `bm-modeline-display-total' and From 494b0acf60f7570a2e492c84c751c228bb6e5436 Mon Sep 17 00:00:00 2001 From: Boruch Baum Date: Wed, 5 May 2021 21:08:44 +0000 Subject: [PATCH 2/2] Fix support for other than the currently selected buffer --- bm.el | 1 + 1 file changed, 1 insertion(+) diff --git a/bm.el b/bm.el index 634439d..c60c1cc 100644 --- a/bm.el +++ b/bm.el @@ -595,6 +595,7 @@ in the minibuffer for quick navigation." "Jump to bookmark: " (mapcar 'car candidates) nil t))) (when (setq decision (assoc decision candidates)) + (pop-to-buffer (overlay-buffer (cadr decision))) (goto-char (overlay-start (cadr decision)))))) (defun bm-bookmark-annotate (&optional bookmark annotation)