|
楼主 |
发表于 2004-5-27 12:21:09
|
显示全部楼层
hvj的讨论和推广emacs贴9:
这贴讲了一些网友们写的有意思和非常有用的elisp函数,可以方便很多工作,这也将是我以后完善我的配置文件的重点地方。不过目前配置文件里都只是我收集到的函数,和大家分享一下。
hvj-function.el
[php]
;;这个由王垠创作
;;如果你正在编辑一个东西(在位置A),突然想到别的某处(位置B)要修改或查看或别的,总之你要过去看看,你可以用C-.来在当前位置做个标记,然后去你想去的地方B,看了一会你觉的我可以回A去了,用C-,就回到刚才做标记的地方A,再用C-,又会回到B
(global-set-key [(control ?\.)] 'ska-point-to-register)
(global-set-key [(control ?\,)] 'ska-jump-to-register)
(defun ska-point-to-register()
"Store cursorposition _fast_ in a register.
Use ska-jump-to-register to jump back to the stored
position."
(interactive)
(setq zmacs-region-stays t)
(point-to-register 8))
(defun ska-jump-to-register()
"Switches between current cursorposition and position
that was stored with ska-point-to-register."
(interactive)
(setq zmacs-region-stays t)
(let ((tmp (point-marker)))
(jump-to-register 8)
(set-register 8 tmp)))
;; 这个忘了是从哪个地方弄来的,在保存~/.emacs文件自动编译为.elc文件
;;目前只是对~/.emacs有效,其余的*.el文件还没有去弄,以后有空我会改的
;;小知识:由于配置文件越来越大,你的*.el配置文件最好都编译为*.elc文件,这样在启动emacs速度会有很大的提升
(defun autocompile nil
"compile itself if ~/.emacs"
(interactive)
(if (string= (buffer-file-name) (concat default-directory ".emacs"))
(byte-compile-file (buffer-file-name))))
(add-hook 'after-save-hook 'autocompile)
;;这个是从emacs-lisp-introduction的那个文档拷过来
;;功能同word的计算文字数相似,不过这个功能有待完善,对中文不大好使
(defun hvj-recursive-count-words (region-end)
"Number of words between point and REGION-END."
(if (and (< (point) region-end)
(re-search-forward "\\w+\\W*" region-end t))
(1+ (hvj-recursive-count-words region-end))
0))
(defun hvj-count-words-region (beginning end)
"rint number of words in the region.
Words are defined as at least one word-constituent
character followed by at least one character that is
not a word-constituent. The buffer's syntax table
determines which characters these are."
(interactive "r")
(message "Counting words in region ... ")
(save-excursion
(goto-char beginning)
(let ((count (hvj-recursive-count-words end)))
(cond ((zerop count)
(message
"The region does NOT have any words."))
((= 1 count)
(message "The region has 1 word."))
(t
(message
"The region has %d words." count))))))
;;这也忘了是从哪弄来的了
;;功能是将当前行设为本页第一行,同终端下的clear命令有点相似
(defun hvj-line-to-top-of-window ()
"Move the line point is on to top of window."
(interactive)
(recenter 0))
[/php] |
|