3

Is there an Emacs feature for highlighting some lines in a file to make it easier to jump around? My immediate use-case is a gigantic auto-generated C++ file with horrible indentation, which is rather difficult to navigate and it's easy to get lost. At the moment, I'm adding comments of the form // LOC-1 to find where I've just been, but that feels a bit icky.

I know that some other text editors have this tied in with their bookmark mechanism (sublime text?) and you can add a blue blob to the left gutter. Maybe there's a way to show Emacs bookmarks in the gutter? Or maybe there's a different feature that shows something like this or highlighted lines?

I'm not concerned with this persisting across closing and opening the file, or with multiple buffers viewing it: either persistent or not is fine with me.

Is there an easy way for me to leave myself some "breadcrumbs"?

1
  • The answer I gave is more in line with your question, however, I wanted to mention evil-mode which emulates vim. This allows you to set "invisible" marks. For example mm would create a mark named "m" and ma would create a mark called "a". You could then navigate to line "m" with 'm and navigate to line "a" with 'a. You could navigate to the marked position on "m" with `m and the marked position on "a" with `a. Of course, evil has a learning curve. Commented Feb 6, 2019 at 13:46

2 Answers 2

6

There are several ways to do this. One of my preferred methods is the bm package. The package provides visual bookmarks:

enter image description here

The setup is dead simple:

(require 'bm)
(global-set-key (kbd "<C-f2>") 'bm-toggle)
(global-set-key (kbd "<f2>")   'bm-next)
(global-set-key (kbd "<S-f2>") 'bm-previous)

You can change the color of the bookmark with

(set-face-attribute 'bm-face nil :background "RoyalBlue4" :foreground 'unspecified)

Use the list-colors command to find something more suitable to your theme than RoyalBlue4.

1
  • 1
    I'd recommend to use instead of C-f2 better s-f2 as C-f2 is set to switch Desktops in some Linux versions
    – Qohelet
    Commented May 15, 2019 at 12:06
1

bm.el may do what you request, but Bookmark+ does everything that bm.el does, and much more. And it uses the same kind of bookmarks that vanilla Emacs uses. Emacs bookmarks record more information than just a location.

Relevant to your request, you can have:

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.