From b37ed033f65b56d9ec249b25bbfdf27aaef6bc9a Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 19 Oct 2024 23:20:04 +0200 Subject: emacs: Implement e/split-line --- .config/emacs/editing.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to '.config/emacs/editing.el') diff --git a/.config/emacs/editing.el b/.config/emacs/editing.el index f635705..951a774 100644 --- a/.config/emacs/editing.el +++ b/.config/emacs/editing.el @@ -156,4 +156,21 @@ point." (previous-line 2) (end-of-line))) +(defun e/split-line (&optional above) + "Split the line at point. +Place the contents after point on a new line, indenting the new line +according to the current major mode. With prefix argument ABOVE the +contents after point are placed on a new line before point." + (interactive "P") + (save-excursion + (let* ((start (point)) + (end (pos-eol)) + (string (buffer-substring start end))) + (delete-region start end) + (when above + (goto-char (1- (pos-bol)))) + (newline) + (insert string) + (indent-according-to-mode)))) + (provide 'editing) -- cgit v1.2.3