Function: hi-lock-unface-buffer

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

Signature

(hi-lock-unface-buffer REGEXP)

Documentation

Remove highlighting of each match to REGEXP set by hi-lock.

Interactively, prompt for REGEXP, accepting only regexps previously inserted by hi-lock interactive functions. If REGEXP is t (or if C-u (universal-argument) was specified interactively), then remove all hi-lock highlighting.

Key Bindings

Aliases

unhighlight-regexp

Source Code

;; Defined in /usr/src/emacs/lisp/hi-lock.el.gz
;;;###autoload
(defun hi-lock-unface-buffer (regexp)
  "Remove highlighting of each match to REGEXP set by hi-lock.
Interactively, prompt for REGEXP, accepting only regexps
previously inserted by hi-lock interactive functions.
If REGEXP is t (or if \\[universal-argument] was specified interactively),
then remove all hi-lock highlighting."
  (interactive
   (cond
    (current-prefix-arg (list t))
    ((and (display-popup-menus-p)
          last-nonmenu-event
          (listp last-nonmenu-event)
          use-dialog-box)
     (catch 'snafu
       (or
        (x-popup-menu
         t
         (cons
          'keymap
          (cons "Select Pattern to Unhighlight"
                (mapcar (lambda (pattern)
                          (let ((lighter
                                 (or (car (rassq pattern hi-lock-interactive-lighters))
                                     (car pattern))))
                            (list lighter
                                  (format
                                   "%s (%s)" lighter
                                   (hi-lock-keyword->face pattern))
                                  (cons nil nil)
                                  lighter)))
                        hi-lock-interactive-patterns))))
        ;; If the user clicks outside the menu, meaning that they
        ;; change their mind, x-popup-menu returns nil, and
        ;; interactive signals a wrong number of arguments error.
        ;; To prevent that, we return an empty string, which will
        ;; effectively disable the rest of the function.
        (throw 'snafu '("")))))
    (t
     ;; Un-highlighting triggered via keyboard action.
     (unless hi-lock-interactive-patterns
       (user-error "No highlighting to remove"))
     ;; Infer the regexp to un-highlight based on cursor position.
     (let* ((defaults (or (hi-lock--regexps-at-point)
                          (mapcar (lambda (pattern)
                                    (or (car (rassq pattern hi-lock-interactive-lighters))
                                        (car pattern)))
                                  hi-lock-interactive-patterns))))
       (list
        (completing-read (format-prompt "Regexp to unhighlight" (car defaults))
                         (mapcar (lambda (pattern)
                                   (cons (or (car (rassq pattern hi-lock-interactive-lighters))
                                             (car pattern))
                                         (cdr pattern)))
                                 hi-lock-interactive-patterns)
			 nil t nil nil defaults))))))

  (when (assoc regexp hi-lock-interactive-lighters)
    (setq regexp (cadr (assoc regexp hi-lock-interactive-lighters))))

  (dolist (keyword (if (eq regexp t) hi-lock-interactive-patterns
                     (list (assoc regexp hi-lock-interactive-patterns))))
    (when keyword
      (let ((face (hi-lock-keyword->face keyword)))
        ;; Make `face' the next one to use by default.
        (when (symbolp face)          ;Don't add it if it's a list (bug#13297).
          (add-to-list 'hi-lock--unused-faces (face-name face))))
      ;; FIXME: Calling `font-lock-remove-keywords' causes
      ;; `font-lock-specified-p' to go from nil to non-nil (because it
      ;; calls font-lock-set-defaults).  This is yet-another bug in
      ;; font-lock-add/remove-keywords, which we circumvent here by
      ;; testing `font-lock-fontified' (bug#19796).
      (if font-lock-fontified (font-lock-remove-keywords nil (list keyword)))
      (setq hi-lock-interactive-patterns
            (delq keyword hi-lock-interactive-patterns))
      (remove-overlays
       nil nil 'hi-lock-overlay-regexp
       (or (car (rassq keyword hi-lock-interactive-lighters))
           (hi-lock--hashcons (car keyword))))
      (setq hi-lock-interactive-lighters
            (rassq-delete-all keyword hi-lock-interactive-lighters))
      (font-lock-flush))))