]> code.delx.au - dotemacs/blobdiff - lisp/my-editing-defuns.el
allow copying lines in read-only files
[dotemacs] / lisp / my-editing-defuns.el
index 1799fdedba8e32d57eae844c1fc371fe53b17e74..bf72f9440fea4359f0696272eabddb73d70f91fc 100644 (file)
@@ -14,7 +14,7 @@
 
 (defun my/copy-line (arg)
   "Copy the current line into the kill ring. With ARG copies that many lines."
-  (interactive "*p")
+  (interactive "p")
   (kill-ring-save (line-beginning-position 1)
                   (line-beginning-position (+ 1 arg)))
   (message "Copied %d lines" arg))
 (defun my/duplicate-line (arg)
   "Duplicate current line, leaving point in lower line. With ARG duplicates the line that many lines."
   (interactive "*p")
-  (kill-ring-save (line-beginning-position 1)
-                  (line-beginning-position 2))
-  (forward-line)
-  (dotimes (ignored arg)
-    (yank))
-  (forward-line (- arg))
-  (back-to-indentation))
+  (let* ((start (line-beginning-position 1))
+         (end (line-beginning-position 2))
+         (at-eof (= end (line-end-position) (point-max))))
+    (kill-ring-save start end)
+    (when at-eof
+      (kill-append "\n" t))
+    (save-excursion
+      (forward-line)
+      (dotimes (ignored arg)
+        (yank)))
+    (forward-line)
+    (back-to-indentation)))
 
 (defun my/open-line-above (arg)
   "Open a new line above point with indentation. With ARG insert that many lines."