Function: hi-lock-mode

hi-lock-mode is an autoloaded, interactive and byte-compiled function defined in hi-lock.el.gz.

Signature

(hi-lock-mode &optional ARG)

Documentation

Toggle selective highlighting of patterns (Hi Lock mode).

Hi Lock mode is automatically enabled when you invoke any of the highlighting commands listed below, such as M-s h r (highlight-regexp). To enable Hi Lock mode in all buffers, use global-hi-lock-mode(var)/global-hi-lock-mode(fun) or add (global-hi-lock-mode 1) to your init file.

In buffers where Font Lock mode is enabled, patterns are highlighted using font lock. In buffers where Font Lock mode is disabled, patterns are applied using overlays; in this case, the highlighting will not be updated as you type. The Font Lock mode is considered "enabled" in a buffer if its major-mode causes font-lock-specified-p to return non-nil, which means the major mode specifies support for Font Lock.

When Hi Lock mode is enabled, a "Regexp Highlighting" submenu is added to the "Edit" menu. The commands in the submenu, which can be called interactively, are:

M-s h r (highlight-regexp) REGEXP FACE
  Highlight matches of pattern REGEXP in current buffer with FACE.

M-s h p (highlight-phrase) PHRASE FACE
  Highlight matches of phrase PHRASE in current buffer with FACE.
  (PHRASE can be any REGEXP, but spaces will be replaced by matches
  to whitespace and initial lower-case letters will become case insensitive.)

M-s h l (highlight-lines-matching-regexp) REGEXP FACE
  Highlight lines containing matches of REGEXP in current buffer with FACE.

M-s h . (highlight-symbol-at-point)
  Highlight the symbol found near point without prompting, using the next
  available face automatically.

M-s h u (unhighlight-regexp) REGEXP
  Remove highlighting on matches of REGEXP in current buffer.

M-s h w (hi-lock-write-interactive-patterns)
  Write active REGEXPs into buffer as comments (if possible). They may
  be read the next time file is loaded or when the M-s h f (hi-lock-find-patterns) command
  is issued. The inserted regexps are in the form of font lock keywords.
  (See font-lock-keywords.) They may be edited and re-loaded with M-s h f,
  any valid font-lock-keywords form is acceptable. When a file is
  loaded the patterns are read if hi-lock-file-patterns-policy is
  always, or if it's ask and the user responds y to the prompt,
  or if hi-lock-file-patterns-policy is bound to a function and that
  function returns t.

M-s h f (hi-lock-find-patterns)
  Re-read patterns stored in buffer (in the format produced by M-s h w (hi-lock-write-interactive-patterns)).

When hi-lock is started and if the mode is not excluded or patterns rejected, the beginning of the buffer is searched for lines of the form:
  Hi-lock: (FOO ...)

where (FOO ...) is a list of patterns. The patterns must start before position (number of characters into buffer) hi-lock-file-patterns-range. Patterns will be read until Hi-lock: end is found. A mode is excluded if it's in the list hi-lock-exclude-modes.

This is a minor mode. If called interactively, toggle the Hi-Lock mode mode. If the prefix argument is positive, enable the mode, and if it is zero or negative, disable the mode.

If called from Lisp, toggle the mode if ARG is toggle. Enable the mode if ARG is nil, omitted, or is a positive number. Disable the mode if ARG is a negative number.

To check whether the minor mode is enabled in the current buffer, evaluate the variable hi-lock-mode(var)/hi-lock-mode(fun).

The mode's hook is called both when the mode is enabled and when it is disabled.

View in manual

Probably introduced at or before Emacs version 22.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/hi-lock.el.gz
;; Visible Functions

;;;###autoload
(define-minor-mode hi-lock-mode
  "Toggle selective highlighting of patterns (Hi Lock mode).

Hi Lock mode is automatically enabled when you invoke any of the
highlighting commands listed below, such as \\[highlight-regexp].
To enable Hi Lock mode in all buffers, use `global-hi-lock-mode'
or add (global-hi-lock-mode 1) to your init file.

In buffers where Font Lock mode is enabled, patterns are
highlighted using font lock.  In buffers where Font Lock mode is
disabled, patterns are applied using overlays; in this case, the
highlighting will not be updated as you type.  The Font Lock mode
is considered \"enabled\" in a buffer if its `major-mode'
causes `font-lock-specified-p' to return non-nil, which means
the major mode specifies support for Font Lock.

When Hi Lock mode is enabled, a \"Regexp Highlighting\" submenu
is added to the \"Edit\" menu.  The commands in the submenu,
which can be called interactively, are:

\\[highlight-regexp] REGEXP FACE
  Highlight matches of pattern REGEXP in current buffer with FACE.

\\[highlight-phrase] PHRASE FACE
  Highlight matches of phrase PHRASE in current buffer with FACE.
  (PHRASE can be any REGEXP, but spaces will be replaced by matches
  to whitespace and initial lower-case letters will become case insensitive.)

\\[highlight-lines-matching-regexp] REGEXP FACE
  Highlight lines containing matches of REGEXP in current buffer with FACE.

\\[highlight-symbol-at-point]
  Highlight the symbol found near point without prompting, using the next
  available face automatically.

\\[unhighlight-regexp] REGEXP
  Remove highlighting on matches of REGEXP in current buffer.

\\[hi-lock-write-interactive-patterns]
  Write active REGEXPs into buffer as comments (if possible).  They may
  be read the next time file is loaded or when the \\[hi-lock-find-patterns] command
  is issued.  The inserted regexps are in the form of font lock keywords.
  (See `font-lock-keywords'.)  They may be edited and re-loaded with \\[hi-lock-find-patterns],
  any valid `font-lock-keywords' form is acceptable.  When a file is
  loaded the patterns are read if `hi-lock-file-patterns-policy' is
  `always', or if it's `ask' and the user responds y to the prompt,
  or if `hi-lock-file-patterns-policy' is bound to a function and that
  function returns t.

\\[hi-lock-find-patterns]
  Re-read patterns stored in buffer (in the format produced by \\[hi-lock-write-interactive-patterns]).

When hi-lock is started and if the mode is not excluded or patterns
rejected, the beginning of the buffer is searched for lines of the
form:
  Hi-lock: (FOO ...)

where (FOO ...) is a list of patterns.  The patterns must start before
position \(number of characters into buffer)
`hi-lock-file-patterns-range'.  Patterns will be read until
Hi-lock: end is found.  A mode is excluded if it's in the list
`hi-lock-exclude-modes'."
  :group 'hi-lock
  :lighter (:eval (if (or hi-lock-interactive-patterns
			  hi-lock-file-patterns)
		      " Hi" ""))
  :global nil
  :keymap hi-lock-map
  (if hi-lock-mode
      ;; Turned on.
      (progn
	(define-key-after menu-bar-edit-menu [hi-lock]
	  (cons "Regexp Highlighting" hi-lock-menu))
	(hi-lock-find-patterns)
        (add-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook nil t)
        ;; Remove regexps from font-lock-keywords (bug#13891).
	(add-hook 'change-major-mode-hook (lambda () (hi-lock-mode -1)) nil t)
	(add-hook 'revert-buffer-restore-functions
		  #'hi-lock-revert-buffer-rehighlight nil t))
    ;; Turned off.
    (when (or hi-lock-interactive-patterns
	      hi-lock-file-patterns)
      (when hi-lock-interactive-patterns
	(font-lock-remove-keywords nil hi-lock-interactive-patterns)
	(setq hi-lock-interactive-patterns nil
	      hi-lock-interactive-lighters nil))
      (when hi-lock-file-patterns
	(font-lock-remove-keywords nil hi-lock-file-patterns)
	(setq hi-lock-file-patterns nil))
      (remove-overlays nil nil 'hi-lock-overlay t)
      (font-lock-flush))
    (define-key-after menu-bar-edit-menu [hi-lock] nil)
    (remove-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook t)
    (remove-hook 'revert-buffer-restore-functions
		 #'hi-lock-revert-buffer-rehighlight t)))