Skip to content

This emacs package implements a local minor mode that highlights occurrences of the current selected region.

License

Notifications You must be signed in to change notification settings

alvarogonzalezsotillo/region-occurrences-highlighter

Repository files navigation

https://melpa.org/packages/region-occurrences-highlighter-badge.svg

This emacs package implements a local minor mode that highlights occurrences of the current selected region. It uses the built-it highlight-regexp function.

screencast.gif

Installation

Add the file region-occurrences-highlighter to your load-path, require it, and enable it for each buffer with alt-x region-occurences-highlighter-mode.

You can add a hook to enable it when oppening a buffer, as in the code below.

(require 'region-occurences-highlighter)

(add-hook 'prog-mode-hook 'region-occurrences-highlighter-mode)

A global mode global-region-occurrences-highlighter-mode is also available (thanks to Jen-Chieh Shen).

Installation from MELPA

Also, it is available on MELPA, and that is the preferred installation method.

(use-package region-occurrences-highlighter 
  :ensure t
  :config
  (add-hook 'prog-mode-hook #'region-occurrences-highlighter-mode)
  (add-hook 'org-mode-hook #'region-occurrences-highlighter-mode)
  (add-hook 'text-mode-hook #'region-occurrences-highlighter-mode))

Navigation between occurrences

In order to add keyboard navigation between highlighted regions, bind your preferred keys in the region-occurrences-highlighter-nav-mode-map keymap:

(define-key region-occurrences-highlighter-nav-mode-map "\M-n" 'region-occurrences-highlighter-next)
(define-key region-occurrences-highlighter-nav-mode-map "\M-p" 'region-occurrences-highlighter-prev)

The region-occurrences-highlighter-nav-mode-map map is only active when regions are highlighted, so the keys can have other bindings when no region highlights exist (thanks to Thomas Fini Hansen).

Customization

The following options are available in customize:

  • region-occurrences-highlighter-all-visible-buffers: In non nil, occurrences are highlighted in the buffers of all visible windows and frames. Defaults to t.
  • region-occurrences-highlighter-face: Face used to highlight the occurrences. Defaults to inverse text.
  • region-occurrences-highlighter-min-size: Minimum region length to highlight occurrences. Defaults to 3.
  • region-occurrences-highlighter-max-size: Maximum region length to highlight occurrences. Defaults to 300.
  • region-occurrences-highlighter-ignore-regex: If defined, selections matching this regex will be ignored. Defaults to [[:space:]\n]+
  • region-occurences-highlighter-case-fold-search: Non-nil means highlightings will ignore case (see case-fold-search).

Possible improvements

  • A post-command-hook is used in order to detect all region changes, including mouse selections. This can lead to performance problems. Another option could be to hook point and mark changes.
  • The current behavior mimics other editors like VSCode, where the highlight takes place instantaneously. Some kind of delay could be implemented in order to improve performance

Similar solutions

About

This emacs package implements a local minor mode that highlights occurrences of the current selected region.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published