]> code.delx.au - dotemacs/blob - lisp/my-editing-defuns.el
Use default yank behaviour
[dotemacs] / lisp / my-editing-defuns.el
1 ;;; -*- lexical-binding: t -*-
2
3 (defun my/copy-line (arg)
4 "Copy the current line into the kill ring. With ARG copies that many lines."
5 (interactive "p")
6 (kill-ring-save (line-beginning-position 1)
7 (line-beginning-position (+ 1 arg)))
8 (message "Copied %d lines" arg))
9
10 (defun my/duplicate-line (arg)
11 "Duplicate current line, leaving point in lower line. With ARG duplicates the line that many lines."
12 (interactive "*p")
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)
17 (when at-eof
18 (kill-append "\n" t))
19 (save-mark-and-excursion
20 (forward-line)
21 (dotimes (ignored arg)
22 (yank)))
23 (forward-line)
24 (back-to-indentation)))
25
26 (defun my/open-line-above (arg)
27 "Open a new line above point with indentation. With ARG insert that many lines."
28 (interactive "*p")
29 (beginning-of-line)
30 (newline arg)
31 (forward-line (- arg))
32 (indent-for-tab-command))
33
34 (defun my/open-line-below (arg)
35 "Open a new line below point with indentation. With ARG insert that many lines."
36 (interactive "*p")
37 (end-of-line)
38 (newline arg)
39 (indent-for-tab-command))
40
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."
43 (interactive "*P")
44 (beginning-of-line)
45 (if (not (and (null arg) (equal (line-beginning-position) (line-end-position))))
46 (kill-line arg))
47 (if (not (string-equal major-mode "fundamental-mode"))
48 (indent-for-tab-command)))