|
6 | 6 | ;; Version: 1.0.0 |
7 | 7 | ;; URL: https://github.com/jamescherti/bufferwizard.el |
8 | 8 | ;; Keywords: convenience |
9 | | -;; Package-Requires: ((emacs "26.1")) |
| 9 | +;; Package-Requires: ((emacs "28.1")) |
10 | 10 | ;; SPDX-License-Identifier: GPL-3.0-or-later |
11 | 11 |
|
12 | 12 | ;; This file is free software; you can redistribute it and/or modify |
@@ -241,39 +241,57 @@ This function confirms each replacement." |
241 | 241 |
|
242 | 242 | ;;; Highlight symbols |
243 | 243 |
|
| 244 | +(defun bufferwizard-get-symbol-or-region-regexp () |
| 245 | + "Return the regexp of the selected region or the default symbol at point." |
| 246 | + (when-let* ((regexp (if (use-region-p) |
| 247 | + (buffer-substring-no-properties (region-beginning) |
| 248 | + (region-end)) |
| 249 | + (find-tag-default)))) |
| 250 | + regexp)) |
| 251 | + |
244 | 252 | (defun bufferwizard-highlight-p () |
245 | 253 | "Return non-nil the symbol at point is currently highlighted." |
246 | | - (when-let* ((regexp (find-tag-default-as-symbol-regexp))) |
| 254 | + (when-let* ((regexp (bufferwizard-get-symbol-or-region-regexp))) |
247 | 255 | (member regexp (hi-lock--regexps-at-point)))) |
248 | 256 |
|
249 | 257 | ;;;###autoload |
250 | | -(defun bufferwizard-highlight-symbol-at-point () |
| 258 | +(defun bufferwizard-highlight-at-point () |
251 | 259 | "Highlight the symbol at point in the current buffer. |
252 | 260 |
|
253 | 261 | This function identifies the symbol at the current point, generates the |
254 | 262 | appropriate regular expression for it, and applies highlighting using the |
255 | 263 | built-in `hi-lock' package." |
256 | 264 | (interactive) |
257 | | - (when-let* ((regexp (find-tag-default-as-symbol-regexp))) |
258 | | - (hi-lock-face-symbol-at-point))) |
| 265 | + ;; Similar to `hi-lock-face-symbol-at-point' |
| 266 | + (let* ((regexp (bufferwizard-get-symbol-or-region-regexp)) |
| 267 | + (hi-lock-auto-select-face t) |
| 268 | + (face (hi-lock-read-face-name))) |
| 269 | + (when regexp |
| 270 | + (or (facep face) (setq face 'hi-yellow)) |
| 271 | + (unless hi-lock-mode (hi-lock-mode 1)) |
| 272 | + (hi-lock-set-pattern |
| 273 | + regexp face nil nil |
| 274 | + (if (and case-fold-search search-upper-case) |
| 275 | + (isearch-no-upper-case-p regexp t) |
| 276 | + case-fold-search))))) |
259 | 277 |
|
260 | 278 | ;;;###autoload |
261 | | -(defun bufferwizard-unhighlight-symbol-at-point () |
| 279 | +(defun bufferwizard-unhighlight-at-point () |
262 | 280 | "Remove highlighting for the symbol at point." |
263 | 281 | (interactive) |
264 | | - (when-let* ((regexp (find-tag-default-as-symbol-regexp))) |
| 282 | + (when-let* ((regexp (bufferwizard-get-symbol-or-region-regexp))) |
265 | 283 | (hi-lock-unface-buffer regexp))) |
266 | 284 |
|
267 | 285 | ;;;###autoload |
268 | | -(defun bufferwizard-toggle-highlight-symbol-at-point () |
| 286 | +(defun bufferwizard-toggle-highlight-at-point () |
269 | 287 | "Toggle highlighting for the symbol at point. |
270 | 288 |
|
271 | 289 | This function checks if the symbol at point is currently highlighted. |
272 | 290 | If it is, it removes the highlight; otherwise, it applies the highlight." |
273 | 291 | (interactive) |
274 | 292 | (if (bufferwizard-highlight-p) |
275 | | - (bufferwizard-unhighlight-symbol-at-point) |
276 | | - (bufferwizard-highlight-symbol-at-point))) |
| 293 | + (bufferwizard-unhighlight-at-point) |
| 294 | + (bufferwizard-highlight-at-point))) |
277 | 295 |
|
278 | 296 | ;;;###autoload |
279 | 297 | (defun bufferwizard-unhighlight () |
|
0 commit comments