Project Awesome project awesome

region-occurrences-highlighter

Highlights occurrences of the current selected region.

Package 29 stars GitHub

[[https://jcs-emacs.github.io/jcs-elpa/#/region-occurrences-highlighter][file:https://raw.githubusercontent.com/jcs-emacs/badges/master/elpa/v/region-occurrences-highlighter.svg]] [[https://melpa.org/#/region-occurrences-highlighter][file:https://melpa.org/packages/region-occurrences-highlighter-badge.svg]] [[https://github.com/alvarogonzalezsotillo/region-occurrences-highlighter/actions/workflows/test.ym][https://github.com/alvarogonzalezsotillo/region-occurrences-highlighter/actions/workflows/test.yml/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.

[[file: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.

#+begin_src emacs-lisp (require 'region-occurences-highlighter)

(add-hook 'prog-mode-hook 'region-occurrences-highlighter-mode) #+end_src

A global mode =global-region-occurrences-highlighter-mode= is also available (thanks to [[https://github.com/jcs090218][Jen-Chieh Shen]]).

** Installation from MELPA Also, it is [[https://melpa.org/#/region-occurrences-highlighter][available on MELPA]], and that is the preferred installation method. #+begin_src emacs-lisp (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)) #+end_src

  • 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:

#+begin_src emacs-lisp (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) #+end_src

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 [[https://github.com/xendk][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 [[https://www.gnu.org/software/emacs/manual/html_node/efaq/Controlling-case-sensitivity.html][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
Back to Emacs