Semantic aware extend selection for Emacs (and Vim, if **you** write vimscript ;))

Hi! I’ve written a quick hack, using libsyntax2/rust-analizer, which some of you Emacs users might find useful!

The hack is an ra-extend-selection function, which implements Rust syntax-aware selection. Here’s a short demo: https://youtu.be/NCBgiAmRro8.

To use it, install Rust analyzer (Rust 1.29.0 is required):

cargo install --git https://github.com/matklad/rust-analyzer/ --rev 5901e98  ra_cli 

Then drop this snippet into your init.el.

Then, add shortcuts for the Rust mode:

(require 'rust-mode)
(define-key rust-mode-map (kbd "C-w") 'ra-extend-selection)
(define-key rust-mode-map (kbd "C-S-w") 'ra-shrink-selection)

If you are a vim user, and you want this feature as well, you’ll have to write the vim-side of support yourself :wink: If you do it, feel free to send a PR which adds it here.

5 Likes

Nice! I’m using expand-region (which does a nice job based on delimiters and heuristics), now I can replace this in rust-mode.

BTW: how did you internalize ace-jump mode? I tried a few times, but it is so radically different that I could never train myself to use it instead of ordinary cursor movement…

I’ve just used way too may different editors (sublime, ergoemacs, plain emacs, evil emacs, vim, IntelliJ with vanilla/emacs/vim shortcuts), so I just got used to quickly adopting different ways of editing text.

I’ve began using ace-jump regularly after I’ve switch from Vim-style editing to just remapping CapsLock + ijkl to arrow keys systemwide (following this post). The fact that you don’t have to touch arrow keys with default config in any application is awesome, but I was missing Vim’s f and F. And both IntelliJ & Emacs have excellent ace-jump implementations :slight_smile: