Emacs copies the current line

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")))

, , . . ? ?

+4
2

:

(defun copy-line ()
  (interactive)
  (save-excursion
    (back-to-indentation)
    (kill-ring-save
     (point)
     (line-end-position)))
     (message "1 line copied"))

, back-to-indentation .

, , . C-u M-5.

+3

:

(defun copy-line ()
  (interactive)
  (kill-ring-save (point-at-bol) (point-at-eol))
  (message "1 line copied"))

, , , , ( ). , key-bind C-c C-k , , , 3 : C-u 3 C-c C-k.

+1

Source: https://habr.com/ru/post/1532299/


All Articles