Skip to content

Latest commit

 

History

History
114 lines (84 loc) · 4.85 KB

README.org

File metadata and controls

114 lines (84 loc) · 4.85 KB

Macrursors

An extremely fast and minimal alternative to multiple-cursors.el.

Overview

Macrursors leverages kmacro and emacs’ overlays to make a fast and extremely minimal multiple-cursor-like editing experience.

Speed

Macrursors is fast!

There is no overhead. Unlike multiple-cursors which applies edits to each cursor while you are multi-editing, macrursors waits till you are finished. While there is no live feedback on your cursors, you can edit overhead-free.

Macrursors only jumps to each cursor once. Multiple-cursors will jump to each cursor in successive order to apply each action. Instead, macrursors will apply all actions at once at each cursor, limiting the number of jumps to the number of cursors (O(n) rather than O(n*m)).

Macrursors also gives you the abilty to temporily turn off minor modes, change the setting of variables, and more while the edits are applying. Anything that is unneeded while applying edits (like auto-complete popups) is recommended to be temporarily turned off to further increase the speed.

;; The following code will turn off corfu only when the edits are being applied
(add-hook 'macrursors-pre-finish-hook 'corfu-mode)
(add-hook 'macrursors-post-finish-hook 'corfu-mode)

Size

Macrursors is minimal! It has no external dependencies.

Workflow

To use macrursors you can spawn a cursor at every line, word, s-exp, list, sentence, etc. From there make all edits you like and then apply the edits.

Unlike multiple cursors, macrursors has the ability to restrict all edits to a secondary selection. Directly inspired by meow, you can mark a selection as a secondary selection. Instead of spawning cursors across the entire buffer, the cursors will be limited to the secondary selection, a.k.a. “workspace”.

These commands can help navigating secondary selections easier.

(defun beginning-of-workspace ()
  "If a secondary selection is active, goto the beginning of it.
Else, goto the beginning of the buffer."
  (interactive)
  (if (and
      (secondary-selection-exist-p)
      (< (overlay-start mouse-secondary-overlay)
	 (overlay-end mouse-secondary-overlay))
      (<= (overlay-start mouse-secondary-overlay)
	 (point)
	 (overlay-end mouse-secondary-overlay)))
      (goto-char (overlay-start mouse-secondary-overlay))
    (goto-char (point-min))))

(defun end-of-workspace ()
  "If a secondary selection is active, goto the end of it.
Else, goto the end of the buffer."
  (interactive)
  (if (and
      (secondary-selection-exist-p)
      (< (overlay-start mouse-secondary-overlay)
	 (overlay-end mouse-secondary-overlay))
      (<= (overlay-start mouse-secondary-overlay)
	 (point)
	 (overlay-end mouse-secondary-overlay)))
      (goto-char (- (overlay-end mouse-secondary-overlay) 1))
    (goto-char (point-max))))

(global-set-key (kbd "M-<") #'beginning-of-workspace)
(global-set-key (kbd "M->") #'end-of-workspace)

Macrursors also has support to spawn a cursor at the direct next instance of something, without need for any selections.

Warnings

Macrursors is still in early development. Bugs are to be expected.

When invoked with M-x macrursors commands do not work. Only execute the commands through bound keys.

Motivation

multiple-cursors.el was too slow and heavy.

Install

Macrursors is not yet on Melpa, so you will need to manually add macrursors.el to your load path.

Usage

Example set up of macrursors.

(use-package macrursors
  :config
  (dolist (mode '(corfu-mode goggles-mode beacon-mode))
    (add-hook 'macrursors-pre-finish-hook mode)
    (add-hook 'macrursors-post-finish-hook mode))
  (define-prefix-command 'macrursors-mark-map)
  (global-set-key (kbd "C-c SPC") #'macrursors-select)
  (global-set-key (kbd "C->") #'macrursors-mark-next-instance-of)
  (global-set-key (kbd "C-<") #'macrursors-mark-previous-instance-of)
  (global-set-key (kbd "C-;") 'macrursors-mark-map)
  (define-key macrursors-mark-map (kbd "C-;") #'macrursors-mark-all-lines-or-instances)
  (define-key macrursors-mark-map (kbd ";") #'macrursors-mark-all-lines-or-instances)
  (define-key macrursors-mark-map (kbd "l") #'macrursors-mark-all-lists)
  (define-key macrursors-mark-map (kbd "s") #'macrursors-mark-all-symbols)
  (define-key macrursors-mark-map (kbd "e") #'macrursors-mark-all-sexps)
  (define-key macrursors-mark-map (kbd "f") #'macrursors-mark-all-defuns)
  (define-key macrursors-mark-map (kbd "n") #'macrursors-mark-all-numbers)
  (define-key macrursors-mark-map (kbd ".") #'macrursors-mark-all-sentences)
  (define-key macrursors-mark-map (kbd "r") #'macrursors-mark-all-lines))

Documentation

License

Copyright (c) 2023 Licensed under the GPL3 License.