How do I highlight a region and it make it remain highlighted when point moves on.

Why would I want that? So I can make important snippets of code stand out when I review it later.

  • Bookmarks are probably what you want to check into. I don't know how to bookmark a region, but I regularly use bm-toggle to create a bookmark at the point. – ebpa Feb 7 '17 at 20:11
up vote 6 down vote accepted
  1. Library Highlight (highlight.el) lets you highlight any number of regions in various ways, including using regexps, using any number of faces.

    One easy way to highlight an expanse of text (and have it persist until you remove it) is to sweep your mouse over it - like using a highlighter pen. This is command hlt-highlighter. By default, the command is bound to C-x down-mouse-2, which means that you use it by hitting C-x and then pressing and dragging mouse-2 (the second or middle mouse button) across the text. With a prefix argument (i.e., C-u C-x + drag mouse-2) you are prompted for the face to use.

  2. A quick and easy way to highlight a single region of text, and have that highlighting persist until you put it on a different region, is to use the secondary selection.

    For that, just press and hold the Meta key (typically Alt) while you drag mouse-1.

    If you use library second-sel.el then you can access any number of such secondary selections on a ring, among other features.

  • 1
    secondary selection is really cool. didn't know about it before this – bernie Feb 8 '17 at 17:17

Are you looking for hi-lock-mode? You can highlight matching regexps or highlight regions by using highlight-phrase: C-x w p phrase RET face RET.

https://www.gnu.org/software/emacs/manual/html_node/emacs/Highlight-Interactively.html

  • 1
    +1, I use these commands a lot. By default the hi-lock commands are bound with a M-s h prefix, so you can use M-s h C-h to see a list of related commands. Also worth noting you can save the current set of highlighted patterns to the current file, so that you can restore them later. – glucas Feb 7 '17 at 21:14

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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