1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-02 18:21:19 -08:00

hi-lock: Use active region for default values in more places

* lisp/hi-lock.el (hi-lock-line-face-buffer, hi-lock-face-buffer)
(hi-lock-face-phrase-buffer): Use the new function
`hi-lock-read-regexp' to read font-lock patterns, mirroring
`hi-lock-read-face-name' used to read face names.  For end users,
all three functions now get the default value from the active
region, rather than just `hi-lock-face-buffer'.
(hi-lock-read-regexp): Extract font-lock pattern reading
functionality from `hi-lock-face-buffer' into this function, to
mirror how faces are read with `hi-lock-read-face-name' and to
promote reuse.  (Bug#79976)
This commit is contained in:
Rudolf Adamkovič 2025-12-09 13:35:42 +01:00 committed by Eli Zaretskii
parent 9e16010686
commit 985e942d1c
2 changed files with 29 additions and 15 deletions

View file

@ -3231,6 +3231,14 @@ Command 'antlr-run-tool' now usually runs on the file for the current
buffer. Customize this user option to have value ' nil' to get the
previous behavior back.
** Hi Lock
---
*** Use active region for default values in more functions.
If an active region exists, the commands 'hi-lock-line-face-buffer' and
'hi-lock-face-phrase-buffer' now use its contents as their default
value. Previously, only 'hi-lock-face-buffer' supported this.
* New Modes and Packages in Emacs 31.1

View file

@ -393,7 +393,7 @@ The lines that match REGEXP will be displayed by merging
the attributes of FACE with any other face attributes
of text in those lines.
Interactively, prompt for REGEXP using `read-regexp', then FACE.
Interactively, prompt for REGEXP using `hi-lock-read-regexp', then FACE.
Use the global history list for FACE.
If REGEXP contains upper case characters (excluding those preceded by `\\')
@ -404,8 +404,7 @@ use overlays for highlighting. If overlays are used, the
highlighting will not update as you type."
(interactive
(list
(hi-lock-regexp-okay
(read-regexp "Regexp to highlight line" 'regexp-history-last))
(hi-lock-read-regexp "Regexp to highlight line")
(hi-lock-read-face-name)))
(or (facep face) (setq face 'hi-yellow))
(unless hi-lock-mode (hi-lock-mode 1))
@ -423,7 +422,7 @@ highlighting will not update as you type."
;;;###autoload
(defun hi-lock-face-buffer (regexp &optional face subexp lighter)
"Set face of each match of REGEXP to FACE.
Interactively, prompt for REGEXP using `read-regexp', then FACE.
Interactively, prompt for REGEXP using `hi-lock-read-regexp', then FACE.
Use the global history list for FACE. Limit face setting to the
corresponding SUBEXP (interactively, the prefix argument) of REGEXP.
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
the major mode specifies support for Font Lock."
(interactive
(list
(hi-lock-regexp-okay
(read-regexp "Regexp to highlight"
(if (use-region-p)
(prog1
(buffer-substring (region-beginning)
(region-end))
(deactivate-mark))
'regexp-history-last)))
(hi-lock-read-regexp "Regexp to highlight")
(hi-lock-read-face-name)
current-prefix-arg))
(when (stringp face)
@ -469,7 +461,7 @@ the major mode specifies support for Font Lock."
;;;###autoload
(defun hi-lock-face-phrase-buffer (regexp &optional face)
"Set face of each match of phrase REGEXP to FACE.
Interactively, prompt for REGEXP using `read-regexp', then FACE.
Interactively, prompt for REGEXP using `hi-lock-read-regexp', then FACE.
Use the global history list for FACE.
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
the major mode specifies support for Font Lock."
(interactive
(list
(hi-lock-regexp-okay
(read-regexp "Phrase to highlight" 'regexp-history-last))
(hi-lock-read-regexp "Phrase to highlight")
(hi-lock-read-face-name)))
(or (facep face) (setq face 'hi-yellow))
(unless hi-lock-mode (hi-lock-mode 1))
@ -726,6 +717,21 @@ with completion and history."
(add-to-list 'hi-lock-face-defaults face t))
(intern face)))
(defun hi-lock-read-regexp (prompt)
"Read font-lock pattern from the minibuffer and return it.
The pattern is read using `read-regexp' with PROMPT and validated using
`hi-lock-regexp-okay'. If the region is active, use its content as the
default value."
(hi-lock-regexp-okay
(read-regexp prompt
(if (use-region-p)
(prog1
(buffer-substring (region-beginning)
(region-end))
(deactivate-mark))
'regexp-history-last))))
(defvar hi-lock-use-overlays nil
"Whether to always use overlays instead of font-lock rules.
When `font-lock-mode' is enabled and the buffer specifies font-lock rules,