Function: hi-lock-find-patterns

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

Signature

(hi-lock-find-patterns)

Documentation

Add patterns from the current buffer to the list of hi-lock patterns.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/hi-lock.el.gz
;;;###autoload
(defun hi-lock-find-patterns ()
  "Add patterns from the current buffer to the list of hi-lock patterns."
  (interactive)
  (unless (memq major-mode hi-lock-exclude-modes)
    (let ((all-patterns nil)
          (target-regexp (concat "\\<" hi-lock-file-patterns-prefix ":")))
      (save-excursion
	(save-restriction
	  (widen)
	  (goto-char (point-min))
	  (re-search-forward target-regexp
			     (+ (point) hi-lock-file-patterns-range) t)
	  (beginning-of-line)
	  (while (and (re-search-forward target-regexp (+ (point) 100) t)
		      (not (looking-at "\\s-*end")))
            (condition-case nil
                (setq all-patterns (append (read (current-buffer)) all-patterns))
              (error (message "Invalid pattern list expression at line %d"
                              (line-number-at-pos)))))))
      (when (and all-patterns
                 hi-lock-mode
                 (cond
                  ((eq this-command 'hi-lock-find-patterns) t)
                  ((functionp hi-lock-file-patterns-policy)
                   (funcall hi-lock-file-patterns-policy all-patterns))
                  ((eq hi-lock-file-patterns-policy 'ask)
                   (y-or-n-p "Add patterns from this buffer to hi-lock? "))
                  ((eq hi-lock-file-patterns-policy 'always) t)
                  (t nil)))
        (hi-lock-set-file-patterns all-patterns)
        (if (called-interactively-p 'interactive)
            (message "Hi-lock added %d patterns." (length all-patterns)))))))