manpagez: man pages & more
info emacs
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

19.8 Interactive Highlighting

Use M-x highlight-changes-mode to enable (or disable) Highlight Changes mode, a minor mode that uses faces (colors, typically) to indicate which parts of the buffer were changed most recently.

Hi Lock mode highlights text that matches regular expressions you specify. For example, you might wish to see all the references to a certain variable in a program source file, highlight certain parts in a voluminous output of some program, or make certain names stand out in an article. Use the M-x hi-lock-mode command to enable (or disable) Hi Lock mode. To enable Hi Lock mode for all buffers, use M-x global-hi-lock-mode or place (global-hi-lock-mode 1) in your ‘.emacs’ file.

Hi Lock mode works like Font Lock mode (see section Font Lock mode), except that you specify explicitly the regular expressions to highlight. You control them with these commands:

C-x w h regexp <RET> face <RET>

Highlight text that matches regexp using face face (highlight-regexp). The highlighting will remain as long as the buffer is loaded. For example, to highlight all occurrences of the word “whim” using the default face (a yellow background) C-x w h whim <RET> <RET>. Any face can be used for highlighting, Hi Lock provides several of its own and these are pre-loaded into a history list. While being prompted for a face use M-p and M-n to cycle through them.

You can use this command multiple times, specifying various regular expressions to highlight in different ways.

C-x w r regexp <RET>

Unhighlight regexp (unhighlight-regexp).

If you invoke this from the menu, you select the expression to unhighlight from a list. If you invoke this from the keyboard, you use the minibuffer. It will show the most recently added regular expression; use M-p to show the next older expression and M-n to select the next newer expression. (You can also type the expression by hand, with completion.) When the expression you want to unhighlight appears in the minibuffer, press <RET> to exit the minibuffer and unhighlight it.

C-x w l regexp <RET> face <RET>

Highlight entire lines containing a match for regexp, using face face (highlight-lines-matching-regexp).

C-x w b

Insert all the current highlighting regexp/face pairs into the buffer at point, with comment delimiters to prevent them from changing your program. (This key binding runs the hi-lock-write-interactive-patterns command.)

These patterns are extracted from the comments, if appropriate, if you invoke M-x hi-lock-find-patterns, or if you visit the file while Hi Lock mode is enabled (since that runs hi-lock-find-patterns).

C-x w i

Extract regexp/face pairs from comments in the current buffer (hi-lock-find-patterns). Thus, you can enter patterns interactively with highlight-regexp, store them into the file with hi-lock-write-interactive-patterns, edit them (perhaps including different faces for different parenthesized parts of the match), and finally use this command (hi-lock-find-patterns) to have Hi Lock highlight the edited patterns.

The variable hi-lock-file-patterns-policy controls whether Hi Lock mode should automatically extract and highlight patterns found in a file when it is visited. Its value can be nil (never highlight), t (highlight the patterns), ask (query the user), or a function. If it is a function, hi-lock-find-patterns calls it with the patterns as argument; if the function returns non-nil, the patterns are used. The default is nil. Note that patterns are always highlighted if you call hi-lock-find-patterns directly, regardless of the value of this variable.

Also, hi-lock-find-patterns does nothing if the current major mode's symbol is a member of the list hi-lock-exclude-modes.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.