It’s fun to edit things quickly.
;;; wal-edit.el --- Editing. -*- lexical-binding: t -*-
;;; Commentary:
;;
;; Provide editing packages.
;;; Code:
(eval-when-compile
(require 'wal-key-bindings nil t))
(declare-function wal-list-from "wal-useful.el")
(defvar corfu-mode)
(defvar wal-default-path)
Don’t you want to edit your buffer in multiple places at once? This
sets up the package to work nicely with other packages (for example,
we don’t want to complete with corfu
while multiple are active).
This creates a repeat map to manage the cursors.
(defvar wal-mc-conflicting-modes '(puni-mode corfu-mode electric-indent-mode)
"Modes that are in conflict with `multiple-cursors-mode'.")
(defvar-local wal-mc-disabled nil
"Modes that were disabled before entering `multiple-cursors-mode'.")
(defun wal-before-mc ()
"Disable conflicting modes before entering mode."
(seq-each
(lambda (it)
(when (and (boundp it) (symbol-value it))
(setq wal-mc-disabled (append wal-mc-disabled `(,it)))
(eval `(,it -1))))
wal-mc-conflicting-modes))
(defun wal-after-mc ()
"Re-enable modes that were disabled before exiting."
(seq-each (lambda (it) (eval `(,it 1))) wal-mc-disabled)
(setq wal-mc-disabled nil))
(use-package multiple-cursors
:init
(defvar-keymap multiple-cursors-repeat-map
:doc "Keymap to repeat `mutliple-cursors' commands."
:repeat t
"." 'mc/mark-next-like-this
"<" 'mc/mark-previous-like-this
"," 'mc/unmark-next-like-this
">" 'mc/unmark-previous-like-this
"?" 'mc/skip-to-previous-like-this
"/" 'mc/skip-to-next-like-this)
:hook
((multiple-cursors-mode-enabled . wal-before-mc)
(multiple-cursors-mode-disabled . wal-after-mc))
:wal-bind
("<mouse-3>" . mc/add-cursor-on-click)
:bind
("C-." . mc/mark-next-like-this)
:general
(editors "." 'mc/mark-all-like-this 'mc/edit-ends-of-lines))
One thing that can be a bit tricky is selecting regions, not anymore.
(use-package expand-region
:config
(defvar-keymap expand-region-repeat-map
:doc "Keymap to repeat various `expand-region' commands."
:repeat t
">" 'er/expand-region
"<" 'er/contract-region)
:bind
(("C->" . er/expand-region)))
Less intrusive pairing mode than smartparens
.
(defun wal-in-case-of-mc-mode-do-not-default (&rest _args)
"Advise to inhibit if `multiple-cursors-mode' is t."
(bound-and-true-p multiple-cursors-mode))
(use-package elec-pair
:hook ((prog-mode harpoon-prog-like) . electric-pair-local-mode)
:init
(advice-add
'electric-pair-default-inhibit :before-until
#'wal-in-case-of-mc-mode-do-not-default))
Surround things with pairs and use surrounding pairs to act upon enclosed content.
(use-package surround
:general
(ambassador "s" '(:keymap surround-keymap :wk "surround"))
(editors "s" 'surround-insert 'surround-kill))
(provide 'wal-edit)
;;; wal-edit.el ends here