-
Notifications
You must be signed in to change notification settings - Fork 1
/
my-editing.el
106 lines (92 loc) · 3.01 KB
/
my-editing.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
;;; my-editing --- editing helpers
;;
;; Copyright (C) 2014 Alex Bennée
;;
;; Author: Alex Bennée <[email protected]>
;;
;; This file is not part of GNU Emacs.
;;
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;;; Commentary:
;;
;;
;;
;;; Code:
;; Require prerequisites
(require 'use-package)
(require 'my-compat)
(require 'my-hydra)
;; Variables
;; Code
;; Nice for jumping about windows.
(use-package avy
:ensure t
:bind ("C-x j" . avy-goto-word-or-subword-1))
;; Multiple cursors
(use-package multiple-cursors
:ensure t
:commands mc/mark-next-like-this multiple-cursors-mode
:bind (:map mc/keymap
("C-n" . mc/mark-next-like-this)))
;; Expand region
(defun my-mark-or-expand-dwim (&optional arg)
"Set the mark (with prefix `ARG') or if mark already set call expand-region."
(interactive "P")
(if arg
(let ((current-prefix-arg nil))
(setq transient-mark-mode t)
(call-interactively #'set-mark-command))
(if (or (use-region-p)
(and mark-active
(eq (point) (mark))))
(call-interactively #'er/expand-region)
(call-interactively #'set-mark-command))))
(use-package expand-region
:ensure t
:commands (er/expand-region)
:hook ((gnus-article-mode-hook . er/add-text-mode-expansions))
:bind (("C-SPC" . my-mark-or-expand-dwim)
("C-@" . my-mark-or-expand-dwim)
("C-=" . er/expand-region)))
(defun my-next-mc-or-line-dwim (&optional arg)
"Do `next-line' or `mc/mark-next-like-this' intelligently (with prefix `ARG').
If the region is less than a line long assume I want to mark the next
mc entry. Otherwise treat it as a new line."
(interactive "P")
(if (= (line-number-at-pos (region-beginning))
(line-number-at-pos (region-end)))
(unless multiple-cursors-mode
(call-interactively #'mc/mark-next-like-this))
(call-interactively #'next-line)))
;; This replaces region-bindings-mode
(when have-melpa
(use-package selected
:ensure t
:bind (:map selected-keymap
("C-n" . my-next-mc-or-line-dwim))
:config (selected-global-mode)))
;; Finally a hydra for the complex editing commands
;; currently set to C-# but I might want to lead via C-SPC later.
(global-set-key
(kbd "C-#")
(defhydra my-editing-hydra (:exit nil :hint nil :color red :timeout 5)
"
line: %(line-number-at-pos) region: %(- (region-end) (region-beginning)) chars
----------------------------------------------------------------
_n_ext like this: %(buffer-substring-no-properties (region-beginning) (region-end))
_e_xpand or _c_ontract current region
"
;; Multiple cursors
("n" mc/mark-next-like-this)
;; Expand Region
("e" er/expand-region)
("c" er/contract-region)))
(use-package ws-butler
:ensure t
:hook (prog-mode . ws-butler-mode))
(provide 'my-editing)
;;; my-editing.el ends here