10

I am searching for a way to highlight selected text in Emacs permanently, just like you do with a marker in a PDF for example. I am using org-mode.

I tried searching on Google but was quite surprised that I didn't find anything.

legoscia
  • 39,593
  • 22
  • 116
  • 167
user2664856
  • 630
  • 14
  • 30
  • This is not a programming question, is it? It should therefore be posted in superuser.com, not here. – Robin Green Nov 16 '13 at 09:05
  • 1
    sounds logically, but arent most questions about emacs like this one? and there are quiet a lot of them on this site. – user2664856 Nov 16 '13 at 09:07
  • Also, emacs can be used for programming tasks. But using org-mode is not a programming task, or at least not specific to programming. – Robin Green Nov 16 '13 at 09:10
  • if emacs does not provide this funcionality, maybe i will add it ;) – user2664856 Nov 16 '13 at 09:11
  • OK, then: emacs does not provide this functionality for org-mode files. – Robin Green Nov 16 '13 at 09:11
  • are you sure about that, and does this apply for emacs in genral ? i can hardly believe this. – user2664856 Nov 16 '13 at 09:12
  • Emacs is a text editor, not a word processor like Microsoft Word. Although emacs has an optional GUI, inside the actual text editor part of the user interface it's basically just a text editor. It does have the ability to display images, but this is not a core focus of emacs development. – Robin Green Nov 16 '13 at 09:14
  • This question appears to be off-topic because it is not about programming as described in the FAQ. – Robin Green Nov 16 '13 at 09:16
  • i am not talking about highlights beeing a core focus, but a nice-to-have feature someone added – user2664856 Nov 16 '13 at 09:16
  • sorry for being off-topic, but i dont want to delete this question, or user2708138 will lose his reputation on this question, and it is in fact a good answer. – user2664856 Nov 16 '13 at 09:17
  • 4
    Hmmm. Reading SO [on-topic page](http://stackoverflow.com/help/on-topic) (again), I don't think this question is off-topic. The question is about *software tools commonly used by programmers*, and as far as I see, it is related to the programmable nature of Emacs. – Ha-Duong Nguyen Nov 16 '13 at 09:24
  • i really appreciate how some people participate on this site. thank you all.
    in the end its about providing information, itsn't it? and i think this question and especially the answers are useful to the community :)
    – user2664856 Nov 16 '13 at 09:27

2 Answers2

15

In org-mode you can use *word* to get word in bold face, /word/ to get word in italics and _word_ to get word underlined.

You can re-define the characters for emphasizing via Options->Customize Emacs->Specific Option then input org-emphasis-alist.

That is permanent in the sense that if you save and kill the buffer and reload the file into emacs you have the same high-lighting again.

Another way is to use enriched-mode. Input M-x enriched-mode. If font-lock-mode is not activated you can use stuff like Edit->Text Properties->Face->Bold and the formatting is permanent in the text-file. It is clear that this leaves traces in the text file. You can see these traces if you load the file via M-x find-file-literally.

Note, that for easier formatting in the X11-port (I think also in the win32-port) you can detach the menus by clicking on the broken line on top (see the right side of the following image for two of such detached menus).

font-lock-mode re-fontifies text with rules from parameters like font-lock-keywords automatically and removes all other fontification (these parameters are most often set by the major-mode). Therefore, text properties do not work if font-lock-mode is activated. org-mode uses font-lock-mode, and text properties from Edit->Text Properties->Face->Bold cannot be used with org-mode (the corresponding menu items are deactivated). You can check whether font-lock-mode is active with C-h m. It is active if Font-Lock is listed. Alternatively, you can query C-h v font-lock-mode which is t if font-lock-mode is active. Fontified text in enriched-mode

Tobias
  • 5,038
  • 1
  • 18
  • 39
  • the answer is getting better and better :) – user2664856 Nov 16 '13 at 09:27
  • 2
    Indeed. You might want to check out [this Stack Overflow question](http://stackoverflow.com/questions/3903137/emacs-persistent-highlighting-of-a-region). – Ha-Duong Nguyen Nov 16 '13 at 09:35
  • It's nice to know enriched-mode, but after `M-x enriched-mode`, the menu in `Edit->Text Properties->Face...` of my Emacs is impossible to be enabled, it's grey, both in normal `emacs` or `emacs -q`, I googled, but I couldn't find anything. – CodyChan Dec 30 '14 at 01:54
  • @CodyChan Works fine for me with `emacs -Q`. The command `emacs -q` loads the customization file `site-start.el` if one exists within your `load-path`. My emacs-version is: `GNU Emacs 24.3.1 (i686-pc-linux-gnu, GTK+ Version 3.10.7) of 2014-03-07 on toyol, modified by Debian`. – Tobias Dec 30 '14 at 07:13
  • @Tobias not work for me even in `emacs -Q` emacs-version:`GNU Emacs 24.4.1 (i686-redhat-linux-gnu, GTK+ Version 3.14.5) of 2014-11-19 on buildvm-13.phx2.fedoraproject.org`, OS: `Fedora 21(3.17.4-301.fc21.i686+PAE)`. I download tar file from Gnus page and extract and execute the binary with `-Q`, it doesn't work as well. – CodyChan Dec 30 '14 at 07:17
  • @CodyChan Note, that a disabled face menu might be a sign for activated `font-lock-mode`. You might test it with `M-x font-lock-mode`. – Tobias Dec 30 '14 at 07:18
  • @Tobias yes, `font-lock-mode` is the problem. I already found the solution without using `enriched-mode`(since I always enable `font-lock-mode`). Add color to the `bold` markup in `org-emphasis-alist` would be better. – CodyChan Dec 30 '14 at 07:31
  • @CodyChan I added a note on `font-lock-mode`. – Tobias Dec 30 '14 at 09:31
5

You can use some commands from hi-lock-mode:

  • highlight-regexp will ask you for a regexp to highlight and a color (there are some combinations of background and foreground)
  • highlight-lines-matching-regexp does what it means
  • you can enable or disable it with hi-lock-mode

and you can permanently save them with hi-lock-write-interactive-patterns (M-s h w). Emacs will write a bit of lisp in a commented line in your buffer.

See more tricks here: https://www.gnu.org/software/emacs/manual/html_node/emacs/Highlight-Interactively.html

http://www.masteringemacs.org/articles/2010/10/13/highlighting-by-word-line-regexp/

Enjoy !

Ehvince
  • 17,274
  • 7
  • 58
  • 79