aatmunbaxi / lasgun.el

Avy-backed, actionable placement of multiple marks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lasgun.el

lasgun-demo.gif

lasgun.el (lays-gun) provides avy-backed, actionable placement of multiple inactive marks in the current buffer. Once these marks have been collected, you can act on the marks in bulk, without disturbing your point (with some obvious exceptions). If this sounds familiar to how avy works, it is! lasgun simply generalizes the Filter -> Select -> Act from avy to one that works on multiple selected candidates.

Why lasgun.el?

  • Avy provides an excellent Filter -> Select -> Act loop. lasgun.el generalizes this to allow multiple runs of Filter -> Select, and Acting when all candidates are selected.
    • So using lasgun.el only makes sense when acting on multiple candidates in bulk
  • This package is extremely simple; the bulk of it is all of two macros.
  • It only provides ingredients, though a small example of a user interface with hercules is provided: hercules-lasgun-example.el (note: depends on general.el and which-key).

Usage

  • Call a lasgun-mark function to mark a buffer position via avy
    • Repeat until desired positions are marked
  • Decide to act on each of these positions or not
    • Actions can be defined with the define-lasgun-action macro. See its docstring for information.

If not acting at lasgun marks, it might be useful to set lasgun-also-push-mark-ring to t, so lasgun marks remain in the mark-ring after clearing the lasgun-mark-ring.

Installation

For example, via straight:

(straight-use-package
 '(lasgun :type git :host github :repo "aatmunbaxi/lasgun.el")

DOOM emacs, in packages.el:

(package! lasgun :recipe (:host github "aatmunbaxi/lasgun.el"))

If your package manager does not support git recipes, a simple git clone and placement of

(add-to-list 'load-path "path/to/lasgun.el")
(require 'lasgun)

in your init.el will do.

Example transient Configuration

The demo gif shows an example UI with hercules. u/Hammar_Morty kindly provided a close translation making use of transient:

(require 'transient)

;; Defines some lasgun actions
(define-lasgun-action lasgun-action-upcase-word t upcase-word)
(define-lasgun-action lasgun-action-downcase-word t downcase-word)
(define-lasgun-action lasgun-action-kill-word nil kill-word)

(transient-define-prefix lasgun-transient ()
  "Main transient for lasgun."
  [["Marks"
    ("c" "Char timer" lasgun-mark-char-timer :transient t)
    ("w" "Word" lasgun-mark-word-0 :transient t)
    ("l" "Begin of line" lasgun-mark-line :transient t)
    ("s" "Symbol" lasgun-mark-symbol-1 :transient t)
    ("o" "Whitespace end" lasgun-mark-whitespace-end :transient t)
    ("x" "Clear lasgun mark ring" lasgun-clear-lasgun-mark-ring :transient t)
    ("u" "Undo lasgun mark" lasgun-pop-lasgun-mark :transient t)]
   ["Actions"
    ("SPC" "Make cursors" lasgun-make-multiple-cursors)
    ("." "Embark act all" lasgun-embark-act-all)
    ("U" "Upcase" lasgun-action-upcase-word)
    ("l" "Downcase" lasgun-action-downcase-word)
    ("K" "Kill word" lasgun-action-kill-word)
    ("q" "Quit" transient-quit-one)]])

(global-set-key (kbd "C-c t g") 'lasgun-transient)

Dependencies

  • avy
  • Optional:
    • multiple-cursors for lasgun-make-multiple-cursors
    • embark for lasgun-embark-act-all

Customizing

By “lasgun mark” we mean a buffer position stored in lasgun-mark-ring.

  • lasgun-mark-ring-max: Maximum number of lasgun marks
  • lasgun-pop-before-make-cursors: Place multiple-cursors cursors only at lasgun marks (can negate interactively, see lasgun-make-multiple-cursors docstring)
  • lasgun-also-push-mark-ring: Also push lasgun marks to buffer-local mark-ring
  • lasgun-use-lasgun-mark-overlay: Use visual overlays for lasgun marks
  • lasgun-persist-lasgun-mark-ring: Persist lasgun-mark-ring after performing action (Can override when defining lasgun actions, see define-lasgun-action docstring.)
  • lasgun-persist-negation-prefix-arg: Prefix arg with which to negate lasgun-persist-lasgun-mark-ring behavior
  • lasgun-mark-face: Face used to visually indicated lasgun marks

lasgun-mark functions

Lasgun provides analogues to nearly every avy-goto function. They are listed below. IMHO, it is an overwhelming number of choices; they are simply provided for completeness. It is recommended that you stick to a few staples, unless you’re using something to remember where each function is bound, like hercules or hydra.

  • lasgun-mark-end-of-line
  • lasgun-mark-line
  • lasgun-mark-word
  • lasgun-mark-char-2
  • lasgun-mark-symbol-1
  • lasgun-mark-subword-0
  • lasgun-mark-subword-1
  • lasgun-mark-char-timer
  • lasgun-mark-char-2-above
  • lasgun-mark-char-2-below
  • lasgun-mark-word-0-above
  • lasgun-mark-word-0-below
  • lasgun-mark-symbol-1-above
  • lasgun-mark-symbol-1-below
  • lasgun-mark-whitespace-end
  • lasgun-mark-whitespace-end-above
  • lasgun-mark-whitespace-end-below

About

Avy-backed, actionable placement of multiple marks


Languages

Language:Emacs Lisp 100.0%