Mercurial > emacs
comparison lisp/hi-lock.el @ 67474:a75f6e2ee182
(hi-lock-mode) Renamed from hi-lock-buffer-mode; react if global-hi-lock-mode
seems intended.
(global-hi-lock-mode) Renamed from hi-lock-mode.
(hi-lock-archaic-interface-message-used, hi-lock-archaic-interface-deduce): New
variables.
(turn-on-hi-lock-if-enabled, hi-lock-line-face-buffer)
(hi-lock-face-buffer, hi-lock-face-phrase-buffer)
(hi-lock-find-patterns, hi-lock-font-lock-hook): Replace hi-lock-buffer-mode
with hi-lock-mode.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sat, 10 Dec 2005 11:47:28 +0000 |
parents | af4b92018fde |
children | fd7c898ab005 |
comparison
equal
deleted
inserted
replaced
67473:b3b489c17f2e | 67474:a75f6e2ee182 |
---|---|
56 ;; | 56 ;; |
57 ;; Put the following code in your .emacs file. This turns on | 57 ;; Put the following code in your .emacs file. This turns on |
58 ;; hi-lock mode and adds a "Regexp Highlighting" entry | 58 ;; hi-lock mode and adds a "Regexp Highlighting" entry |
59 ;; to the edit menu. | 59 ;; to the edit menu. |
60 ;; | 60 ;; |
61 ;; (hi-lock-mode 1) | 61 ;; (global-hi-lock-mode 1) |
62 ;; | 62 ;; |
63 ;; You might also want to bind the hi-lock commands to more | 63 ;; You might also want to bind the hi-lock commands to more |
64 ;; finger-friendly sequences: | 64 ;; finger-friendly sequences: |
65 | 65 |
66 ;; (define-key hi-lock-map "\C-z\C-h" 'highlight-lines-matching-regexp) | 66 ;; (define-key hi-lock-map "\C-z\C-h" 'highlight-lines-matching-regexp) |
186 "History of regexps used for interactive fontification.") | 186 "History of regexps used for interactive fontification.") |
187 | 187 |
188 (defvar hi-lock-file-patterns-prefix "Hi-lock" | 188 (defvar hi-lock-file-patterns-prefix "Hi-lock" |
189 "Regexp for finding hi-lock patterns at top of file.") | 189 "Regexp for finding hi-lock patterns at top of file.") |
190 | 190 |
191 (defvar hi-lock-archaic-interface-message-used nil | |
192 "True if user alerted that global-hi-lock-mode is now the global switch. | |
193 Earlier versions of hi-lock used hi-lock-mode as the global switch, | |
194 the message is issued if it appears that hi-lock-mode is used assuming | |
195 that older functionality. This variable avoids multiple reminders.") | |
196 | |
197 (defvar hi-lock-archaic-interface-deduce nil | |
198 "If non-nil, sometimes assume that hi-lock-mode means global-hi-lock-mode. | |
199 Assumption is made if hi-lock-mode used in the *scratch* buffer while | |
200 a library is being loaded.") | |
201 | |
191 (make-variable-buffer-local 'hi-lock-interactive-patterns) | 202 (make-variable-buffer-local 'hi-lock-interactive-patterns) |
192 (put 'hi-lock-interactive-patterns 'permanent-local t) | 203 (put 'hi-lock-interactive-patterns 'permanent-local t) |
193 (make-variable-buffer-local 'hi-lock-regexp-history) | 204 (make-variable-buffer-local 'hi-lock-regexp-history) |
194 (put 'hi-lock-regexp-history 'permanent-local t) | 205 (put 'hi-lock-regexp-history 'permanent-local t) |
195 (make-variable-buffer-local 'hi-lock-file-patterns) | 206 (make-variable-buffer-local 'hi-lock-file-patterns) |
236 | 247 |
237 ;; Visible Functions | 248 ;; Visible Functions |
238 | 249 |
239 | 250 |
240 ;;;###autoload | 251 ;;;###autoload |
241 (define-minor-mode hi-lock-buffer-mode | 252 (define-minor-mode hi-lock-mode |
242 "Toggle minor mode for interactively adding font-lock highlighting patterns. | 253 "Toggle minor mode for interactively adding font-lock highlighting patterns. |
243 | 254 |
244 If ARG positive turn hi-lock on. Issuing a hi-lock command will also | 255 If ARG positive turn hi-lock on. Issuing a hi-lock command will also |
245 turn hi-lock on. When hi-lock is turned on, a \"Regexp Highlighting\" | 256 turn hi-lock on; to turn hi-lock on in all buffers use |
246 submenu is added to the \"Edit\" menu. The commands in the submenu, | 257 global-hi-lock-mode or in your .emacs file (global-hi-lock-mode 1). |
247 which can be called interactively, are: | 258 When hi-lock is turned on, a \"Regexp Highlighting\" submenu is added |
259 to the \"Edit\" menu. The commands in the submenu, which can be | |
260 called interactively, are: | |
248 | 261 |
249 \\[highlight-regexp] REGEXP FACE | 262 \\[highlight-regexp] REGEXP FACE |
250 Highlight matches of pattern REGEXP in current buffer with FACE. | 263 Highlight matches of pattern REGEXP in current buffer with FACE. |
251 | 264 |
252 \\[highlight-phrase] PHRASE FACE | 265 \\[highlight-phrase] PHRASE FACE |
281 is found. A mode is excluded if it's in the list `hi-lock-exclude-modes'." | 294 is found. A mode is excluded if it's in the list `hi-lock-exclude-modes'." |
282 :group 'hi-lock | 295 :group 'hi-lock |
283 :lighter " H" | 296 :lighter " H" |
284 :global nil | 297 :global nil |
285 :keymap hi-lock-map | 298 :keymap hi-lock-map |
286 (if hi-lock-buffer-mode | 299 (when (and (equal (buffer-name) "*scratch*") |
300 load-in-progress | |
301 (not (interactive-p)) | |
302 (not hi-lock-archaic-interface-message-used)) | |
303 (setq hi-lock-archaic-interface-message-used t) | |
304 (if hi-lock-archaic-interface-deduce | |
305 (global-hi-lock-mode hi-lock-mode) | |
306 (warn | |
307 "Possible archaic use of (hi-lock-mode). | |
308 Use (global-hi-lock-mode 1) in .emacs to enable hi-lock for all buffers, | |
309 use (hi-lock-mode 1) for individual buffers. For compatibility with Emacs | |
310 versions before 22 use the following in your .emacs file: | |
311 | |
312 (if (functionp 'global-hi-lock-mode) | |
313 (global-hi-lock-mode 1) | |
314 (hi-lock-mode 1)) | |
315 "))) | |
316 (if hi-lock-mode | |
287 ;; Turned on. | 317 ;; Turned on. |
288 (progn | 318 (progn |
289 (unless font-lock-mode (font-lock-mode 1)) | 319 (unless font-lock-mode (font-lock-mode 1)) |
290 (define-key-after menu-bar-edit-menu [hi-lock] | 320 (define-key-after menu-bar-edit-menu [hi-lock] |
291 (cons "Regexp Highlighting" hi-lock-menu)) | 321 (cons "Regexp Highlighting" hi-lock-menu)) |
292 (hi-lock-find-patterns) | 322 (hi-lock-find-patterns) |
293 (add-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook nil t)) | 323 (add-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook nil t)) |
294 ;; Turned off. | 324 ;; Turned off. |
295 (when (or hi-lock-interactive-patterns | 325 (when (or hi-lock-interactive-patterns |
296 hi-lock-file-patterns) | 326 hi-lock-file-patterns) |
297 (when hi-lock-interactive-patterns | 327 (when hi-lock-interactive-patterns |
298 (font-lock-remove-keywords nil hi-lock-interactive-patterns) | 328 (font-lock-remove-keywords nil hi-lock-interactive-patterns) |
299 (setq hi-lock-interactive-patterns nil)) | 329 (setq hi-lock-interactive-patterns nil)) |
300 (when hi-lock-file-patterns | 330 (when hi-lock-file-patterns |
301 (font-lock-remove-keywords nil hi-lock-file-patterns) | 331 (font-lock-remove-keywords nil hi-lock-file-patterns) |
302 (setq hi-lock-file-patterns nil)) | 332 (setq hi-lock-file-patterns nil)) |
304 (font-lock-fontify-buffer))) | 334 (font-lock-fontify-buffer))) |
305 (define-key-after menu-bar-edit-menu [hi-lock] nil) | 335 (define-key-after menu-bar-edit-menu [hi-lock] nil) |
306 (remove-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook t))) | 336 (remove-hook 'font-lock-mode-hook 'hi-lock-font-lock-hook t))) |
307 | 337 |
308 ;;;###autoload | 338 ;;;###autoload |
309 (define-global-minor-mode hi-lock-mode | 339 (define-global-minor-mode global-hi-lock-mode |
310 hi-lock-buffer-mode turn-on-hi-lock-if-enabled | 340 hi-lock-mode turn-on-hi-lock-if-enabled |
311 :group 'hi-lock) | 341 :group 'hi-lock) |
312 | 342 |
313 (defun turn-on-hi-lock-if-enabled () | 343 (defun turn-on-hi-lock-if-enabled () |
344 (setq hi-lock-archaic-interface-message-used t) | |
314 (unless (memq major-mode hi-lock-exclude-modes) | 345 (unless (memq major-mode hi-lock-exclude-modes) |
315 (hi-lock-buffer-mode 1))) | 346 (hi-lock-mode 1))) |
316 | 347 |
317 ;;;###autoload | 348 ;;;###autoload |
318 (defalias 'highlight-lines-matching-regexp 'hi-lock-line-face-buffer) | 349 (defalias 'highlight-lines-matching-regexp 'hi-lock-line-face-buffer) |
319 ;;;###autoload | 350 ;;;###autoload |
320 (defun hi-lock-line-face-buffer (regexp &optional face) | 351 (defun hi-lock-line-face-buffer (regexp &optional face) |
330 (read-from-minibuffer "Regexp to highlight line: " | 361 (read-from-minibuffer "Regexp to highlight line: " |
331 (cons (or (car hi-lock-regexp-history) "") 1 ) | 362 (cons (or (car hi-lock-regexp-history) "") 1 ) |
332 nil nil 'hi-lock-regexp-history)) | 363 nil nil 'hi-lock-regexp-history)) |
333 (hi-lock-read-face-name))) | 364 (hi-lock-read-face-name))) |
334 (or (facep face) (setq face 'hi-yellow)) | 365 (or (facep face) (setq face 'hi-yellow)) |
335 (unless hi-lock-buffer-mode (hi-lock-buffer-mode 1)) | 366 (unless hi-lock-mode (hi-lock-mode 1)) |
336 (hi-lock-set-pattern | 367 (hi-lock-set-pattern |
337 ;; The \\(?:...\\) grouping construct ensures that a leading ^, +, * or ? | 368 ;; The \\(?:...\\) grouping construct ensures that a leading ^, +, * or ? |
338 ;; or a trailing $ in REGEXP will be interpreted correctly. | 369 ;; or a trailing $ in REGEXP will be interpreted correctly. |
339 (concat "^.*\\(?:" regexp "\\).*$") face)) | 370 (concat "^.*\\(?:" regexp "\\).*$") face)) |
340 | 371 |
355 (read-from-minibuffer "Regexp to highlight: " | 386 (read-from-minibuffer "Regexp to highlight: " |
356 (cons (or (car hi-lock-regexp-history) "") 1 ) | 387 (cons (or (car hi-lock-regexp-history) "") 1 ) |
357 nil nil 'hi-lock-regexp-history)) | 388 nil nil 'hi-lock-regexp-history)) |
358 (hi-lock-read-face-name))) | 389 (hi-lock-read-face-name))) |
359 (or (facep face) (setq face 'hi-yellow)) | 390 (or (facep face) (setq face 'hi-yellow)) |
360 (unless hi-lock-buffer-mode (hi-lock-buffer-mode 1)) | 391 (unless hi-lock-mode (hi-lock-mode 1)) |
361 (hi-lock-set-pattern regexp face)) | 392 (hi-lock-set-pattern regexp face)) |
362 | 393 |
363 ;;;###autoload | 394 ;;;###autoload |
364 (defalias 'highlight-phrase 'hi-lock-face-phrase-buffer) | 395 (defalias 'highlight-phrase 'hi-lock-face-phrase-buffer) |
365 ;;;###autoload | 396 ;;;###autoload |
375 (read-from-minibuffer "Phrase to highlight: " | 406 (read-from-minibuffer "Phrase to highlight: " |
376 (cons (or (car hi-lock-regexp-history) "") 1 ) | 407 (cons (or (car hi-lock-regexp-history) "") 1 ) |
377 nil nil 'hi-lock-regexp-history))) | 408 nil nil 'hi-lock-regexp-history))) |
378 (hi-lock-read-face-name))) | 409 (hi-lock-read-face-name))) |
379 (or (facep face) (setq face 'hi-yellow)) | 410 (or (facep face) (setq face 'hi-yellow)) |
380 (unless hi-lock-buffer-mode (hi-lock-buffer-mode 1)) | 411 (unless hi-lock-mode (hi-lock-mode 1)) |
381 (hi-lock-set-pattern regexp face)) | 412 (hi-lock-set-pattern regexp face)) |
382 | 413 |
383 ;;;###autoload | 414 ;;;###autoload |
384 (defalias 'unhighlight-regexp 'hi-lock-unface-buffer) | 415 (defalias 'unhighlight-regexp 'hi-lock-unface-buffer) |
385 ;;;###autoload | 416 ;;;###autoload |
533 (not (looking-at "\\s-*end"))) | 564 (not (looking-at "\\s-*end"))) |
534 (condition-case nil | 565 (condition-case nil |
535 (setq all-patterns (append (read (current-buffer)) all-patterns)) | 566 (setq all-patterns (append (read (current-buffer)) all-patterns)) |
536 (error (message "Invalid pattern list expression at %d" | 567 (error (message "Invalid pattern list expression at %d" |
537 (line-number-at-pos))))))) | 568 (line-number-at-pos))))))) |
538 (when hi-lock-buffer-mode (hi-lock-set-file-patterns all-patterns)) | 569 (when hi-lock-mode (hi-lock-set-file-patterns all-patterns)) |
539 (if (interactive-p) | 570 (if (interactive-p) |
540 (message "Hi-lock added %d patterns." (length all-patterns)))))) | 571 (message "Hi-lock added %d patterns." (length all-patterns)))))) |
541 | 572 |
542 (defun hi-lock-font-lock-hook () | 573 (defun hi-lock-font-lock-hook () |
543 "Add hi lock patterns to font-lock's." | 574 "Add hi lock patterns to font-lock's." |
544 (if font-lock-mode | 575 (if font-lock-mode |
545 (progn (font-lock-add-keywords nil hi-lock-file-patterns) | 576 (progn (font-lock-add-keywords nil hi-lock-file-patterns) |
546 (font-lock-add-keywords nil hi-lock-interactive-patterns)) | 577 (font-lock-add-keywords nil hi-lock-interactive-patterns)) |
547 (hi-lock-buffer-mode -1))) | 578 (hi-lock-mode -1))) |
548 | 579 |
549 (provide 'hi-lock) | 580 (provide 'hi-lock) |
550 | 581 |
551 ;; arch-tag: d2e8fd07-4cc9-4c6f-a200-1e729bc54066 | 582 ;; arch-tag: d2e8fd07-4cc9-4c6f-a200-1e729bc54066 |
552 ;;; hi-lock.el ends here | 583 ;;; hi-lock.el ends here |