diff options
| -rw-r--r-- | etc/NEWS | 8 | ||||
| -rw-r--r-- | lisp/hi-lock.el | 36 |
2 files changed, 29 insertions, 15 deletions
| @@ -3231,6 +3231,14 @@ Command 'antlr-run-tool' now usually runs on the file for the current | |||
| 3231 | buffer. Customize this user option to have value ' nil' to get the | 3231 | buffer. Customize this user option to have value ' nil' to get the |
| 3232 | previous behavior back. | 3232 | previous behavior back. |
| 3233 | 3233 | ||
| 3234 | ** Hi Lock | ||
| 3235 | |||
| 3236 | --- | ||
| 3237 | *** Use active region for default values in more functions. | ||
| 3238 | If an active region exists, the commands 'hi-lock-line-face-buffer' and | ||
| 3239 | 'hi-lock-face-phrase-buffer' now use its contents as their default | ||
| 3240 | value. Previously, only 'hi-lock-face-buffer' supported this. | ||
| 3241 | |||
| 3234 | 3242 | ||
| 3235 | * New Modes and Packages in Emacs 31.1 | 3243 | * New Modes and Packages in Emacs 31.1 |
| 3236 | 3244 | ||
diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el index 35ee01c2f3b..71f302f3ebc 100644 --- a/lisp/hi-lock.el +++ b/lisp/hi-lock.el | |||
| @@ -393,7 +393,7 @@ The lines that match REGEXP will be displayed by merging | |||
| 393 | the attributes of FACE with any other face attributes | 393 | the attributes of FACE with any other face attributes |
| 394 | of text in those lines. | 394 | of text in those lines. |
| 395 | 395 | ||
| 396 | Interactively, prompt for REGEXP using `read-regexp', then FACE. | 396 | Interactively, prompt for REGEXP using `hi-lock-read-regexp', then FACE. |
| 397 | Use the global history list for FACE. | 397 | Use the global history list for FACE. |
| 398 | 398 | ||
| 399 | If REGEXP contains upper case characters (excluding those preceded by `\\') | 399 | If REGEXP contains upper case characters (excluding those preceded by `\\') |
| @@ -404,8 +404,7 @@ use overlays for highlighting. If overlays are used, the | |||
| 404 | highlighting will not update as you type." | 404 | highlighting will not update as you type." |
| 405 | (interactive | 405 | (interactive |
| 406 | (list | 406 | (list |
| 407 | (hi-lock-regexp-okay | 407 | (hi-lock-read-regexp "Regexp to highlight line") |
| 408 | (read-regexp "Regexp to highlight line" 'regexp-history-last)) | ||
| 409 | (hi-lock-read-face-name))) | 408 | (hi-lock-read-face-name))) |
| 410 | (or (facep face) (setq face 'hi-yellow)) | 409 | (or (facep face) (setq face 'hi-yellow)) |
| 411 | (unless hi-lock-mode (hi-lock-mode 1)) | 410 | (unless hi-lock-mode (hi-lock-mode 1)) |
| @@ -423,7 +422,7 @@ highlighting will not update as you type." | |||
| 423 | ;;;###autoload | 422 | ;;;###autoload |
| 424 | (defun hi-lock-face-buffer (regexp &optional face subexp lighter) | 423 | (defun hi-lock-face-buffer (regexp &optional face subexp lighter) |
| 425 | "Set face of each match of REGEXP to FACE. | 424 | "Set face of each match of REGEXP to FACE. |
| 426 | Interactively, prompt for REGEXP using `read-regexp', then FACE. | 425 | Interactively, prompt for REGEXP using `hi-lock-read-regexp', then FACE. |
| 427 | Use the global history list for FACE. Limit face setting to the | 426 | Use the global history list for FACE. Limit face setting to the |
| 428 | corresponding SUBEXP (interactively, the prefix argument) of REGEXP. | 427 | corresponding SUBEXP (interactively, the prefix argument) of REGEXP. |
| 429 | If SUBEXP is omitted or nil, the entire REGEXP is highlighted. | 428 | If SUBEXP is omitted or nil, the entire REGEXP is highlighted. |
| @@ -443,14 +442,7 @@ causes `font-lock-specified-p' to return non-nil, which means | |||
| 443 | the major mode specifies support for Font Lock." | 442 | the major mode specifies support for Font Lock." |
| 444 | (interactive | 443 | (interactive |
| 445 | (list | 444 | (list |
| 446 | (hi-lock-regexp-okay | 445 | (hi-lock-read-regexp "Regexp to highlight") |
| 447 | (read-regexp "Regexp to highlight" | ||
| 448 | (if (use-region-p) | ||
| 449 | (prog1 | ||
| 450 | (buffer-substring (region-beginning) | ||
| 451 | (region-end)) | ||
| 452 | (deactivate-mark)) | ||
| 453 | 'regexp-history-last))) | ||
| 454 | (hi-lock-read-face-name) | 446 | (hi-lock-read-face-name) |
| 455 | current-prefix-arg)) | 447 | current-prefix-arg)) |
| 456 | (when (stringp face) | 448 | (when (stringp face) |
| @@ -469,7 +461,7 @@ the major mode specifies support for Font Lock." | |||
| 469 | ;;;###autoload | 461 | ;;;###autoload |
| 470 | (defun hi-lock-face-phrase-buffer (regexp &optional face) | 462 | (defun hi-lock-face-phrase-buffer (regexp &optional face) |
| 471 | "Set face of each match of phrase REGEXP to FACE. | 463 | "Set face of each match of phrase REGEXP to FACE. |
| 472 | Interactively, prompt for REGEXP using `read-regexp', then FACE. | 464 | Interactively, prompt for REGEXP using `hi-lock-read-regexp', then FACE. |
| 473 | Use the global history list for FACE. | 465 | Use the global history list for FACE. |
| 474 | 466 | ||
| 475 | If REGEXP contains upper case characters (excluding those preceded by `\\') | 467 | If REGEXP contains upper case characters (excluding those preceded by `\\') |
| @@ -484,8 +476,7 @@ causes `font-lock-specified-p' to return non-nil, which means | |||
| 484 | the major mode specifies support for Font Lock." | 476 | the major mode specifies support for Font Lock." |
| 485 | (interactive | 477 | (interactive |
| 486 | (list | 478 | (list |
| 487 | (hi-lock-regexp-okay | 479 | (hi-lock-read-regexp "Phrase to highlight") |
| 488 | (read-regexp "Phrase to highlight" 'regexp-history-last)) | ||
| 489 | (hi-lock-read-face-name))) | 480 | (hi-lock-read-face-name))) |
| 490 | (or (facep face) (setq face 'hi-yellow)) | 481 | (or (facep face) (setq face 'hi-yellow)) |
| 491 | (unless hi-lock-mode (hi-lock-mode 1)) | 482 | (unless hi-lock-mode (hi-lock-mode 1)) |
| @@ -726,6 +717,21 @@ with completion and history." | |||
| 726 | (add-to-list 'hi-lock-face-defaults face t)) | 717 | (add-to-list 'hi-lock-face-defaults face t)) |
| 727 | (intern face))) | 718 | (intern face))) |
| 728 | 719 | ||
| 720 | (defun hi-lock-read-regexp (prompt) | ||
| 721 | "Read font-lock pattern from the minibuffer and return it. | ||
| 722 | |||
| 723 | The pattern is read using `read-regexp' with PROMPT and validated using | ||
| 724 | `hi-lock-regexp-okay'. If the region is active, use its content as the | ||
| 725 | default value." | ||
| 726 | (hi-lock-regexp-okay | ||
| 727 | (read-regexp prompt | ||
| 728 | (if (use-region-p) | ||
| 729 | (prog1 | ||
| 730 | (buffer-substring (region-beginning) | ||
| 731 | (region-end)) | ||
| 732 | (deactivate-mark)) | ||
| 733 | 'regexp-history-last)))) | ||
| 734 | |||
| 729 | (defvar hi-lock-use-overlays nil | 735 | (defvar hi-lock-use-overlays nil |
| 730 | "Whether to always use overlays instead of font-lock rules. | 736 | "Whether to always use overlays instead of font-lock rules. |
| 731 | When `font-lock-mode' is enabled and the buffer specifies font-lock rules, | 737 | When `font-lock-mode' is enabled and the buffer specifies font-lock rules, |