** eamcs中快速复制一个词、一行文字、一个段落,而不用先选中它们
这个方法是有效的。可以参考它定义你想要的类似功能。
Copy Word
Put these code into your lisp file and a global key binding into your .emacs file. Then just put your point at the word and press “Ctrl-c w”, the word at your point will be copied into the kill-ring.
(defun copy-word (&optional arg)
"Copy words at point into kill-ring"
(interactive "P")
(let ((beg (progn (if (looking-back "[a-zA-Z0-9]" 1) (backward-word 1)) (point)))
(end (progn (forward-word arg) (point))))
(copy-region-as-kill beg end))
)Key binding
(global-set-key (kbd "C-c w") (quote copy-word))
Copy Line
Put these code into your lisp file and a global key binding into your .emacs file. Then just put your point at the line and press “Ctrl-c l”, the whole line at your point will be copied into the kill-ring.
(defun copy-line (&optional arg)
"Save current line into Kill-Ring without mark the line "
(interactive "P")
(let ((beg (line-beginning-position))
(end (line-end-position arg)))
(copy-region-as-kill beg end))
)Key binding
(global-set-key (kbd "C-c l") (quote copy-line))
Copy Paragraph
Put these code into your lisp file and a global key binding into your .emacs file. Then just put your point at the paragraph and press “Ctrl-c p”, the whole paragraph at your point will be copied into the kill-ring.
(defun copy-paragraph (&optional arg)
"Copy paragraphes at point"
(interactive "P")
(let ((beg (progn (backward-paragraph 1) (point)))
(end (progn (forward-paragraph arg) (point))))
(copy-region-as-kill beg end))
)Key binding
(global-set-key (kbd "C-c p") (quote copy-paragraph))
Copy String
Put these code into your lisp file and a global key binding into your .emacs file. Then just put your point at the word and press “Ctrl-c s”, the text string at your point will be copied into the kill-ring.
(defun copy-string (&optional arg)
"Copy a sequence of string into kill-ring"
(interactive)
(setq onPoint (point))
(let (
( beg (progn (re-search-backward "[\t ]" (line-beginning-position) 3 1)
(if (looking-at "[\t ]") (+ (point) 1) (point) ) )
)
( end (progn (goto-char onPoint) (re-search-forward "[\t ]" (line-end-position) 3 1)
(if (looking-back "[\t ]") (- (point) 1) (point) ) )
))
(copy-region-as-kill beg end)
)
)Key binding
(global-set-key (kbd "C-c s") (quote copy-string))
That’s all.