lex-hl

Highlight lexically bound variables
git clone git://jamzattack.xyz/lex-hl.git
Log | Files | Refs

commit f9cca2dedaaa9b7766b4723d5365fc7c62c0d6d9
parent 9467663b77ae4568e5bbef85e3fef02c33f877ec
Author: Jamie Beardslee <jdb@jamzattack.xyz>
Date:   Fri, 11 Sep 2020 21:22:02 +1200

Make prefix arg behaviour consistent.

In general, a prefix argument unhilights the buffer unless it is
numeric.

Diffstat:
Mlex-hl.el | 67+++++++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 39 insertions(+), 28 deletions(-)

diff --git a/lex-hl.el b/lex-hl.el @@ -67,7 +67,7 @@ determined face." "A list of functions/macros that `lex-hl' can highlight.") (defun lex-hl-add-form (symbol &optional function) - "FUNCTION highlights the variables bound by SYMBOl. + "FUNCTION highlights the variables bound by SYMBOL. If FUNCTION is omitted or nil, `lex-hl--SYMBOL' will be used." (put symbol 'lex-hl (or function (intern (format "lex-hl--%s" symbol)))) (add-to-list 'lex-hl-forms (symbol-name symbol))) @@ -130,42 +130,53 @@ If FUNCTION is omitted or nil, `lex-hl--SYMBOL' will be used." ;;; User-facing commands ;;;###autoload -(defun lex-hl-top-level () +(defun lex-hl-top-level (&optional unhilight) "Highlight variables bound in the top-level form at point. -See the variable `lex-hl-forms' for a list of supported forms." - (interactive) - (save-excursion - (beginning-of-defun) - (lex-hl-sexp-at-point))) +With prefix argument, UNHIGHLIGHT the buffer. See the variable +`lex-hl-forms' for a list of supported forms." + (interactive "P") + (if arg + (hi-lock-unface-buffer t) + (save-excursion + (beginning-of-defun) + (lex-hl-sexp-at-point)))) ;;;###autoload -(defun lex-hl-prompt (bounds) +(defun lex-hl-prompt (bounds &optional unhilight) "Highlight variables bound in the form chosen from the minibuffer. -This is limited to the region specified by BOUNDS. Interactively, -this is the top-level form at point, or the active region with a -prefix argument." - (interactive (if current-prefix-arg - (region-bounds) - (list (bounds-of-thing-at-point 'defun)))) - (let ((beg (car bounds)) - (end (cdr bounds)) - list) - (save-excursion - (goto-char beg) - (while (re-search-forward (lex-hl-generate-regexp) end :noerror) - (let ((match (match-beginning 0))) - (push (cons (buffer-substring match (line-end-position)) match) - list))) - (goto-char (cdr (assoc (completing-read "Highlight variables in: " list) - list))) - (lex-hl-sexp-at-point)))) +This is limited to the region specified by BOUNDS which, +interactively, is the top-level form (aka defun) at point, or the +active region with a prefix argument. If prefix arg is negative +or zero, UNHIGHLIGHT the buffer." + (interactive (cond ((<= (prefix-numeric-value current-prefix-arg) 0) + '((nil) t)) + (current-prefix-arg + (region-bounds)) + (t + (list (bounds-of-thing-at-point 'defun))))) + (if unhilight + (hi-lock-unface-buffer t) + (let ((beg (car bounds)) + (end (cdr bounds)) + (current-prefix-arg nil) + list) + (save-excursion + (goto-char beg) + (while (re-search-forward (lex-hl-generate-regexp) end :noerror) + (let ((match (match-beginning 0))) + (push (cons (buffer-substring match (line-end-position)) match) + list))) + (goto-char (cdr (assoc (completing-read "Highlight variables in: " list) + list))) + (lex-hl-sexp-at-point))))) ;;;###autoload (defun lex-hl-nearest (n) "Highlight variables bound in the Nth nearest form. +If prefix arg is non-numeric, this instead unhilights the buffer. See the variable `lex-hl-forms' for a list of supported forms." - (interactive "p") - (if (<= n 0) + (interactive "P") + (if (and (listp n) (not (null n))) (hi-lock-unface-buffer t) (let ((beg (car (bounds-of-thing-at-point 'defun)))) (save-excursion