Skip to content

Instantly share code, notes, and snippets.

@emasaka
Created May 26, 2012 02:34
Show Gist options
  • Select an option

  • Save emasaka/2791789 to your computer and use it in GitHub Desktop.

Select an option

Save emasaka/2791789 to your computer and use it in GitHub Desktop.
(require 'hi-lock)
(defun grepf->regexp (file)
(with-temp-buffer
(insert-file-contents file)
(goto-char (point-max))
(when (looking-back "\n")
(delete-char -1) )
(goto-char (point-min))
(while (search-forward "\n" nil t)
(replace-match "\\|" nil t) )
(buffer-substring (point-min) (point-max)) ))
(defun hi-lock-from-file (file &optional face)
"Set face of each match of regexps in FILE to FACE.
Interactively, prompt for FILE then FACE.
FILE is grep -f style"
(interactive
(list
(read-file-name "Pattern File:" )
(hi-lock-read-face-name)))
(hi-lock-face-buffer (grepf->regexp file) face) )
(define-key hi-lock-map "\C-xwf" 'hi-lock-from-file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment