For some reason, copying strings in Emacs is very unintuitive and complicated. If I am doing something wrong, please let me know. Surprisingly, Emacs does not have this by default.
I am trying to write a function that copies a string. I always used to have:
(global-set-key (kbd "C-x c") "\C-a\C- \C-n\M-w")
This is a little annoying as it copies any new line after line. I decided to change it to:
(global-set-key (kbd "C-x c") "\M-m\C- \C-e\M-w")
Now I saw: http://www.emacswiki.org/emacs/CopyingWholeLines , and it seems that their copy-print function displays a message with the number of lines copied. I am trying to insert this message into my global keyset above, but it does not work. Basically, I can not start the raw sequence, as indicated above in the function. So I passed each keystroke to a function and did the following:
(defun copy-line ()
(interactive)
(kill-ring-save
(back-to-indentation)
(move-end-of-line 1))
(message "1 line copied"))
;; optional key binding
(global-set-key "\C-c\C-k" 'copy-line)
This, however, causes an error wrong number of arguments.
My first question is: how can I put (message "1 line copied")in my global key set above?
My second question: using the standard copy provided in the link above:
(defun copy-line (arg)
"Copy lines (as many as prefix argument) in the kill ring"
(interactive "p")
(kill-ring-save (line-beginning-position)
(line-beginning-position (+ 1 arg)))
(message "%d line%s copied" arg (if (= 1 arg) "" "s")))
, , . . ? ?