我无法编写emacs功能,有人可以帮助我吗?。
答案 0 :(得分:4)
是的,有。 This code is borrowed from this blog entry:
(defadvice kill-ring-save (before slick-copy activate compile)
"When called interactively with no active region, copy a single line instead."
(interactive
(if mark-active (list (region-beginning) (region-end))
(message "Copied line")
(list (line-beginning-position)
(line-beginning-position 2)))))
(defadvice kill-region (before slick-cut activate compile)
"When called interactively with no active region, kill a single line instead."
(interactive
(if mark-active (list (region-beginning) (region-end))
(list (line-beginning-position)
(line-beginning-position 2)))))
答案 1 :(得分:2)
有几种方法可以复制一行:
通常的方式: C-a C-SPC C-n M-w
使用鼠标:三次单击该行,键入 M-w
将变量kill-whole-line
设置(或自定义)为t
,然后通过删除和撤消进行复制: Ca Ck C -_
我没有发现这是一个足够普通的操作,我想给它分配一个组合键,但如果你这样做,那么编写一个函数很容易:
(defun kill-ring-save-line ()
"Save the line containing point to the kill ring."
(interactive)
(kill-ring-save (line-beginning-position)
(line-beginning-position 2)))
答案 2 :(得分:0)
C-a C-k C-k C-y
或
C-a C-u 1 C-k C-y
通过发现
C-h k C-k
和
C-h f kill-TAB
(defun copy-line ()
(interactive)
(beginning-of-line)
(kill-line 1)
(yank))
答案 3 :(得分:0)
;; http://www.emacswiki.org/emacs/WholeLineOrRegion#toc2
;; cut, copy, yank
(defadvice kill-ring-save (around slick-copy activate)
"When called interactively with no active region, copy a single line instead."
(if (or (use-region-p) (not (called-interactively-p)))
ad-do-it
(kill-new (buffer-substring (line-beginning-position)
(line-beginning-position 2))
nil '(yank-line))
(message "Copied line")))
(defadvice kill-region (around slick-copy activate)
"When called interactively with no active region, kill a single line instead."
(if (or (use-region-p) (not (called-interactively-p)))
ad-do-it
(kill-new (filter-buffer-substring (line-beginning-position)
(line-beginning-position 2) t)
nil '(yank-line))))
(defun yank-line (string)
"Insert STRING above the current line."
(beginning-of-line)
(unless (= (elt string (1- (length string))) ?\n)
(save-excursion (insert "\n")))
(insert string))
(global-set-key (kbd "<f2>") 'kill-region) ; cut.
(global-set-key (kbd "<f3>") 'kill-ring-save) ; copy.
(global-set-key (kbd "<f4>") 'yank) ; paste.