X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/ef705f25740224b52e27ceb66841b48cba23ad9b..ef62b23df5a7007c3d8c74dbca87ba83e9da682e:/lisp/hi-lock.el diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el index ca74d6f0a8..2c2d08e19c 100644 --- a/lisp/hi-lock.el +++ b/lisp/hi-lock.el @@ -1,9 +1,8 @@ ;;; hi-lock.el --- minor mode for interactive automatic highlighting -;; Copyright (C) 2000, 2001, 2002, 2003, 2004, -;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +;; Copyright (C) 2000-2012 Free Software Foundation, Inc. -;; Author: David M. Koppelman, koppel@ece.lsu.edu +;; Author: David M. Koppelman ;; Keywords: faces, minor-mode, matching, display ;; This file is part of GNU Emacs. @@ -88,8 +87,7 @@ ;;; Code: -(eval-and-compile - (require 'font-lock)) +(require 'font-lock) (defgroup hi-lock nil "Interactively add and remove font-lock patterns for highlighting text." @@ -206,16 +204,15 @@ patterns." (defvar hi-lock-interactive-patterns nil "Patterns provided to hi-lock by user. Should not be changed.") +(define-obsolete-variable-alias 'hi-lock-face-history + 'hi-lock-face-defaults "23.1") (defvar hi-lock-face-defaults '("hi-yellow" "hi-pink" "hi-green" "hi-blue" "hi-black-b" "hi-blue-b" "hi-red-b" "hi-green-b" "hi-black-hb") "Default faces for hi-lock interactive functions.") -;(dolist (f hi-lock-face-defaults) (unless (facep f) (error "%s not a face" f))) - -(define-obsolete-variable-alias 'hi-lock-face-history - 'hi-lock-face-defaults - "23.1") +;;(dolist (f hi-lock-face-defaults) +;; (unless (facep f) (error "%s not a face" f))) (define-obsolete-variable-alias 'hi-lock-regexp-history 'regexp-history @@ -240,57 +237,62 @@ a library is being loaded.") (make-variable-buffer-local 'hi-lock-file-patterns) (put 'hi-lock-file-patterns 'permanent-local t) -(defvar hi-lock-menu (make-sparse-keymap "Hi Lock") +(defvar hi-lock-menu + (let ((map (make-sparse-keymap "Hi Lock"))) + (define-key-after map [highlight-regexp] + '(menu-item "Highlight Regexp..." highlight-regexp + :help "Highlight text matching PATTERN (a regexp).")) + + (define-key-after map [highlight-phrase] + '(menu-item "Highlight Phrase..." highlight-phrase + :help "Highlight text matching PATTERN (a regexp processed to match phrases).")) + + (define-key-after map [highlight-lines-matching-regexp] + '(menu-item "Highlight Lines..." highlight-lines-matching-regexp + :help "Highlight lines containing match of PATTERN (a regexp).")) + + (define-key-after map [unhighlight-regexp] + '(menu-item "Remove Highlighting..." unhighlight-regexp + :help "Remove previously entered highlighting pattern." + :enable hi-lock-interactive-patterns)) + + (define-key-after map [hi-lock-write-interactive-patterns] + '(menu-item "Patterns to Buffer" hi-lock-write-interactive-patterns + :help "Insert interactively added REGEXPs into buffer at point." + :enable hi-lock-interactive-patterns)) + + (define-key-after map [hi-lock-find-patterns] + '(menu-item "Patterns from Buffer" hi-lock-find-patterns + :help "Use patterns (if any) near top of buffer.")) + map) "Menu for hi-lock mode.") -(define-key-after hi-lock-menu [highlight-regexp] - '(menu-item "Highlight Regexp..." highlight-regexp - :help "Highlight text matching PATTERN (a regexp).")) - -(define-key-after hi-lock-menu [highlight-phrase] - '(menu-item "Highlight Phrase..." highlight-phrase - :help "Highlight text matching PATTERN (a regexp processed to match phrases).")) - -(define-key-after hi-lock-menu [highlight-lines-matching-regexp] - '(menu-item "Highlight Lines..." highlight-lines-matching-regexp - :help "Highlight lines containing match of PATTERN (a regexp)..")) - -(define-key-after hi-lock-menu [unhighlight-regexp] - '(menu-item "Remove Highlighting..." unhighlight-regexp - :help "Remove previously entered highlighting pattern." - :enable hi-lock-interactive-patterns)) - -(define-key-after hi-lock-menu [hi-lock-write-interactive-patterns] - '(menu-item "Patterns to Buffer" hi-lock-write-interactive-patterns - :help "Insert interactively added REGEXPs into buffer at point." - :enable hi-lock-interactive-patterns)) - -(define-key-after hi-lock-menu [hi-lock-find-patterns] - '(menu-item "Patterns from Buffer" hi-lock-find-patterns - :help "Use patterns (if any) near top of buffer.")) - -(defvar hi-lock-map (make-sparse-keymap "Hi Lock") +(defvar hi-lock-map + (let ((map (make-sparse-keymap "Hi Lock"))) + (define-key map "\C-xwi" 'hi-lock-find-patterns) + (define-key map "\C-xwl" 'highlight-lines-matching-regexp) + (define-key map "\C-xwp" 'highlight-phrase) + (define-key map "\C-xwh" 'highlight-regexp) + (define-key map "\C-xwr" 'unhighlight-regexp) + (define-key map "\C-xwb" 'hi-lock-write-interactive-patterns) + map) "Key map for hi-lock.") -(define-key hi-lock-map "\C-xwi" 'hi-lock-find-patterns) -(define-key hi-lock-map "\C-xwl" 'highlight-lines-matching-regexp) -(define-key hi-lock-map "\C-xwp" 'highlight-phrase) -(define-key hi-lock-map "\C-xwh" 'highlight-regexp) -(define-key hi-lock-map "\C-xwr" 'unhighlight-regexp) -(define-key hi-lock-map "\C-xwb" 'hi-lock-write-interactive-patterns) - ;; Visible Functions ;;;###autoload (define-minor-mode hi-lock-mode - "Toggle minor mode for interactively adding font-lock highlighting patterns. - -If ARG positive, turn hi-lock on. Issuing a hi-lock command will also -turn hi-lock on. To turn hi-lock on in all buffers use -`global-hi-lock-mode' or in your .emacs file (global-hi-lock-mode 1). -When hi-lock is turned on, a \"Regexp Highlighting\" submenu is added -to the \"Edit\" menu. The commands in the submenu, which can be -called interactively, are: + "Toggle selective highlighting of patterns (Hi Lock mode). +With a prefix argument ARG, enable Hi Lock mode if ARG is +positive, and disable it otherwise. If called from Lisp, enable +the mode if ARG is omitted or nil. + +Issuing one the highlighting commands listed below will +automatically enable Hi Lock mode. To enable Hi Lock mode in all +buffers, use `global-hi-lock-mode' or add (global-hi-lock-mode 1) +to your init file. 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. @@ -338,7 +340,7 @@ is found. A mode is excluded if it's in the list `hi-lock-exclude-modes'." :keymap hi-lock-map (when (and (equal (buffer-name) "*scratch*") load-in-progress - (not (interactive-p)) + (not (called-interactively-p 'interactive)) (not hi-lock-archaic-interface-message-used)) (setq hi-lock-archaic-interface-message-used t) (if hi-lock-archaic-interface-deduce @@ -398,7 +400,8 @@ and \\[next-history-element] to retrieve default values. \(See info node `Minibuffer History'.)" (interactive (list - (hi-lock-regexp-okay (read-regexp "Regexp to highlight line")) + (hi-lock-regexp-okay + (read-regexp "Regexp to highlight line" (car regexp-history))) (hi-lock-read-face-name))) (or (facep face) (setq face 'hi-yellow)) (unless hi-lock-mode (hi-lock-mode 1)) @@ -421,7 +424,8 @@ and \\[next-history-element] to retrieve default values. \(See info node `Minibuffer History'.)" (interactive (list - (hi-lock-regexp-okay (read-regexp "Regexp to highlight")) + (hi-lock-regexp-okay + (read-regexp "Regexp to highlight" (car regexp-history))) (hi-lock-read-face-name))) (or (facep face) (setq face 'hi-yellow)) (unless hi-lock-mode (hi-lock-mode 1)) @@ -439,12 +443,14 @@ lower-case letters made case insensitive." (list (hi-lock-regexp-okay (hi-lock-process-phrase - (read-regexp "Phrase to highlight"))) + (read-regexp "Phrase to highlight" (car regexp-history)))) (hi-lock-read-face-name))) (or (facep face) (setq face 'hi-yellow)) (unless hi-lock-mode (hi-lock-mode 1)) (hi-lock-set-pattern regexp face)) +(declare-function x-popup-menu "menu.c" (position menu)) + ;;;###autoload (defalias 'unhighlight-regexp 'hi-lock-unface-buffer) ;;;###autoload @@ -457,7 +463,9 @@ interactive functions. \(See `hi-lock-interactive-patterns'.\) \\Use \\[minibuffer-complete] to complete a partially typed regexp. \(See info node `Minibuffer History'.\)" (interactive - (if (and (display-popup-menus-p) (not last-nonmenu-event)) + (if (and (display-popup-menus-p) + (listp last-nonmenu-event) + use-dialog-box) (catch 'snafu (or (x-popup-menu @@ -564,10 +572,11 @@ not suitable." "Highlight REGEXP with face FACE." (let ((pattern (list regexp (list 0 (list 'quote face) t)))) (unless (member pattern hi-lock-interactive-patterns) - (font-lock-add-keywords nil (list pattern) t) (push pattern hi-lock-interactive-patterns) (if font-lock-fontified - (font-lock-fontify-buffer) + (progn + (font-lock-add-keywords nil (list pattern) t) + (font-lock-fontify-buffer)) (let* ((serial (hi-lock-string-serialize regexp)) (range-min (- (point) (/ hi-lock-highlight-range 2))) (range-max (+ (point) (/ hi-lock-highlight-range 2))) @@ -623,16 +632,14 @@ not suitable." (y-or-n-p "Add patterns from this buffer to hi-lock? ")) (t nil))) (hi-lock-set-file-patterns all-patterns) - (if (interactive-p) + (if (called-interactively-p 'interactive) (message "Hi-lock added %d patterns." (length all-patterns))))))) (defun hi-lock-font-lock-hook () "Add hi-lock patterns to font-lock's." - (if font-lock-mode - (progn - (font-lock-add-keywords nil hi-lock-file-patterns t) - (font-lock-add-keywords nil hi-lock-interactive-patterns t)) - (hi-lock-mode -1))) + (when font-lock-fontified + (font-lock-add-keywords nil hi-lock-file-patterns t) + (font-lock-add-keywords nil hi-lock-interactive-patterns t))) (defvar hi-lock-string-serialize-hash (make-hash-table :test 'equal) @@ -662,5 +669,4 @@ A string is considered new if it had not previously been used in a call to (provide 'hi-lock) -;; arch-tag: d2e8fd07-4cc9-4c6f-a200-1e729bc54066 ;;; hi-lock.el ends here