3

Often when fixing a bug or implementing a new feature in a code repository, I start off with an investigatory step.

For example, I would have a lead, a word such as "Article" and I would start by grepping the codebase for "Article". Suppose there are 5 files that contain the word. I would open up one of these files with emacs. Reading the file, I would learn that the code in that file is just a "wrapper" function, and the real meat of the work happens in another place (the parent/caller function) This step would repeat for about a dozen times until I found what I'm looking for. Sometimes I don't find what I'm looking for. Sometimes on a 10 step exploration ( 10 files opened up consecutively) I would decide to take 4 steps back, and branch off in another direction/idea.

Four days later I would be in the shower and have a thought flash, and would want to revisit/retrace my steps but the emacs instance has long been killed.

Is bookmarks.el the answer? Or are there better ways to wander down rabbit holes with emacs.

american-ninja-warrior
  • 3,773
  • 2
  • 21
  • 40
  • If you use `M-.` to jump to definitions, you can use `M-,` to go back to where you've looked for the definition. There's also the mark ring, which has the limitation to being separate for each buffer. –  Jul 25 '19 at 17:43
  • your answer was quite helpful, ,maybe you want to write it as an answer. – american-ninja-warrior Aug 07 '19 at 00:47

2 Answers2

1

Yes, Emacs bookmarks are a good answer for getting back to places later (and for restoring contexts later).

But that means that you need to create a bookmark, e.g., perhaps guessing that you might want to get back to the current place.

If you use Bookmark+ then you can optionally have Emacs create bookmarks automatically whenever Emacs is idle for a given time period. You might or might not like to turn this on, e.g., when working on some code that you expect you might want to get back to.


Another part of your question mentions grepping for some code fragment. Another possibility is to try for a better grep search string: one that will avoid just "wrapper" code -- if that's possible.

Or you can maybe try using a different kind of search than just grep (which is line-oriented). For instance, if you use library isearch-prop.el then you can search the zones of text that match a given regexp, using command isearchp-regexp-context-search or isearchp-regexp-context-regexp-search. In other words, don't use individual lines as search contexts; define the contexts to search as the text that matches a regexp. (A similar feature is available with Icicles search.)

Drew
  • 75,699
  • 9
  • 109
  • 225
  • After reading https://www.emacswiki.org/emacs/BookmarkPlus , Im very excited about trying it out in the coming days/weeks. I wish the bookmarks list had a way to change the view when pressing backtrack, so for example show tags, annots. as columns in the list. dired sometimes makes use of backtick like that. – american-ninja-warrior Jul 26 '19 at 16:58
1

You can use M-. to jump to definitions, and M-, to jump back to places you've looked from.

There's M-?, which can be used to find references in a project.

You can also use the mark ring to go back to places you've marked (for instance with C-SPC, or by using isearch) before, but this is limited to a buffer. You can pop the ring with C-u C-SPC. This can be handy, when you need to import something you're about to use before you get back to what you were writing as well.