mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-16 10:50:49 -08:00
Provide for customizing default regexp in hi-lock commands (Bug#13892).
* lisp/hi-lock.el (hi-lock-read-regexp-defaults-function): New var. (hi-lock-read-regexp-defaults): New defun. (hi-lock-line-face-buffer, hi-lock-face-buffer) (hi-lock-face-phrase-buffer): Propagate above change. Update docstring. * lisp/subr.el (find-tag-default-as-regexp): New defun. * lisp/replace.el (read-regexp): Propagate above change.
This commit is contained in:
parent
0bce5d9eb8
commit
eb1a6e153a
4 changed files with 80 additions and 30 deletions
|
|
@ -1,3 +1,14 @@
|
||||||
|
2013-03-08 Jambunathan K <kjambunathan@gmail.com>
|
||||||
|
|
||||||
|
* hi-lock.el (hi-lock-read-regexp-defaults-function): New var.
|
||||||
|
(hi-lock-read-regexp-defaults): New defun.
|
||||||
|
(hi-lock-line-face-buffer, hi-lock-face-buffer)
|
||||||
|
(hi-lock-face-phrase-buffer): Propagate above change. Update
|
||||||
|
docstring (bug#13892).
|
||||||
|
|
||||||
|
* subr.el (find-tag-default-as-regexp): New defun.
|
||||||
|
* replace.el (read-regexp): Propagate above change.
|
||||||
|
|
||||||
2013-03-08 Jay Belanger <jay.p.belanger@gmail.com>
|
2013-03-08 Jay Belanger <jay.p.belanger@gmail.com>
|
||||||
|
|
||||||
* calc/calc-units.el (calc-convert-units): Fix the way that default
|
* calc/calc-units.el (calc-convert-units): Fix the way that default
|
||||||
|
|
|
||||||
|
|
@ -279,6 +279,26 @@ a library is being loaded.")
|
||||||
map)
|
map)
|
||||||
"Key map for hi-lock.")
|
"Key map for hi-lock.")
|
||||||
|
|
||||||
|
(defvar hi-lock-read-regexp-defaults-function
|
||||||
|
'hi-lock-read-regexp-defaults
|
||||||
|
"Function that provides default regexp(s) for highlighting commands.
|
||||||
|
This function should take no arguments and return one of nil, a
|
||||||
|
regexp or a list of regexps for use with highlighting commands -
|
||||||
|
`hi-lock-face-phrase-buffer', `hi-lock-line-face-buffer' and
|
||||||
|
`hi-lock-face-buffer'. The return value of this function is used
|
||||||
|
as DEFAULTS param of `read-regexp' while executing the
|
||||||
|
highlighting command. This function is called only during
|
||||||
|
interactive use.
|
||||||
|
|
||||||
|
For example, to highlight at symbol at point use
|
||||||
|
|
||||||
|
\(setq hi-lock-read-regexp-defaults-function
|
||||||
|
'find-tag-default-as-regexp\)
|
||||||
|
|
||||||
|
If you need different defaults for different highlighting
|
||||||
|
operations, use `this-command' to identify the command under
|
||||||
|
execution.")
|
||||||
|
|
||||||
;; Visible Functions
|
;; Visible Functions
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
|
@ -399,17 +419,18 @@ versions before 22 use the following in your init file:
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun hi-lock-line-face-buffer (regexp &optional face)
|
(defun hi-lock-line-face-buffer (regexp &optional face)
|
||||||
"Set face of all lines containing a match of REGEXP to FACE.
|
"Set face of all lines containing a match of REGEXP to FACE.
|
||||||
Interactively, prompt for REGEXP then FACE, using a buffer-local
|
Interactively, prompt for REGEXP then FACE. Use
|
||||||
history list for REGEXP and a global history list for FACE.
|
`hi-lock-read-regexp-defaults-function' to retrieve default
|
||||||
|
value(s) of REGEXP. Use the global history list for FACE.
|
||||||
|
|
||||||
If Font Lock mode is enabled in the buffer, it is used to
|
Use Font lock mode, if enabled, to highlight REGEXP. Otherwise,
|
||||||
highlight REGEXP. If Font Lock mode is disabled, overlays are
|
use overlays for highlighting. If overlays are used, the
|
||||||
used for highlighting; in this case, the highlighting will not be
|
highlighting will not update as you type."
|
||||||
updated as you type."
|
|
||||||
(interactive
|
(interactive
|
||||||
(list
|
(list
|
||||||
(hi-lock-regexp-okay
|
(hi-lock-regexp-okay
|
||||||
(read-regexp "Regexp to highlight line" (car regexp-history)))
|
(read-regexp "Regexp to highlight line"
|
||||||
|
(funcall hi-lock-read-regexp-defaults-function)))
|
||||||
(hi-lock-read-face-name)))
|
(hi-lock-read-face-name)))
|
||||||
(or (facep face) (setq face 'hi-yellow))
|
(or (facep face) (setq face 'hi-yellow))
|
||||||
(unless hi-lock-mode (hi-lock-mode 1))
|
(unless hi-lock-mode (hi-lock-mode 1))
|
||||||
|
|
@ -424,17 +445,18 @@ updated as you type."
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun hi-lock-face-buffer (regexp &optional face)
|
(defun hi-lock-face-buffer (regexp &optional face)
|
||||||
"Set face of each match of REGEXP to FACE.
|
"Set face of each match of REGEXP to FACE.
|
||||||
Interactively, prompt for REGEXP then FACE, using a buffer-local
|
Interactively, prompt for REGEXP then FACE. Use
|
||||||
history list for REGEXP and a global history list for FACE.
|
`hi-lock-read-regexp-defaults-function' to retrieve default
|
||||||
|
value(s) REGEXP. Use the global history list for FACE.
|
||||||
|
|
||||||
If Font Lock mode is enabled in the buffer, it is used to
|
Use Font lock mode, if enabled, to highlight REGEXP. Otherwise,
|
||||||
highlight REGEXP. If Font Lock mode is disabled, overlays are
|
use overlays for highlighting. If overlays are used, the
|
||||||
used for highlighting; in this case, the highlighting will not be
|
highlighting will not update as you type."
|
||||||
updated as you type."
|
|
||||||
(interactive
|
(interactive
|
||||||
(list
|
(list
|
||||||
(hi-lock-regexp-okay
|
(hi-lock-regexp-okay
|
||||||
(read-regexp "Regexp to highlight" (car regexp-history)))
|
(read-regexp "Regexp to highlight"
|
||||||
|
(funcall hi-lock-read-regexp-defaults-function)))
|
||||||
(hi-lock-read-face-name)))
|
(hi-lock-read-face-name)))
|
||||||
(or (facep face) (setq face 'hi-yellow))
|
(or (facep face) (setq face 'hi-yellow))
|
||||||
(unless hi-lock-mode (hi-lock-mode 1))
|
(unless hi-lock-mode (hi-lock-mode 1))
|
||||||
|
|
@ -445,18 +467,22 @@ updated as you type."
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun hi-lock-face-phrase-buffer (regexp &optional face)
|
(defun hi-lock-face-phrase-buffer (regexp &optional face)
|
||||||
"Set face of each match of phrase REGEXP to FACE.
|
"Set face of each match of phrase REGEXP to FACE.
|
||||||
If called interactively, replaces whitespace in REGEXP with
|
Interactively, prompt for REGEXP then FACE. Use
|
||||||
arbitrary whitespace and makes initial lower-case letters case-insensitive.
|
`hi-lock-read-regexp-defaults-function' to retrieve default
|
||||||
|
value(s) of REGEXP. Use the global history list for FACE. When
|
||||||
|
called interactively, replace whitespace in user provided regexp
|
||||||
|
with arbitrary whitespace and make initial lower-case letters
|
||||||
|
case-insensitive before highlighting with `hi-lock-set-pattern'.
|
||||||
|
|
||||||
If Font Lock mode is enabled in the buffer, it is used to
|
Use Font lock mode, if enabled, to highlight REGEXP. Otherwise,
|
||||||
highlight REGEXP. If Font Lock mode is disabled, overlays are
|
use overlays for highlighting. If overlays are used, the
|
||||||
used for highlighting; in this case, the highlighting will not be
|
highlighting will not update as you type."
|
||||||
updated as you type."
|
|
||||||
(interactive
|
(interactive
|
||||||
(list
|
(list
|
||||||
(hi-lock-regexp-okay
|
(hi-lock-regexp-okay
|
||||||
(hi-lock-process-phrase
|
(hi-lock-process-phrase
|
||||||
(read-regexp "Phrase to highlight" (car regexp-history))))
|
(read-regexp "Phrase to highlight"
|
||||||
|
(funcall hi-lock-read-regexp-defaults-function))))
|
||||||
(hi-lock-read-face-name)))
|
(hi-lock-read-face-name)))
|
||||||
(or (facep face) (setq face 'hi-yellow))
|
(or (facep face) (setq face 'hi-yellow))
|
||||||
(unless hi-lock-mode (hi-lock-mode 1))
|
(unless hi-lock-mode (hi-lock-mode 1))
|
||||||
|
|
@ -622,6 +648,11 @@ not suitable."
|
||||||
(error "Regexp cannot match an empty string")
|
(error "Regexp cannot match an empty string")
|
||||||
regexp))
|
regexp))
|
||||||
|
|
||||||
|
(defun hi-lock-read-regexp-defaults ()
|
||||||
|
"Return the latest regexp from `regexp-history'.
|
||||||
|
See `hi-lock-read-regexp-defaults-function' for details."
|
||||||
|
(car regexp-history))
|
||||||
|
|
||||||
(defun hi-lock-read-face-name ()
|
(defun hi-lock-read-face-name ()
|
||||||
"Return face for interactive highlighting.
|
"Return face for interactive highlighting.
|
||||||
When `hi-lock-auto-select-face' is non-nil, just return the next face.
|
When `hi-lock-auto-select-face' is non-nil, just return the next face.
|
||||||
|
|
|
||||||
|
|
@ -603,15 +603,7 @@ If HISTORY is nil, `regexp-history' is used."
|
||||||
(append
|
(append
|
||||||
suggestions
|
suggestions
|
||||||
(list
|
(list
|
||||||
;; Regexp for tag at point.
|
(find-tag-default-as-regexp)
|
||||||
(let* ((tagf (or find-tag-default-function
|
|
||||||
(get major-mode 'find-tag-default-function)
|
|
||||||
'find-tag-default))
|
|
||||||
(tag (funcall tagf)))
|
|
||||||
(cond ((not tag) "")
|
|
||||||
((eq tagf 'find-tag-default)
|
|
||||||
(format "\\_<%s\\_>" (regexp-quote tag)))
|
|
||||||
(t (regexp-quote tag))))
|
|
||||||
(car regexp-search-ring)
|
(car regexp-search-ring)
|
||||||
(regexp-quote (or (car search-ring) ""))
|
(regexp-quote (or (car search-ring) ""))
|
||||||
(car (symbol-value query-replace-from-history-variable)))))
|
(car (symbol-value query-replace-from-history-variable)))))
|
||||||
|
|
|
||||||
16
lisp/subr.el
16
lisp/subr.el
|
|
@ -2697,6 +2697,22 @@ If there is no plausible default, return nil."
|
||||||
(setq to (point)))))
|
(setq to (point)))))
|
||||||
(buffer-substring-no-properties from to))))
|
(buffer-substring-no-properties from to))))
|
||||||
|
|
||||||
|
(defun find-tag-default-as-regexp ()
|
||||||
|
"Return regexp that matches the default tag at point.
|
||||||
|
If there is no tag at point, return nil.
|
||||||
|
|
||||||
|
When in a major mode that does not provide it's own
|
||||||
|
`find-tag-default-function', return a regexp that matches the
|
||||||
|
symbol at point exactly."
|
||||||
|
(let* ((tagf (or find-tag-default-function
|
||||||
|
(get major-mode 'find-tag-default-function)
|
||||||
|
'find-tag-default))
|
||||||
|
(tag (funcall tagf)))
|
||||||
|
(cond ((not tag))
|
||||||
|
((eq tagf 'find-tag-default)
|
||||||
|
(format "\\_<%s\\_>" (regexp-quote tag)))
|
||||||
|
(t (regexp-quote tag)))))
|
||||||
|
|
||||||
(defun play-sound (sound)
|
(defun play-sound (sound)
|
||||||
"SOUND is a list of the form `(sound KEYWORD VALUE...)'.
|
"SOUND is a list of the form `(sound KEYWORD VALUE...)'.
|
||||||
The following keywords are recognized:
|
The following keywords are recognized:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue