Last active
December 22, 2015 11:08
-
-
Save tam17aki/6463193 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun copy-whole-line2 (&optional arg) | |
"Copy current line." | |
(interactive "p") | |
(or arg (setq arg 1)) | |
(if (and (> arg 0) (eobp) (save-excursion (forward-visible-line 0) (eobp))) | |
(signal 'end-of-buffer nil)) | |
(if (and (< arg 0) (bobp) (save-excursion (end-of-visible-line) (bobp))) | |
(signal 'beginning-of-buffer nil)) | |
(unless (eq last-command 'copy-region-as-kill) | |
(kill-new "") | |
(setq last-command 'copy-region-as-kill)) | |
(cond ((zerop arg) | |
(save-excursion | |
(copy-region-as-kill (progn (back-to-indentation) (point)) | |
(progn (end-of-visible-line) (point))))) | |
((< arg 0) | |
(save-excursion | |
(copy-region-as-kill (progn (end-of-visible-line) (point)) | |
(progn (forward-visible-line arg) | |
(back-to-indentation) (point))))) | |
((or (> arg 1) (eq current-prefix-arg 1)) | |
(save-excursion | |
(copy-region-as-kill (progn (back-to-indentation) (point)) | |
(progn (forward-visible-line (1+ arg)) | |
(unless (bobp) (backward-char)) (point))))) | |
(t | |
(save-excursion | |
(copy-region-as-kill (progn (back-to-indentation) (point)) | |
(progn (forward-visible-line arg) | |
(unless (bobp) (backward-char)) (point)))))) | |
(message "Copied from \"%s\"." (substring (car kill-ring-yank-pointer) 0 nil))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment