commit 7a1f6aa89785be5f8c5b958270812535f4e5ba81
parent 2dd76b8f23c74d62d992df5bbfd30ffd18576beb
Author: andsy10 <andsy1016@gmail.com>
Date: Mon, 14 Sep 2026 08:02:49 +0800
Inline functions from crux package
Diffstat:
4 files changed, 41 insertions(+), 11 deletions(-)
diff --git a/lisp/init-edit.el b/lisp/init-edit.el
@@ -45,9 +45,6 @@
hydra-multiple-cursors/mc/unmark-previous-like-this
hydra-multiple-cursors/nil)))
-;; useful commands
-(use-package crux)
-
;; hungry-delete
(use-package hungry-delete)
diff --git a/lisp/init-kbd-func.el b/lisp/init-kbd-func.el
@@ -19,6 +19,40 @@ With a prefix ARG create a new *scratch* buffer."
(funcall initial-major-mode))
(scratch-buffer)))
+;; from Bozhidar Batsov's crux
+(defun my-kill-line-backwards ()
+ "Kill line backwards and adjust the indentation."
+ (interactive)
+ (kill-line 0)
+ (indent-according-to-mode))
+
+;; from Bozhidar Batsov's crux
+(defun my-get-positions-of-line-or-region ()
+ "Return positions (beg . end) of the current line or region."
+ (let (beg end)
+ (if (and mark-active (> (point) (mark)))
+ (exchange-point-and-mark))
+ (setq beg (line-beginning-position))
+ (if mark-active
+ (exchange-point-and-mark))
+ (setq end (line-end-position))
+ (cons beg end)))
+
+(defun my-duplicate-current-line-or-region (arg)
+ "Duplicates the current line or region ARG times.
+If there's no region, the current line will be duplicated. However, if
+there's a region, all lines that region covers will be duplicated."
+ (interactive "p")
+ (pcase-let* ((origin (point))
+ (`(,beg . ,end) (my-get-positions-of-line-or-region))
+ (region (buffer-substring-no-properties beg end)))
+ (dotimes (_i arg)
+ (goto-char end)
+ (newline)
+ (insert region)
+ (setq end (point)))
+ (goto-char (+ origin (* (length region) arg) arg))))
+
(defun enable-truncate-lines ()
(toggle-truncate-lines 1))
diff --git a/lisp/init-kbd.el b/lisp/init-kbd.el
@@ -282,7 +282,7 @@
"C-c t l" #'org-toggle-link-display
"M-{" #'backward-paragraph
"M-}" #'forward-paragraph
- "C-," #'crux-duplicate-current-line-or-region
+ "C-," #'my-duplicate-current-line-or-region
"C-c o l" #'denote-link
"C-c o L" #'denote-org-link-to-heading
"C-c o b" #'my-denote-find-backlink-with-location
@@ -365,7 +365,6 @@
"M-]" #'next-buffer
"C-x 4 b" #'consult-buffer-other-window
"C-x C-b" #'ibuffer-other-window
- "C-x K" #'crux-kill-other-buffers
"C-x b" #'consult-buffer
"C-x C-1" #'delete-other-windows
"C-x C-2" #'split-window-below
@@ -376,8 +375,8 @@
"M-c" #'capitalize-dwim
"M-u" #'upcase-dwim
"M-l" #'downcase-dwim
- "C-," #'crux-duplicate-current-line-or-region
- "C-<backspace>" #'crux-kill-line-backwards
+ "C-," #'my-duplicate-current-line-or-region
+ "C-<backspace>" #'my-kill-line-backwards
"M-y" #'consult-yank-from-kill-ring
"C-c <backspace>" #'hungry-delete-backward
"C-c C-<backspace>" #'hungry-delete-forward
diff --git a/lisp/init-terminal.el b/lisp/init-terminal.el
@@ -209,7 +209,7 @@ With a prefix ARG create a new *scratch* buffer."
(funcall initial-major-mode))
(scratch-buffer)))
-(defun crux-get-positions-of-line-or-region ()
+(defun my-get-positions-of-line-or-region ()
"Return positions (beg . end) of the current line or region."
(let (beg end)
(if (and mark-active (> (point) (mark)))
@@ -220,13 +220,13 @@ With a prefix ARG create a new *scratch* buffer."
(setq end (line-end-position))
(cons beg end)))
-(defun crux-duplicate-current-line-or-region (arg)
+(defun my-duplicate-current-line-or-region (arg)
"Duplicates the current line or region ARG times.
If there's no region, the current line will be duplicated. However, if
there's a region, all lines that region covers will be duplicated."
(interactive "p")
(pcase-let* ((origin (point))
- (`(,beg . ,end) (crux-get-positions-of-line-or-region))
+ (`(,beg . ,end) (my-get-positions-of-line-or-region))
(region (buffer-substring-no-properties beg end)))
(dotimes (_i arg)
(goto-char end)
@@ -284,7 +284,7 @@ there's a region, all lines that region covers will be duplicated."
(keymap-global-set "M-c" #'capitalize-dwim)
(keymap-global-set "M-u" #'upcase-dwim)
(keymap-global-set "M-l" #'downcase-dwim)
-(keymap-global-set "C-," #'crux-duplicate-current-line-or-region)
+(keymap-global-set "C-," #'my-duplicate-current-line-or-region)
(keymap-global-set "M-y" #'yank-from-kill-ring)
(keymap-global-set "C-M-@" #'er/mark-symbol)
(keymap-global-set "M-@" #'er/mark-word)