Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlighting lines in emacs

I am using an IM which does not support viewing previous chat history nor can I change my IM. So I have to copy the chat into a text file everytime.

I am using Emacs.Is there some way by which I can highlight the lines which contain the participant names as below?

===> **[Vivek Kumar]**  
Hi, how are you doing!  
===> **[Mr X Y Z]**    
fine  
===> **[Vivek Kumar]**  
sdfksd;fks;

EDIT 1:

Earlier when I'd access to gvim, I would use the highlight.vim plugin.

like image 733
Vivek Kumar Avatar asked Oct 11 '13 04:10

Vivek Kumar


1 Answers

Emacs supports highlighting of lines or phrases. You can use one of highlight-lines-matching-regexp, highlight-phrase, or highlight-regexp. I'm sure there are several others too.

To try this, paste your text into the editor, press ESC-x (or Alt-x might work too) to enter the "mini-buffer" at the bottom of the editor window, and enter one of the above commands.

For example, I tried: highlight-lines-matching-regexp and entered the regexp "\[.*\]" and made it match the names in your example. Here's a screenshot:

Just after running highlight-lines-matching-regexp

You can tweak this expression to fit your needs. Some links to regular expressions in emacs:

  • http://www.emacswiki.org/emacs/RegularExpression
  • This question on SO: Good tutorial + reference for Emacs search and replace?

Of course you could also use highlight-phrase and just highlight a simple string of text (instead of messing with regexes).

Here's one where I ran highlight-phrase and entered the two separate names and gave them different colors (hi-yellow and hi-red):

After running highlight-phrase

Finally you can then run unhighlight-regexp to clear out the highlighting.

like image 117
scorpiodawg Avatar answered Nov 14 '22 19:11

scorpiodawg