1 ;;; -*- lexical-binding: t -*-
3 (defun my/copy-line (arg)
4 "Copy the current line into the kill ring. With ARG copies that many lines."
6 (kill-ring-save (line-beginning-position 1)
7 (line-beginning-position (+ 1 arg)))
8 (message "Copied %d lines" arg))
10 (defun my/duplicate-line (arg)
11 "Duplicate current line, leaving point in lower line. With ARG duplicates the line that many lines."
13 (let* ((start (line-beginning-position 1))
14 (end (line-beginning-position 2))
15 (at-eof (= end (line-end-position) (point-max))))
16 (kill-ring-save start end)
19 (save-mark-and-excursion
21 (dotimes (ignored arg)
24 (back-to-indentation)))
26 (defun my/open-line-above (arg)
27 "Open a new line above point with indentation. With ARG insert that many lines."
31 (forward-line (- arg))
32 (indent-for-tab-command))
34 (defun my/open-line-below (arg)
35 "Open a new line below point with indentation. With ARG insert that many lines."
39 (indent-for-tab-command))
41 (defun my/substitute-line (arg)
42 "Kill the current line and leave point at correct indentation level. With ARG kill that many lines first."
45 (if (not (and (null arg) (equal (line-beginning-position) (line-end-position))))
47 (if (not (string-equal major-mode "fundamental-mode"))
48 (indent-for-tab-command)))
51 "If the text to be yanked has a newline then move to beginning of line before yanking. Otherwise same as normal `yank'."
53 (advice-add 'insert-for-yank :around #'my/yank/advice)
56 (advice-remove 'insert-for-yank #'my/yank/advice)))
58 (defun my/yank/advice (original-function string)
59 (if (string-match-p "\n" string)
61 (funcall original-function string))