• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/emacs-93/emacs/lisp/

Lines Matching defs:hi

0 ;;; hi-lock.el --- minor mode for interactive automatic highlighting
28 ;; With the hi-lock commands text matching interactively entered
47 ;; M-x highlight-regexp Total execution time [0-9]+ RET hi-blue-b RET
50 ;; M-x highlight-lines-matching-regexp January 2000 RET hi-black-b RET
59 ;; hi-lock mode and adds a "Regexp Highlighting" entry
62 ;; (global-hi-lock-mode 1)
65 ;; there by hi-lock) include the following in your .emacs file:
67 ;; (setq hi-lock-file-patterns-policy 'ask)
72 ;; You might also want to bind the hi-lock commands to more
75 ;; (define-key hi-lock-map "\C-z\C-h" 'highlight-lines-matching-regexp)
76 ;; (define-key hi-lock-map "\C-zi" 'hi-lock-find-patterns)
77 ;; (define-key hi-lock-map "\C-zh" 'highlight-regexp)
78 ;; (define-key hi-lock-map "\C-zp" 'highlight-phrase)
79 ;; (define-key hi-lock-map "\C-zr" 'unhighlight-regexp)
80 ;; (define-key hi-lock-map "\C-zb" 'hi-lock-write-interactive-patterns))
82 ;; See the documentation for hi-lock-mode `C-h f hi-lock-mode' for
87 ; Hi-lock: (("^;;; .*" (0 (quote hi-black-hb) t)))
96 (defgroup hi-lock nil
101 (defcustom hi-lock-file-patterns-range 10000
102 "Limit of search in a buffer for hi-lock patterns.
103 When a file is visited and hi-lock mode is on, patterns starting
105 of functions `hi-lock-mode' and `hi-lock-find-patterns'."
107 :group 'hi-lock)
109 (defcustom hi-lock-highlight-range 200000
110 "Size of area highlighted by hi-lock when font-lock not active.
113 hi-lock patterns will only be applied over a range of
114 `hi-lock-highlight-range' characters. If font-lock is active then
117 :group 'hi-lock)
119 (defcustom hi-lock-exclude-modes
121 "List of major modes in which hi-lock will not run.
125 :group 'hi-lock)
127 (defcustom hi-lock-file-patterns-policy 'ask
128 "Specify when hi-lock should use patterns found in file.
136 :group 'hi-lock
140 (put 'hi-lock-file-patterns-policy 'risky-local-variable t)
142 (defgroup hi-lock-faces nil
143 "Faces for hi-lock."
144 :group 'hi-lock
147 (defface hi-yellow
153 "Default face for hi-lock mode."
154 :group 'hi-lock-faces)
156 (defface hi-pink
159 "Face for hi-lock mode."
160 :group 'hi-lock-faces)
162 (defface hi-green
168 "Face for hi-lock mode."
169 :group 'hi-lock-faces)
171 (defface hi-blue
174 "Face for hi-lock mode."
175 :group 'hi-lock-faces)
177 (defface hi-black-b
179 "Face for hi-lock mode."
180 :group 'hi-lock-faces)
182 (defface hi-blue-b
185 "Face for hi-lock mode."
186 :group 'hi-lock-faces)
188 (defface hi-green-b
191 "Face for hi-lock mode."
192 :group 'hi-lock-faces)
194 (defface hi-red-b
197 "Face for hi-lock mode."
198 :group 'hi-lock-faces)
200 (defface hi-black-hb
202 "Face for hi-lock mode."
203 :group 'hi-lock-faces)
205 (defvar hi-lock-file-patterns nil
206 "Patterns found in file for hi-lock. Should not be changed.")
208 (defvar hi-lock-interactive-patterns nil
209 "Patterns provided to hi-lock by user. Should not be changed.")
211 (defvar hi-lock-face-history
212 (list "hi-yellow" "hi-pink" "hi-green" "hi-blue" "hi-black-b"
213 "hi-blue-b" "hi-red-b" "hi-green-b" "hi-black-hb")
214 "History list of faces for hi-lock interactive functions.")
216 ;(dolist (f hi-lock-face-history) (unless (facep f) (error "%s not a face" f)))
218 (defvar hi-lock-regexp-history nil
221 (defvar hi-lock-file-patterns-prefix "Hi-lock"
222 "Search target for finding hi-lock patterns at top of file.")
224 (defvar hi-lock-archaic-interface-message-used nil
225 "True if user alerted that `global-hi-lock-mode' is now the global switch.
226 Earlier versions of hi-lock used `hi-lock-mode' as the global switch;
227 the message is issued if it appears that `hi-lock-mode' is used assuming
230 (defvar hi-lock-archaic-interface-deduce nil
231 "If non-nil, sometimes assume that `hi-lock-mode' means `global-hi-lock-mode'.
232 Assumption is made if `hi-lock-mode' used in the *scratch* buffer while
235 (make-variable-buffer-local 'hi-lock-interactive-patterns)
236 (put 'hi-lock-interactive-patterns 'permanent-local t)
237 (make-variable-buffer-local 'hi-lock-regexp-history)
238 (put 'hi-lock-regexp-history 'permanent-local t)
239 (make-variable-buffer-local 'hi-lock-file-patterns)
240 (put 'hi-lock-file-patterns 'permanent-local t)
242 (defvar hi-lock-menu (make-sparse-keymap "Hi Lock")
243 "Menu for hi-lock mode.")
245 (define-key-after hi-lock-menu [highlight-regexp]
249 (define-key-after hi-lock-menu [highlight-phrase]
253 (define-key-after hi-lock-menu [highlight-lines-matching-regexp]
257 (define-key-after hi-lock-menu [unhighlight-regexp]
260 :enable hi-lock-interactive-patterns))
262 (define-key-after hi-lock-menu [hi-lock-write-interactive-patterns]
263 '(menu-item "Patterns to Buffer" hi-lock-write-interactive-patterns
265 :enable hi-lock-interactive-patterns))
267 (define-key-after hi-lock-menu [hi-lock-find-patterns]
268 '(menu-item "Patterns from Buffer" hi-lock-find-patterns
271 (defvar hi-lock-map (make-sparse-keymap "Hi Lock")
272 "Key map for hi-lock.")
274 (define-key hi-lock-map "\C-xwi" 'hi-lock-find-patterns)
275 (define-key hi-lock-map "\C-xwl" 'highlight-lines-matching-regexp)
276 (define-key hi-lock-map "\C-xwp" 'highlight-phrase)
277 (define-key hi-lock-map "\C-xwh" 'highlight-regexp)
278 (define-key hi-lock-map "\C-xwr" 'unhighlight-regexp)
279 (define-key hi-lock-map "\C-xwb" 'hi-lock-write-interactive-patterns)
284 (define-minor-mode hi-lock-mode
287 If ARG positive, turn hi-lock on. Issuing a hi-lock command will also
288 turn hi-lock on. To turn hi-lock on in all buffers use
289 `global-hi-lock-mode' or in your .emacs file (global-hi-lock-mode 1).
290 When hi-lock is turned on, a \"Regexp Highlighting\" submenu is added
308 \\[hi-lock-write-interactive-patterns]
310 be read the next time file is loaded or when the \\[hi-lock-find-patterns] command
312 (See `font-lock-keywords'.) They may be edited and re-loaded with \\[hi-lock-find-patterns],
314 loaded the patterns are read if `hi-lock-file-patterns-policy is
316 `hi-lock-file-patterns-policy' is bound to a function and that
319 \\[hi-lock-find-patterns]
320 Re-read patterns stored in buffer (in the format produced by \\[hi-lock-write-interactive-patterns]).
322 When hi-lock is started and if the mode is not excluded or patterns
328 \(number of characters into buffer) `hi-lock-file-patterns-range'.
331 is found. A mode is excluded if it's in the list `hi-lock-exclude-modes'."
332 :group 'hi-lock
333 :lighter (:eval (if (or hi-lock-interactive-patterns
334 hi-lock-file-patterns)
337 :keymap hi-lock-map
341 (not hi-lock-archaic-interface-message-used))
342 (setq hi-lock-archaic-interface-message-used t)
343 (if hi-lock-archaic-interface-deduce
344 (global-hi-lock-mode hi-lock-mode)
346 "Possible archaic use of (hi-lock-mode).
347 Use (global-hi-lock-mode 1) in .emacs to enable hi-lock for all buffers,
348 use (hi-lock-mode 1) for individual buffers. For compatibility with Emacs
351 (if (functionp 'global-hi-lock-mode)
352 (global-hi-lock-mode 1)
353 (hi-lock-mode 1))
355 (if hi-lock-mode
359 (define-key-after menu-bar-edit-menu [hi-lock]
360 (cons "Regexp Highlighting" hi-lock-menu))
361 (hi-lock-find-patterns)
362 (add-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook nil t))
364 (when (or hi-lock-interactive-patterns
365 hi-lock-file-patterns)
366 (when hi-lock-interactive-patterns
367 (font-lock-remove-keywords nil hi-lock-interactive-patterns)
368 (setq hi-lock-interactive-patterns nil))
369 (when hi-lock-file-patterns
370 (font-lock-remove-keywords nil hi-lock-file-patterns)
371 (setq hi-lock-file-patterns nil))
372 (remove-overlays nil nil 'hi-lock-overlay t)
374 (define-key-after menu-bar-edit-menu [hi-lock] nil)
375 (remove-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook t)))
378 (define-globalized-minor-mode global-hi-lock-mode
379 hi-lock-mode turn-on-hi-lock-if-enabled
380 :group 'hi-lock)
382 (defun turn-on-hi-lock-if-enabled ()
383 (setq hi-lock-archaic-interface-message-used t)
384 (unless (memq major-mode hi-lock-exclude-modes)
385 (hi-lock-mode 1)))
388 (defalias 'highlight-lines-matching-regexp 'hi-lock-line-face-buffer)
390 (defun hi-lock-line-face-buffer (regexp &optional face)
399 (hi-lock-regexp-okay
401 (cons (or (car hi-lock-regexp-history) "") 1 )
402 nil nil 'hi-lock-regexp-history))
403 (hi-lock-read-face-name)))
404 (or (facep face) (setq face 'hi-yellow))
405 (unless hi-lock-mode (hi-lock-mode 1))
406 (hi-lock-set-pattern
413 (defalias 'highlight-regexp 'hi-lock-face-buffer)
415 (defun hi-lock-face-buffer (regexp &optional face)
424 (hi-lock-regexp-okay
426 (cons (or (car hi-lock-regexp-history) "") 1 )
427 nil nil 'hi-lock-regexp-history))
428 (hi-lock-read-face-name)))
429 (or (facep face) (setq face 'hi-yellow))
430 (unless hi-lock-mode (hi-lock-mode 1))
431 (hi-lock-set-pattern regexp face))
434 (defalias 'highlight-phrase 'hi-lock-face-phrase-buffer)
436 (defun hi-lock-face-phrase-buffer (regexp &optional face)
443 (hi-lock-regexp-okay
444 (hi-lock-process-phrase
446 (cons (or (car hi-lock-regexp-history) "") 1 )
447 nil nil 'hi-lock-regexp-history)))
448 (hi-lock-read-face-name)))
449 (or (facep face) (setq face 'hi-yellow))
450 (unless hi-lock-mode (hi-lock-mode 1))
451 (hi-lock-set-pattern regexp face))
454 (defalias 'unhighlight-regexp 'hi-lock-unface-buffer)
456 (defun hi-lock-unface-buffer (regexp)
457 "Remove highlighting of each match to REGEXP set by hi-lock.
460 regexp's maintained. Will accept only regexps inserted by hi-lock
461 interactive functions. \(See `hi-lock-interactive-patterns'.\)
482 hi-lock-interactive-patterns))))
490 hi-lock-interactive-patterns)))
491 (unless hi-lock-interactive-patterns
495 hi-lock-interactive-patterns nil t
496 (car (car hi-lock-interactive-patterns))
498 (let ((keyword (assoc regexp hi-lock-interactive-patterns)))
501 (setq hi-lock-interactive-patterns
502 (delq keyword hi-lock-interactive-patterns))
504 nil nil 'hi-lock-overlay-regexp (hi-lock-string-serialize regexp))
508 (defun hi-lock-write-interactive-patterns ()
513 be found in variable `hi-lock-interactive-patterns'."
515 (if (null hi-lock-interactive-patterns)
521 hi-lock-file-patterns-prefix
523 hi-lock-interactive-patterns)
525 (when (> (point) hi-lock-file-patterns-range)
530 (defun hi-lock-process-phrase (phrase)
543 (defun hi-lock-regexp-okay (regexp)
552 (defun hi-lock-read-face-name ()
557 (cons (car hi-lock-face-history)
560 (substring (car hi-lock-face-history) 0 1)
562 hi-lock-face-history))))
564 (not (equal prefix (car hi-lock-face-history))))
566 '(hi-lock-face-history . 0))))
568 (defun hi-lock-set-pattern (regexp face)
571 (unless (member pattern hi-lock-interactive-patterns)
573 (push pattern hi-lock-interactive-patterns)
576 (let* ((serial (hi-lock-string-serialize regexp))
577 (range-min (- (point) (/ hi-lock-highlight-range 2)))
578 (range-max (+ (point) (/ hi-lock-highlight-range 2)))
589 (overlay-put overlay 'hi-lock-overlay t)
590 (overlay-put overlay 'hi-lock-overlay-regexp serial)
594 (defun hi-lock-set-file-patterns (patterns)
596 (when (or hi-lock-file-patterns patterns)
597 (font-lock-remove-keywords nil hi-lock-file-patterns)
598 (setq hi-lock-file-patterns patterns)
599 (font-lock-add-keywords nil hi-lock-file-patterns t)
602 (defun hi-lock-find-patterns ()
603 "Find patterns in current buffer for hi-lock."
605 (unless (memq major-mode hi-lock-exclude-modes)
607 (target-regexp (concat "\\<" hi-lock-file-patterns-prefix ":")))
613 (+ (point) hi-lock-file-patterns-range) t)
622 hi-lock-mode
624 ((eq this-command 'hi-lock-find-patterns) t)
625 ((functionp hi-lock-file-patterns-policy)
626 (funcall hi-lock-file-patterns-policy all-patterns))
627 ((eq hi-lock-file-patterns-policy 'ask)
628 (y-or-n-p "Add patterns from this buffer to hi-lock? "))
630 (hi-lock-set-file-patterns all-patterns)
634 (defun hi-lock-font-lock-hook ()
635 "Add hi-lock patterns to font-lock's."
638 (font-lock-add-keywords nil hi-lock-file-patterns t)
639 (font-lock-add-keywords nil hi-lock-interactive-patterns t))
640 (hi-lock-mode -1)))
642 (defvar hi-lock-string-serialize-hash
646 (defvar hi-lock-string-serialize-serial 1
647 "Number assigned to last new string in call to `hi-lock-string-serialize'.
649 `hi-lock-string-serialize'.")
651 (defun hi-lock-string-serialize (string)
654 (let ((val (gethash string hi-lock-string-serialize-hash)))
657 (setq hi-lock-string-serialize-serial
658 (1+ hi-lock-string-serialize-serial))
659 hi-lock-string-serialize-hash)
660 hi-lock-string-serialize-serial)))
662 (provide 'hi-lock)
665 ;;; hi-lock.el ends here