2

When we open bookmarks panel we see the following:

% Bookmark
- --------
  mark-1                         ~/work/file-1.txt
  mark-2                         ~/work/file-2.txt
  ...
  mark-n                         ~/work/file-n.txt

So, to open n-th file I need to click <Down> key n times, algorithm complexity O(n). Supposing, that n < 10, can we attach the keys from 0 to 9 to the appropriate bookmark? So it will look like this:

% Bookmark
- --------
0  mark-1                         ~/work/file-1.txt
1  mark-2                         ~/work/file-2.txt
  ...
9  mark-9                         ~/work/file-9.txt

When the user clicks the key <n>, the appropriate file is opened immediately. In this case the complexity becomes O(1) - the user needs to make 1 action.

Or widening the idea: the user can attach hotkeys to bookmarks, making the number of bookmarks pretty big:

% Bookmark
- --------
0  mark-1                         ~/work/file-1.txt
1  mark-2                         ~/work/file-2.txt
a  mark-a                         ~/work/file-a.txt
b  mark-b                         ~/work/file-b.txt
  ...
z  mark-9                         ~/work/file-z.txt
  • A common approach for quickly getting to a specific bookmark is to use bookmark-jump (or some variation of that command) with a completion/narrowing framework like ivy, helm, or ido. – glucas Oct 15 '15 at 15:10
  • Also not really an answer, but note that you can use a prefix argument to jump down n lines rather than repeating the down command. For example: C-8 C-n in the Bookmarks List buffer (or most other buffers) will jump down 8 lines. – glucas Oct 15 '15 at 15:14
  • I don't know how to but should be possible with something like avy backend @abo-abo. – Kaushal Modi Oct 15 '15 at 15:54
  • @kaushalmodi To go that route, I'd take a look at the avy-backed implementation of ace-link. That includes a number of commands to jump to "visible links" of various kinds. Should be fairly straightforward to add a variant for bookmarks in the list buffer. (Actually -- just use avy-goto-line....) – glucas Oct 15 '15 at 18:11
  • @glucas "just use avy-goto-line" Duh, of course! :) – Kaushal Modi Oct 15 '15 at 18:34
4

Are you interested in using only the *Bookmark List* display to jump to bookmarks, or are you interested in jumping to them from any buffer?

If the former, you can bind the keys you want (0 to 9 or whatever) in bookmark-bmenu-mode-map to commands that jump to particular bookmarks or to, say, the Nth next bookmark. Or you can just define a command that jumps to the Nth next bookmark, where you provide N as the prefix arg.

For example:

(defun my-jump-to-nth-bookmark (n)
  "Jump to the Nth bookmark after point.
N is the numeric prefix argument."
  (interactive "p")
  (save-excursion
    (next-line n)
    (bookmark-jump (bookmark-bmenu-bookmark))))

But if you just want a quick way to get to the line of a particular bookmark (so you can hit RET there), then you can use C-s (or any of the other, search-related quick-access commands provided by various libraries) or SPC with a prefix arg N to move down N lines.

If the latter, you can bind keys in the global-map to commands that jump to specific bookmarks. Or you can just use bookmark-jump to jump to any bookmark, choosing the bookmark name using completion. If all of your bookmark names have a common prefix such as mark- (I would not recommend that, but that seems to be your case), then completion is as quick as TAB N, e.g., TAB 3.

The general command to jump to a bookmark is bookmark-jump. You can define your own command that jumps to a particular bookmark by passing bookmark-jump that bookmark name:

(defun my-bmk-jump-to-mark-3 ()
  "Jump to bookmark `mark-3'."
  (interactive)
  (bookmark-jump "mark-3"))

Note: Library Bookmark+ offers many more possibilities for using bookmarks than does vanilla Emacs. And as far as completion/narrowing for bookmark commands goes, no library offers as much as does Icicles. In particular, it extends what Bookmark+ offers in many ways.


BTW, your display of *Bookmark List* is wrong, in showing your proposed keys in the % column. That column is used for marking bookmarks (so you can act on them). It does not indicate key bindings. Or if you are proposing that it should show a key that jumps to the bookmark on that line, then you would need to rewrite the code that displays *Bookmark List* accordingly.

More importantly, you would need to establish a convention of association of keys with bookmark names, such as the rudimentary one you show (key 3 corresponds to bookmark name mark-3). You could certainly do that for your own use, but it would not be something that would be useful for others, IMO. Bookmarks take general names for a reason.

  • I want it to be just in the buffer. It would be incorrect to have <9> key to open a buffer for me when I'm editing a file. – user4035 Oct 15 '15 at 18:30
3

Just to highlight another approach from the comments: you can use a library such as ace-jump or avy. These libraries are not specific to bookmarks, but provide a general way to jump to a specific location in the visible window.

For example, with avy you could use the command avy-goto-line. When invoked this command adds a number or character (depending on configuration) to each visible line. You can use that prefix to jump directly to a specific line.

0

Not really a direct answer but you can use register:

(set-register ?e '(file . "~/.emacs"))
(set-register ?b '(file . "~/.bashrc"))
(set-register ?c '(file . "~/.emacs.d/lisp/custom.el"))

Then C-x r j give the list you wants

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.