diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3eade7..c924bd9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,8 +23,6 @@ jobs: strategy: matrix: emacs-version: - - 26.3 - - 27.1 - 28.1 - 29.1 - 29.4 diff --git a/README.md b/README.md index e7b290f..5312530 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ![](https://raw.githubusercontent.com/jamescherti/bufferwizard.el/main/.images/made-for-gnu-emacs.svg) The **bufferwizard** Emacs package offers a suite of helper functions: -- `(bufferwizard-toggle-highlight-symbol-at-point)`: Toggle highlighting for the symbol at point. This function checks if the symbol at point is currently highlighted. If it is, it removes the highlight; otherwise, it applies the highlight. (This is a lightweight alternative to the `highlight-symbol` package.) +- `(bufferwizard-toggle-highlight-at-point)`: Toggles highlighting for the symbol at point. If a selection is active, it highlights the selected text instead. This function checks whether the symbol at point or the selected text is currently highlighted. If it is, the highlight is removed; otherwise, it is applied. (This serves as a lightweight alternative to the `highlight-symbol` package.) - `(bufferwizard-replace-symbol-at-point)`: Replace occurrences of a symbol at point with a specified string. - `(bufferwizard-clone-indirect-buffer)` and `(bufferwizard-clone-and-switch-to-indirect-buffer)`: These functions are enhanced versions of the built-in `clone-indirect-buffer`. They create an indirect buffer with the same content as the current buffer while preserving the point position, window start, and horizontal scroll position. This package also provides the `(bufferwizard-switch-to-base-buffer)` function, which allows switching from an indirect buffer to its corresponding base buffer. @@ -40,9 +40,9 @@ To install `bufferwizard` with `use-package` and `:vc` (Emacs >= 30): #### Case sensitivity -The functions `(bufferwizard-toggle-highlight-symbol-at-point)` and `(bufferwizard-replace-symbol-at-point)` depend on built-in functions that can be customized via the following variable: +The functions `(bufferwizard-toggle-highlight-at-point)` and `(bufferwizard-replace-symbol-at-point)` depend on built-in functions that can be customized via the following variable: -- `case-fold-search`: This buffer-local variable determines the behavior of `(bufferwizard-toggle-highlight-symbol-at-point)` and `(bufferwizard-replace-symbol-at-point)`. When set to t (default), both symbol highlighting and searches become case-insensitive, matching symbols regardless of case. When set to nil, they become case-sensitive, matching symbols only when the case exactly matches the text in the buffer. +- `case-fold-search`: This buffer-local variable determines the behavior of `(bufferwizard-toggle-highlight-at-point)` and `(bufferwizard-replace-symbol-at-point)`. When set to t (default), both symbol highlighting and searches become case-insensitive, matching symbols regardless of case. When set to nil, they become case-sensitive, matching symbols only when the case exactly matches the text in the buffer. Example: ```elisp ;; Setting case-fold-search to nil enables case-sensitive symbol highlighting diff --git a/bufferwizard.el b/bufferwizard.el index 483cd96..dbddf64 100644 --- a/bufferwizard.el +++ b/bufferwizard.el @@ -6,7 +6,7 @@ ;; Version: 1.0.0 ;; URL: https://github.com/jamescherti/bufferwizard.el ;; Keywords: convenience -;; Package-Requires: ((emacs "26.1")) +;; Package-Requires: ((emacs "28.1")) ;; SPDX-License-Identifier: GPL-3.0-or-later ;; This file is free software; you can redistribute it and/or modify @@ -241,39 +241,57 @@ This function confirms each replacement." ;;; Highlight symbols +(defun bufferwizard-get-symbol-or-region-regexp () + "Return the regexp of the selected region or the default symbol at point." + (when-let* ((regexp (if (use-region-p) + (buffer-substring-no-properties (region-beginning) + (region-end)) + (find-tag-default)))) + regexp)) + (defun bufferwizard-highlight-p () "Return non-nil the symbol at point is currently highlighted." - (when-let* ((regexp (find-tag-default-as-symbol-regexp))) + (when-let* ((regexp (bufferwizard-get-symbol-or-region-regexp))) (member regexp (hi-lock--regexps-at-point)))) ;;;###autoload -(defun bufferwizard-highlight-symbol-at-point () +(defun bufferwizard-highlight-at-point () "Highlight the symbol at point in the current buffer. This function identifies the symbol at the current point, generates the appropriate regular expression for it, and applies highlighting using the built-in `hi-lock' package." (interactive) - (when-let* ((regexp (find-tag-default-as-symbol-regexp))) - (hi-lock-face-symbol-at-point))) + ;; Similar to `hi-lock-face-symbol-at-point' + (let* ((regexp (bufferwizard-get-symbol-or-region-regexp)) + (hi-lock-auto-select-face t) + (face (hi-lock-read-face-name))) + (when regexp + (or (facep face) (setq face 'hi-yellow)) + (unless hi-lock-mode (hi-lock-mode 1)) + (hi-lock-set-pattern + regexp face nil nil + (if (and case-fold-search search-upper-case) + (isearch-no-upper-case-p regexp t) + case-fold-search))))) ;;;###autoload -(defun bufferwizard-unhighlight-symbol-at-point () +(defun bufferwizard-unhighlight-at-point () "Remove highlighting for the symbol at point." (interactive) - (when-let* ((regexp (find-tag-default-as-symbol-regexp))) + (when-let* ((regexp (bufferwizard-get-symbol-or-region-regexp))) (hi-lock-unface-buffer regexp))) ;;;###autoload -(defun bufferwizard-toggle-highlight-symbol-at-point () +(defun bufferwizard-toggle-highlight-at-point () "Toggle highlighting for the symbol at point. This function checks if the symbol at point is currently highlighted. If it is, it removes the highlight; otherwise, it applies the highlight." (interactive) (if (bufferwizard-highlight-p) - (bufferwizard-unhighlight-symbol-at-point) - (bufferwizard-highlight-symbol-at-point))) + (bufferwizard-unhighlight-at-point) + (bufferwizard-highlight-at-point))) ;;;###autoload (defun bufferwizard-unhighlight ()