Emacs Copy Current Line -
for reason, copying lines in emacs unintuitive , difficult. if i'm doing wrong here, please let me know. surprising emacs not have default somewhere.
i trying write function copies line. used have:
(global-set-key (kbd "c-x c") "\c-a\c- \c-n\m-w") this little annoying since copies new line after line. decided change to:
(global-set-key (kbd "c-x c") "\m-m\c- \c-e\m-w") now, saw: http://www.emacswiki.org/emacs/copyingwholelines , appears copy-line function prints message number of lines copied. trying insert message global-set-key above not working. basically, unable run raw sequence above in function. conveyed each keystroke function , did this:
(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, throws wrong number of arguments error.
my first question: how can put (message "1 line copied") global-set-key above?
my second question: using standard copy-line found in link above:
(defun copy-line (arg) "copy lines (as many prefix argument) in 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"))) from message, appears can have multiple lines copied. however, when selecting multiple lines , copying, 1 copied. why message structured in way? how can select multiple lines?
here's function, fixed:
(defun copy-line () (interactive) (save-excursion (back-to-indentation) (kill-ring-save (point) (line-end-position))) (message "1 line copied")) the problem back-to-indentation doesn't return point.
as other function, copy multiple lines when called prefix argument, e.g. c-u or m-5.
Comments
Post a Comment