Posted on 06-10-2008
Filed Under (技术) by waterlin

今天看到《让拷贝和粘贴变得充满乐趣》这篇文章,觉得蛮有意思的。通过这样的编码,实现了对一行、一段、一个单词的自动化拷贝,在很多时候,的确是能减轻大家编码的工作量。

要做的其实非常简单,只要把以下代码放到.emacs里即可实现拷贝的自动化。

(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))
)(defun copy-word (&optional arg)
“Copy words at point”
(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))
)

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

同样,根据这样的原理,我们还可以写出更多的、具有特殊功能的自动拷贝代码。

© 2008, 浏忙大爆炸. All rights reserved.
除非注明,浏忙大爆炸文章均为原创,转载请以链接形式标明本文地址。

(0) Comments    (742) Views    Read More   
Post a Comment
Name:
Email:
Website:
Comments: