2

I would like the ability to go back and forth through a series of stored recent cursor positions, say up to 100 of them. Specifically, a position should be recorded when I click somewhere, or when I do a find operation that causes me to jump to a different location in the file. Ideally, I would be able to go back to the previous stored position, then back forward again through the list of positions, if I choose to do so.

Is there some preexisting way to do this? Alternatively, is there a relatively easy way to design a function to do this? Say, to set hooks for a cursor position change, then update some global array when such a hook is activated?

I don't care whether positions are stored per-buffer or per-window or per-frame (although per-buffer would probably be better).

exchange-point-and-mark sort of does this (after a find operation; doesn't pay attention to mouse click position), on a much smaller scale.

2

You are describing a use case of bookmarks. For example, have a look at the visual bookmark package at https://github.com/joodland/bm. You get functions to toggle bookmarks at point and move back and forth between them. Bind them to keys that are convenient for you.

1

I was going to suggest helm-all-mark-rings in the Helm package. It has been mentioned here previously, along with some other tips. To me it otherwise sounds like you might be interested in bm, which is a way to manually add locations to a file (by mouse or keyboard), which you can then jump between.

1

The simplest option, although it does not keep positions in a ring, is to save positions to registers.

The docstring for the command point-to-register:

It is bound to C-x r SPC, C-x r C-SPC, C-x r C-@.

(point-to-register REGISTER &optional ARG)

Store current location of point in register REGISTER. With prefix argument, store current frame configuration. Use C-x r j to go to that location or restore that configuration. Argument is a character, naming the register.

And the docstring for jump-to-register:

It is bound to C-x r j.

(jump-to-register REGISTER &optional DELETE)

Move point to location stored in a register. If the register contains a file name, find that file. (To put a file name in a register, you must use set-register.) If the register contains a window configuration (one frame) or a frameset (all frames), restore that frame or all frames accordingly. First argument is a character, naming the register. Optional second arg non-nil (interactively, prefix argument) says to delete any existing frames that the frameset doesn't mention. (Otherwise, these frames are iconified.)

  • Is there a way to add a hook that will detect the start and end of a find operation, and/or a mouse click? I'm aware of isearch-mode-end-hook, but no matching "isearch-mode-start-hook" or any hook for mouse click events. – std_answ Dec 16 '16 at 20:16

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.