elisp-tree-sitter
elisp-tree-sitter copied to clipboard
Tree sitter highlighting breaks buffer content during search/replace (reproducible example within)
Ran into an interesting issue. When using evil mode's smart-case search/replace, buffer content's are "corrupted"/out of date if tree-sitter highlighting is enabled.
Here is reproducible example (tested on emacs 28 with native comp, same result on linux and macos):
init.el:
;;; Straight-el boostrap
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
;;; Evil
(straight-use-package 'evil)
(straight-use-package 'evil-collection)
(straight-use-package 'evil-surround)
(straight-use-package 'evil-commentary)
(customize-set-variable 'evil-want-integration t)
(customize-set-variable 'evil-want-keybinding nil)
(customize-set-variable 'evil-respect-visual-line-mode t)
(customize-set-variable 'evil-undo-system 'undo-redo)
(customize-set-variable 'evil-split-window-below t)
(customize-set-variable 'evil-vsplit-window-right t)
(customize-set-variable 'evil-want-C-u-scroll t)
(require 'evil)
(evil-mode 1)
(require 'evil-surround)
(global-evil-surround-mode 1)
(require 'evil-commentary)
(evil-commentary-mode)
(require 'evil-collection)
(evil-collection-init)
;;; Treesitter
(straight-use-package 'tree-sitter)
(straight-use-package 'tree-sitter-langs)
(require 'tree-sitter)
(require 'tree-sitter-langs)
;;; Typescript
(straight-use-package 'typescript-mode)
(require 'typescript-mode)
Example file to see issue (example.ts):
import * as SomeQueries from '../../queries/queries';
export const main = async (): void => {
try {
const result = await SomeQueries.query();
} catch (err) {
console.log('wowo err');
}
};
Steps:
emacs -nw example.ts- enable tree-sitter highlighting (e.g.
tree-sitter-hl-mode) - execute search and replace utilizing smart case (e.g.
:%s/some/other/g) - observe corrupt buffer contents (incorrect highlighting, incomplete replace, etc).
- (optional) perform same steps without activating
tree-sitter-hl-modeand observe no issue.