1

I am wondering why it is so difficult to go back when you mix local and global jumps in Emacs. Maybe I am missing something. For example, if I am in buffer 1 and jump to position 100 (for example using a search command or a bookmark jump), then jump to position 1000, then I jump to buffer 2 position 500 (using for example a bookmark jump).

If I now want to backtrace this history of jumps, I first need to know that I should be using the global mark ring (not the local) to jump to buffer 1, then I will end up at position 100 in buffer 1 (not position 1000 as I wanted), so I need to access the local mark ring for buffer 1, to get to my desired position. This is far from ideal, I would like to avoid having to think about local vs global mark ring when I go back, and I would like to go back to the previous location, whether it is in the current buffer or in some other buffer.

By the way, I am using helm-all-mark-rings for this kind of movement.

The solution provided by backbutton involves "abusing" the global mark ring to also record local jumps. Is this safe to do, and will it work with helm-global-mark-ring? Are there built-in methods that I have missed?

See also kozikow/back.el

1 Answer 1

1

If you can choose among markers in all buffers then you need to be able to choose one, and that means identifying the buffer and the marker in it that you want. That is, I believe, the answer to your question of why it is so difficult to navigate among all such markers.

If you use Icicles then you can use command icicle-goto-any-marker, bound by default to C-0 C-SPC, to do what you want. It provides, as completion candidates, the markers in all buffers.

More precisely, if option icicle-show-multi-completion-flag is non-nil, which it is by default, then a completion candidate is a multi-completion with two parts:

  • The name of the marker's buffer
  • Text from the beginning of the marker's line

icicle-goto-any-marker is an interactive compiled Lisp function in icicles-cmd2.el.

(icicle-goto-any-marker)

Like icicle-goto-marker, but lets you visit markers in all buffers.

If user option icicle-show-multi-completion-flag is non-nil, then each completion candidate is has two parts, the first of which is the name of the marker's buffer, and the second of which is the text from the marker's line.

By default, candidates are sorted in buffer order and then marker order, that is, buffer positions. Use C-M-, or C-, to change the sort order. Remember too that you can use C-A to toggle case-sensitivity (e.g., for buffer names).

See also command icicle-goto-global-marker.

The default order of the completion candidates is buffer followed by marker position. That means that you can easily navigate among them (e.g. cycle) in marker-position order. But you can use C-, to change the sort order to, for example, the order of last use as input. (You can also define whatever other sort order you find most convenient.)

That says that the command is like command icicle-goto-marker (which is bound by default to C-SPC with a negative prefix arg). It's doc string tells you about cycling among completion candidates, i.e., moving among the marked positions in order.

icicle-goto-marker is an interactive compiled Lisp function in icicles-cmd2.el.

(icicle-goto-marker)

Go to a marker in this buffer, choosing it by the line that includes it.

If crosshairs.el is loaded, then the target position is highlighted.

By default, candidates are sorted in marker order, that is, with respect to their buffer positions. Use C-M-, or C-, to change the sort order.

During completion you can use these keys:

C-RET - Goto marker named by current completion candidate

C-down - Goto marker named by next completion candidate

C-up - Goto marker named by previous completion candidate

C-next - Goto marker named by next apropos-completion candidate

C-prior - Goto marker named by previous apropos-completion candidate

C-end - Goto marker named by next prefix-completion candidate

C-home - Goto marker named by previous prefix-completion candidate

S-delete - Delete marker named by current completion candidate

When candidate action and cycling are combined (e.g. C-next), option icicle-act-before-cycle-flag determines which occurs first.

With prefix C-M- instead of C-, the same keys (C-M-mouse-2, C-M-f1, C-M-down, and so on) provide help about candidates.

Use mouse-2, RET, or S-RET to choose a candidate as the final destination, or C-g to quit. This is an Icicles command - see command icicle-mode.

See also commands icicle-goto-any-marker and icicle-goto-global-marker.

4
  • Can this icicle-goto-any-marker be sorted by time? If not, then I don't understand how this answers OP question? Commented Jun 23 at 12:21
  • @JasonHunter: You can sort the completion candidates in many ways. By default: (1) alphabetical, (2) by buffer, then by position, (3) by flx score, (4) by last use as input, (5) by previous use alphabetically, (6) case insensitive, (7) extra candidates first, (8) special candidates first, (9) turned OFF. But yes, it might help for this (and other goto-marker commands) to add a sort order that sorts by marker-creation/change time. However, markers don't record the time of their creation or last repositioning, and doing that separately wouldn't be worth it just for this (IMO).
    – Drew
    Commented Jun 23 at 16:54
  • Wouldn't it be the only way to solve OP problem;). If there is no timestamp, then there can be no line of history, making it impossible to "backtrace" as OP says. Commented Jun 23 at 19:55
  • @JasonHunter: Maybe, for a strict, visit all positions, in order, interpretation of "backtrace". I don't see a one-by-one, timestamp ordered navigation in the question. All markers were created or updated in the past, so visiting them - in whatever order, is going back to previous positions. If you want to choose where to jump, and the choices show portions of buffer text or another easy way to identify them, you can explore the positions pretty easily. Is the time of visiting important - I don't see that in the question. Anyway, if this answer doesn't help then maybe another will.
    – Drew
    Commented Jun 24 at 3:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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