Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ jobs:
strategy:
matrix:
emacs-version:
- 26.3
- 27.1
- 28.1
- 29.1
- 29.4
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
38 changes: 28 additions & 10 deletions bufferwizard.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ()
Expand Down