summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.config/emacs/editing.el45
-rw-r--r--.config/emacs/modules/mm-keybindings.el9
2 files changed, 52 insertions, 2 deletions
diff --git a/.config/emacs/editing.el b/.config/emacs/editing.el
index 284f6bf..644c7b7 100644
--- a/.config/emacs/editing.el
+++ b/.config/emacs/editing.el
@@ -174,4 +174,49 @@ contents after point are placed on a new line before point."
(insert string)
(indent-according-to-mode))))
+(defun e/mc/sort-regions (&optional reverse)
+ "Sort marked regions.
+This command is an exact replica of `mc/sort-regions' except that
+calling this command with a prefix argument REVERSE sorts the marked
+regions in reverse order."
+ (interactive "*P")
+ (unless (use-region-p)
+ (mc/execute-command-for-all-cursors))
+ (setq mc--strings-to-replace (sort (mc--ordered-region-strings)
+ (if reverse #'string> #'string<)))
+ (mc--replace-region-strings))
+
+(defun e/sort-dwim (&optional reverse)
+ "Sort regions do-what-i-mean.
+When multiple cursors are not being used this command functions just
+like `sort-lines' with the start- and end bounds set to the current
+region beginning and -end.
+
+When using multiple cursors this command sorts the regions marked by
+each cursor (effectively calling `e/mc/sort-regions'.
+
+When called with a prefix argument REVERSE, sorting occurs in reverse
+order."
+ (interactive "*P")
+ (if (> 1 (mc/num-cursors))
+ (e/mc/sort-regions reverse)
+ (sort-lines reverse (region-beginning) (region-end))))
+
+(defun e/yank (&optional arg)
+ "Yank text from the kill-ring.
+Yank the most recent kill from the kill ring via `yank'. If called with
+prefix argument ARG then interactively yank from the kill ring via
+`yank-from-kill-ring'.
+
+If `consult' is available than this command instead calls
+`consult-yank-from-kill-ring' when called with non-nil ARG."
+ (declare (interactive-only t))
+ (interactive "*P")
+ (cond ((null arg)
+ (yank))
+ ((featurep 'consult)
+ (call-interactively #'consult-yank-from-kill-ring))
+ (t
+ (call-interactively #'yank-from-kill-ring))))
+
(provide 'editing)
diff --git a/.config/emacs/modules/mm-keybindings.el b/.config/emacs/modules/mm-keybindings.el
index c1dee93..a025a82 100644
--- a/.config/emacs/modules/mm-keybindings.el
+++ b/.config/emacs/modules/mm-keybindings.el
@@ -89,7 +89,8 @@ the first command is remapped to the second command."
mark-word e/mark-entire-word
open-line e/open-line
transpose-chars e/transpose-previous-chars
- transpose-lines e/transpose-current-and-next-lines)
+ transpose-lines e/transpose-current-and-next-lines
+ yank e/yank)
(with-eval-after-load 'cc-vars
(setopt c-backspace-function #'backward-delete-char))
@@ -117,12 +118,16 @@ the first command is remapped to the second command."
"C-c d" #'duplicate-dwim
"C-c t a" #'e/align-regexp
"C-c t f" #'fill-paragraph
- "C-c t s" #'sort-lines)
+ "C-c t s" #'e/sort-dwim)
(mm-keymap-set-repeating global-map
"j" #'e/join-current-and-next-line
"J" #'join-line)
+(mm-keymap-set-repeating global-map
+ "n" #'next-error
+ "p" #'previous-error)
+
(with-eval-after-load 'increment
(mm-keymap-set-repeating global-map
"d" #'decrement-number-at-point