Commit 5f74b99e authored by marc0s's avatar marc0s

New copy-line function

parent afbb3a7f
......@@ -507,5 +507,25 @@ The destination file is derived from the CURRENT buffer file name,
(flycheck-next-error))
(global-set-key (kbd "<f9>") 'marc0s/flycheck-from-buffer-start)
(defun copy-line (arg)
"Copy lines (as many as prefix argument) in the kill ring.
Ease of use features:
- Move to start of next line.
- Appends the copy on sequential calls.
- Use newline as last char even on the last line of the buffer.
- If region is active, copy its lines."
(interactive "p")
(let ((beg (line-beginning-position))
(end (line-end-position arg)))
(when mark-active
(if (> (point) (mark))
(setq beg (save-excursion (goto-char (mark)) (line-beginning-position)))
(setq end (save-excursion (goto-char (mark)) (line-end-position)))))
(if (eq last-command 'copy-line)
(kill-append (buffer-substring beg end) (< end beg))
(kill-ring-save beg end)))
(kill-append "\n" nil)
(beginning-of-line (or (and arg (1+ arg)) 2))
(if (and arg (not (= 1 arg))) (message "%d lines copied" arg)))
(global-set-key (kbd "C-c C-k") 'copy-line)
;;; init.el ends here
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment