Highlight symbols with overlays while providing a keymap for various operations about highlighted symbols. It was originally inspired by the package highlight-symbol
. The fundamental difference is that in symbol-overlay
every symbol is highlighted by the Emacs built-in function overlay-put
rather than the font-lock
mechanism used in highlight-symbol
.
New commands symbol-overlay-jump-first
(key "<") and symbol-overlay-jump-last
(key ">") are now enabled.
New customizable variable symbol-overlay-displayed-window
is introduced to control the overlay behavior at symbol-overlay-mode
. If it is non-nil, occurrences outside the displayed window will not be counted or highlighted.
symbol-overlay-toggle-in-scope
now affects both global and in-scope highlighting. symbol-overlay-rename
now uses the original symbol name as the initial text in minibuffer. New command symbol-overlay-count
for counting symbol at point. And other improvements.
Minor-mode symbol-overlay-mode
for auto-highlighting is now enabled.
Toggling to isearch-mode is now enabled. Try symbol-overlay-isearch-literally
via "s" to search the not-quoted symbol in isearch-mode.
Toggling overlays to be showed in buffer or only in scope is now enabled. When symbol is highlighted in scope, all related operations is narrowed to the scope, too. Try symbol-overlay-toggle-in-scope
via "t". This feature is applicable only for languages that support the lisp function narrow-to-defun
. Otherwise you may specify beginning-of-defun-function
and end-of-defun-function
on your own.
Auto-refresh is now enabled. Every time the highlighted text is changed or a new occurrence shows up, the buffer will refresh automatically.
Two new commands added: symbol-overlay-save-symbol
for copying the current symbol, symbol-overlay-echo-mark
for undoing a recent jump.
When highlighting symbols in a buffer of regular size and language, overlay-put
behaves as fast as the traditional Highlighting method font-lock
. However, for a buffer of major-mode with complicated keywords syntax, like haskell-mode, font-lock
is quite slow even the buffer is less than 100 lines. Besides, when counting the number of highlighted occurrences, highlight-symbol
will call the function how-many
twice, which could also result in an unpleasant delay in a large buffer. Those problems don't exist in symbol-overlay
.
When putting overlays on symbols, an auto-activated overlay-inside keymap will enable you to call various useful commands with a single keystroke.
symbol-overlay-put
symbol-overlay-jump-next
& symbol-overlay-jump-prev
symbol-overlay-switch-forward
& symbol-overlay-switch-backward
symbol-overlay-mode
symbol-overlay-remove-all
symbol-overlay-save-symbol
symbol-overlay-toggle-in-scope
symbol-overlay-echo-mark
symbol-overlay-jump-to-definition
regexp-quote
the symbol: symbol-overlay-isearch-literally
symbol-overlay-query-replace
symbol-overlay-rename
To use symbol-overlay
in your Emacs, you need only to bind these keys:
(require 'symbol-overlay)
(global-set-key (kbd "M-i") 'symbol-overlay-put)
(global-set-key (kbd "M-n") 'symbol-overlay-switch-forward)
(global-set-key (kbd "M-p") 'symbol-overlay-switch-backward)
(global-set-key (kbd "<f7>") 'symbol-overlay-mode)
(global-set-key (kbd "<f8>") 'symbol-overlay-remove-all)
Default key-bindings defined in symbol-overlay-map
:
"i" -> symbol-overlay-put
"n" -> symbol-overlay-jump-next
"p" -> symbol-overlay-jump-prev
"w" -> symbol-overlay-save-symbol
"t" -> symbol-overlay-toggle-in-scope
"e" -> symbol-overlay-echo-mark
"d" -> symbol-overlay-jump-to-definition
"s" -> symbol-overlay-isearch-literally
"q" -> symbol-overlay-query-replace
"r" -> symbol-overlay-rename
You can re-bind the commands to any keys you prefer by simply writing
(define-key symbol-overlay-map (kbd "your-prefer-key") 'any-command)
Or you may prefer to overwrite the keymap
(let ((map (make-sparse-keymap)))
(define-key map (kbd "key1") 'command-1)
(define-key map (kbd "key2") 'command-2)
(setq symbol-overlay-map map))
As a final example, you can define a handy set of keys using transient
:
see the snippet posted here.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。