I would like to write a function which
- on the first execution behaves like the regular
kill-ring-saveif some region is selected
- on the first execution copies the current word if no region is selected,
- on the second execution copies the current line
- on the third execution copies the current paragraph
- on the fourth execution and so on copies the whole current buffer
Eventually I would like to remap
kill-ring-save to this new function.
So far I have written this
(defun modified-kill-ring-save () (interactive) (if (region-active-p) (kill-ring-save (region-beginning) (region-end)) (if (not (equal last-command 'modified-kill-ring-save)) (progn (select-current-word) (kill-ring-save (region-beginning) (region-end)) ) (progn (select-current-line) (kill-ring-save (region-beginning) (region-end)) ) ) ) )
which does 1, 2 and 3. But I am not able to go further.
In the above code I have used the following functions from http://ergoemacs.org/emacs/elisp_examples.html
(defun select-current-line () "Select the current line" (interactive) (beginning-of-line) ; move to end of line (set-mark (line-end-position))) (defun select-current-word () "Select the word under cursor. “word” here is considered any alphanumeric sequence with “_” or “-”." (interactive) (let (pt) (skip-chars-backward "-_A-Za-z0-9") (setq pt (point)) (skip-chars-forward "-_A-Za-z0-9") (set-mark pt) ))