Skip to content

Highlights minor mode #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Highlights minor mode #137

wants to merge 11 commits into from

Conversation

mishoo
Copy link
Contributor

@mishoo mishoo commented Sep 7, 2024

Here is a little mode that I've been using for years, perhaps others will find it useful. Pasting the commentary below:

;; This is a minor mode that highlights certain things of interest and
;; allows you to easily move through them. The most useful is
;; `js2r-highlight-thing-at-point', which highlights occurrences of
;; the thing at point. You'd normally use it on variables, and it
;; selects all occurrences in the defining scope, but it also works on
;; constants (highlights occurrences in the whole buffer), or on
;; "this" or "super" keywords.
;;
;; There's also `js2r-highlight-free-vars' which selects free
;; variables in the enclosing function, and `js2r-highlight-exits'
;; which selects exit points from the current function ("return" or
;; "throw" nodes).
;;
;; While highlights mode is on, the following key bindings are
;; available:
;;
;;     C-<down> - `js2r-highlight-move-next'
;;     C-<up> - `js2r-highlight-move-prev'
;;     C-<return> - `js2r-highlight-rename'
;;     <escape> or C-g - `js2r-highlight-forgetit'
;;
;; `js2r-highlight-rename' will replace all highlighted regions with
;; something else (you'll specify in the minibuffer). When used on
;; variables it takes care to maintain code semantics, for example in
;; situations like this:
;;
;;     let { foo } = obj;
;;
;; With the cursor on "foo", `js2r-highlight-thing-at-point' will
;; select all occurrences of "foo" in the enclosing scope, and if you
;; use rename, it will convert to something like this, instead of
;; simply renaming:
;;
;;     let { foo: newName } = obj;
;;
;; such that newName will still be initialized to obj.foo, as in the
;; original code.
;;
;; I use the following key bindings to enter highlights mode:
;;
;;     (define-key js2-refactor-mode-map (kbd "M-?") 'js2r-highlight-thing-at-point)
;;     (define-key js2-refactor-mode-map (kbd "C-c C-f") 'js2r-highlight-free-vars)
;;     (define-key js2-refactor-mode-map (kbd "C-c C-x") 'js2r-highlight-exits)
;;
;; There is also an utility function suitable for expand-region, I
;; have the following in my `js2-mode-hook':
;;
;;     (setq er/try-expand-list '(js2r-highlight-extend-region))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant