分享

一个比较好中文说明的emacs配置文件

 yusihai719 2017-03-21

(setq time-stamp-format '%:u %02m/%02d/%04y %02H02M02S')
;;将修改时间戳添加到保存文件的动作里。
(add-hook 'write-file-hooks 'time-stamp)

;;时间显示设置
;;启用时间显示设置,在minibuffer上面的那个杠上(忘了叫什么来着)
(display-time-mode 1)
;;时间使用24小时制
(setq display-time-24hr-format t)
;;时间显示包括日期和具体时间
(setq display-time-day-and-date t)
;;时间栏旁边启用邮件设置
(setq display-time-use-mail-icon t)
;;时间的变化频率,单位多少来着?
(setq display-time-interval 10)

hvj的讨论和推广emacs贴3:
这里继续帖我得hvj-basic-config.el,讲另外一些比较零碎的设置
引用:;;启用minibuffer,好像是默认设置吧
(minibuffer-electric-default-mode 1)
;;启用部分补全功能,如输入M-x q r r相当于M-x query-replace-regexp
(partial-completion-mode 1)
;;在minibuffer里启用自动补全函数和变量
(icomplete-mode 1)
;;所有的问题用y/n方式,不用yes/no方式。有点懒,只想输入一个字母
(fset 'yes-or-no-p 'y-or-n-p)
;;允许minibuffer自由变化其大小(指宽度)
(setq resize-mini-windows t)
;;当寻找一个同名的文件,自动关联上那个文件?
(setq uniquify-buffer-name-style 'forward)
;;在emacs读man文档时,使用当前buffer
(setq Man-notify-method 'pushy)
;;鼠标自动避开指针,如当你输入的时候,指针到了鼠标的位置,鼠标有点挡住视线了
(mouse-avoidance-mode 'animate)
;;允许自动打开图片,如wiki里面
(auto-image-file-mode)
;;可以操作压缩文档
(auto-compression-mode 1)
;;在minibuffer上面可以显示列号
(column-number-mode t)
;;显示默认的文档的宽度,看起来比较舒服?
(setq default-fill-column 60)
;;指针不要闪,我得眼睛花了
(blink-cursor-mode -1)
(transient-mark-mode 1)
;;当指针到一个括号时,自动显示所匹配的另一个括号
(show-paren-mode 1)
;;是用滚轴鼠标
(mouse-wheel-mode t)
;;去掉烦人的警告铃声
(setq visible-bell nil)
;;滚动页面时比较舒服,不要整页的滚动
(setq scroll-step 1
scroll-margin 3
scroll-conservatively 10000)
;;设定句子结尾,主要是针对中文设置
(setq sentence-end '\\([?££?£?]\\|??\\|[.?!][]\'')}]*\\($\\|[ \t]\\)\\)[ \t\n]*')
(setq sentence-end-double-space nil)
;;去掉Emacs和gnus启动时的引导界面
(setq inhibit-startup-message t)
(setq gnus-inhibit-startup-message t)
;;当指针移到另一行,不要新增这一行?d
(setq next-line-add-newlines nil)
;;在文档最后自动插入空白一行,好像某些系统配置文件是需要这样的
(setq require-final-newline t)
(setq track-eol t)
;;使用C-k删掉指针到改行末的所有东西
(setq-default kill-whole-line t)
;;设定删除保存记录为200,可以方便以后无限恢复
(setq kill-ring-max 200)
;;增大使用查找函数和变量的寻找范围
(setq apropos-do-all t)
;;是用aspell程序作为Emacs的拼写检查成学
(setq-default ispell-program-name 'aspell')
;;使用narrow功能时的一个设置
(put 'narrow-to-region 'disabled nil)
;;启动Emacs自动设置为两个窗口(上下各一个)
(split-window-vertically)
;;改变emacs标题栏的标题
(setq frame-title-format '%b@vj.org')
;;允许emacs和外部其他程序的粘贴
(setq x-select-enable-clipboard t)


hvj的讨论和推广emacs贴4:

这贴主要讲一下中文的设置,是我的配置文件hvj-language.el
我得Emacs中文配置由三部分组成:local设置,.Xdefault设置字体,hvj-language设置emacs环境。

我的locale设置很简单,如下:
引用:export LANG=en_US
export LC_CTYPE=zh_CN


我的.Xdefaults中有关emacs的配置是:
引用:Emacs.Font:fontset-global
Emacs.Fontset-0:-*-*-medium-r-*-*-14-*-*-*-*-*-fontset-global,\
ascii:-*-fixed-medium-r-*-*-14-*-*-*-*-*-iso8859-*,\
chinese-gb2312:-*-tangti-medium-r-normal-*-14-*-*-*-*-*-gb2312.1980-0,\
chinese-big5-1:-*-tangti-medium-r-*-*-14-*-*-*-*-*-big5-0,\
chinese-big5-2:-*-tangti-medium-r-*-*-14-*-*-*-*-*-big5-0, \
utf-8:-misc-fixed-medium-r-*-*-14-*-*-*-*-*-iso10646-1, \
mule-utf-8:-misc-fixed-*-r-*-*-14-*-*-*-*-*-iso10646-1, \
mule-unicode-0100-24ff:-misc-fixed-*-r-*-*-14-*-*-*-*-*-iso10646-1, \
korean-ksc5601:-*-*-medium-r-normal-*-20-*-*-*-*-*-ksc5601*-*, \
sjis:-*-*-medium-r-normal-*-20-*-*-*-*-*-jisx0208*-*



下面是我得hvj-language.el
引用:;;emacs环境设置
;;整体环境设置
(set-language-environment 'Chinese-GB)
;;应该和输入有关系
(set-keyboard-coding-system 'chinese-iso-8bit-with-esc)
;;终端下emacs的中文设置?
(set-terminal-coding-system 'chinese-iso-8bit-with-esc)
;;文件保存时的编码设置
(set-buffer-file-coding-system 'chinese-iso-8bit-with-esc)
;;下面两天是emacs和其他程序互相复制/粘贴的设置
;;在帖3(hvj-basicconfig.el)的最后一行中也有相关的一个设定
(set-selection-coding-system 'chinese-iso-8bit-with-esc)
(set-clipboard-coding-system 'chinese-iso-8bit-with-esc)
;;什么设置?忘了?有些人没用下面这些
(modify-coding-system-alist 'process '*' 'chinese-iso-8bit-with-esc)
(setq default-process-coding-system '(chinese-iso-8bit-with-esc . chinese-iso-8bit-with-esc))
(setq-default pathname-coding-system 'chinese-iso-8bit-with-esc)

;;字体解码优先顺序
;;从王垠那拷过来的,不用怎么再改吧。
(setq font-encoding-alist
(append '(('MuleTibetan-0' (tibetan . 0))
('GB2312' (chinese-gb2312 . 0))
('JISX0208' (japanese-jisx0208 . 0))
('JISX0212' (japanese-jisx0212 . 0))
('VISCII' (vietnamese-viscii-lower . 0))
('KSC5601' (korean-ksc5601 . 0))
('MuleArabic-0' (arabic-digit . 0))
('MuleArabic-1' (arabic-1-column . 0))
('MuleArabic-2' (arabic-2-column . 0))) font-encoding-alist))

一些其他的说明:
1,有些人使用gbk的locale,那么就需要安装mule-gbk扩展elisp包,我以前装过,配置不是很难。论坛里可以搜到,这次比较急,不再去搜了,下次在加到这贴里。
2,emacs目前对Unicode支持不是很好,虽然现在有mule-ucs包,我一直没用的很爽。对于Unicode解码的文件、email我都改用了别的工具。官方说emacs的下一版对unicode解码更好了,大家有兴趣可以去试用emacs-cvs版。
3,emacs在windows的中文设置,以及Xemacs在linux和Windows的设置我不清楚,没用过,不能保证这些方法能适用你们。

hvj的讨论和推广emacs贴5:

这次讲讲日历的设置。emacs的日历功能是很强大的,我只使用了万年历、生日功能。其实还有很多不错别的功能,如日记功能,以前学习emacs的时候就听有人用emacs的diary记日记和笔记。我的笔记都是用Wikij记录的,这在后面将会有介绍。

M-x calendar可以进入emacs中的日历,我将此功能绑定在一个键上了(在最后会将键的绑定)

小知识:M-x calendar是指Alt键和x键同时摁,然后在minibuffer输入calendar

下面就看看我的配置文件:
引用:;;日历基本配置
;;设置我所在地方的经纬度,calendar里有个功能是日月食的预测,和你的经纬度相联系的。
(setq calendar-latitude +39.9)
(setq calendar-longitude +116.4)
;;我的所在地北京,欢迎大家来找北京请我吃饭
(setq calendar-location-name 'Beijing')
;;这个做什么的?忘了,有谁能告诉我,谢谢。
;;我的配置文件里很多东西忘了,欢迎大家来指正下
(setq calendar-remove-frame-by-deleting t)
;;设定一周的开始为周一
(setq calendar-week-start-day 1)
;;节日和生日提醒设置
;;我不过基督徒的节日、希伯来人的节日和伊斯兰教的节日。
;;我是无神论者,不过我喜欢神话,大家有兴趣也可以探讨一下,发email给我吧
(setq christian-holidays nil)
(setq hebrew-holidays nil)
(setq islamic-holidays nil)
;;设定一些自定义的生日和节日
;;隐私需要,删掉朋友的生日
;;后面那些农历节日需要每年根据日历修改
;;有些可惜,没有中国传统农历,谁能写个扩展elisp包弄一下
(setq general-holidays '((holiday-fixed 1 1 '元旦')
(holiday-fixed 3 8 '妇女节')
(holiday-fixed 4 1 '愚人节')
(holiday-fixed 4 11 '谁的生日')
(holiday-fixed 5 1 '劳动节')
(holiday-fixed 10 1 '国庆节')
(holiday-fixed 12 25 '圣诞节')
(holiday-fixed 2 5 '元宵节')
(holiday-fixed 4 4 '清明节')
(holiday-fixed 4 21 '鬼节')
(holiday-fixed 6 22 '端午节')
(holiday-fixed 9 28 '中秋节')
(holiday-float 5 0 2 '母亲节')
(holiday-float 6 0 3 '父亲节')
))
;;其他的一些设置
;;日历不和日记相连,我不用Calendar自带的diary记日记
(setq mark-diary-entries-in-calendar nil)
;;这个又忘了,我真是忘性好!
(setq appt-issue-message nil)
;;在日历中突出标记节日和生日
(setq mark-holidays-in-calendar t)
;;打开calendar自动打开节日和生日列表
(setq view-calendar-holidays-initially t)

;;下面两个是设置年份为中国年,好像默认的是用英文写的,由王垠修改的。
;;这个设置在节日列表的春节那天能看到,如今年的春节他就写着
;;Thursday, January 22, 2004: Chinese New Year (甲-申)
(setq chinese-calendar-celestial-stem
['甲' '乙' '丙' '丁' '戊' '己' '庚' '辛' '壬' '癸'])
(setq chinese-calendar-terrestrial-branch
['子' '丑' '寅' '卯' '辰' '巳' '戊' '未' '申' '酉' '戌' '亥'])


hvj的讨论和推广emacs贴6:

这贴主要讲hvj-folding.el,内容是关于编辑的。我目前用的不多,不好发表太多想法。这里主要引用王垠的一段话如下:

“我编辑了这么长一个 HTML 文件,你觉得一定很费力,不容易定位吧?其实我的屏幕看起来就是这个样子 。所有小节都被我折叠了起来,我很容易就可以调换小节的位置。我刚才把folding的大段的配置代码移动到了另一个文件,就像移动了一行。

folding 根据不同的文档有不同的标记,它都是基于注释的。本网页就是这样一个例子。”

我的配置文件也是直接从王垠那copy过来的,如下:
PHP 代码:
;;小知识:autoload和load相比,前者是在需要时启动folding.el,而在emacs启动时只加载这个函数名而已,也就是让Emacs知道有这个函数。而是用load,则在Emacs启动时便加载,如果加载东西很多,emacs启动会很慢。
(autoload 'folding-mode 'folding'
'Minor mode that simulates a folding editor' t)
(load-library 'folding')
(defun folding-mode-find-file-hook ()
'One of the hooks called whenever a `find-file' is successful.'
(and (assq 'folded-file (buffer-local-variables))
folded-file
(folding-mode 1)
(kill-local-variable 'folded-file)))
(setq fold-fold-on-startup t)
(folding-mode-add-find-file-hook)

;;修改folding.el默认的快捷键,以方便自己使用
;;我大部分的快捷键在最后一帖中将会讲到
(setq fold-keys-already-setup nil)
(add-hook 'folding-mode-hook
(function (lambda()
(unless fold-keys-already-setup
(setq fold-keys-already-setup t)
(define-prefix-command 'ctl-f-folding-mode-prefix)
(define-key 'ctl-f-folding-mode-prefix 'f' 'fold-fold-region)
(define-key 'ctl-f-folding-mode-prefix 'e' 'fold-enter)
(define-key 'ctl-f-folding-mode-prefix 'x' 'fold-exit)
(define-key 'ctl-f-folding-mode-prefix 'b' 'fold-whole-buffer)
(define-key 'ctl-f-folding-mode-prefix 'o' 'fold-open-buffer)
(define-key 'ctl-f-folding-mode-prefix 'h' 'fold-hide)
(define-key 'ctl-f-folding-mode-prefix 's' 'fold-show)
(define-key 'ctl-f-folding-mode-prefix 't' 'fold-top-level)
(define-key 'ctl-f-folding-mode-prefix 'f' 'fold-fold-region)
)
(local-set-key 'C-f' 'ctl-f-folding-mode-prefix))))

;;设定各个模式下,折叠的具体内容和方式
(fold-add-to-marks-list 'sgml-mode
'' ' --> ')
(fold-add-to-marks-list 'c-mode '/* <' '/* > */' '*/')
(fold-add-to-marks-list 'c++-mode
'//<' '//>' '')
(fold-add-to-marks-list 'LaTeX-mode '%%% {{{' '%%% }}}' ' ')
(fold-add-to-marks-list 'latex2e-mode '%%% {{{' '%%% }}}' ' ')
(fold-add-to-marks-list 'latex-mode '%%%% {{{' '%%%% }}}' ' ')
(fold-add-to-marks-list 'BibTeX-mode '%%% {{{' '%%% }}}' ' ')
(fold-add-to-marks-list 'lisp-mode ';;; {' ';;; }' '')
(fold-add-to-marks-list 'lex-mode' /* {{{ ' ' /* }}} */ ' '*/')
(fold-add-to-marks-list 'html-mode '' '-->')
(fold-add-to-marks-list 'shell-script-mode '# {{{' '# }}}' nil)
(fold-add-to-marks-list 'sh-mode '# {{{ ' '# }}}' nil)


hvj的讨论和推广emacs贴7:

这里讲讲切换buffer的扩展elisp包。Emacs默认的好象是C-c C-b,感觉不是很人性化。所以很多emacs爱好者写出了学多这方面的扩展包:ibuffer.el,swbuffer.el,ido.el,tabbar.el,等等。

在王垠的网站里对这些包都有具体的说明。

而我使用的是ido.el和tabbar.el。

这贴主要贴一下ido.el,我对应的配置文件是hvj-ido.el,差不多也是从王垠那拷过来的。不过我用的功能不多,也没用到其切换buffer的功能,只用到其查找文件时的超级匹配功能;我切换buffer在后面的tabbar.el的功能中有讲解。切换buffer的功能,大家可以自己去体验一下,也很不错的。这个ido.el包确实非常的强大。

以下是我的hvj-ido.el,主要是对键绑定的修改。其实Emacs中的键绑定是比较难记的,但又是完全可以自定义的。除开一些基本的操作键,我很多键都自己绑定了;这就像自己写的程序,不管格式多乱,自己都能看懂。

hvj-ido.el
PHP 代码:
(require 'ido)
(ido-mode t)
(add-hook 'ido-define-mode-map-hook 'ido-hvj-keys)
(defun ido-hvj-keys ()
'Set up the keymap for `ido'.'
;; common keys
(define-key ido-mode-map 'C-e' 'ido-edit-input)
(define-key ido-mode-map 't' 'ido-complete) ;; complete partial
(define-key ido-mode-map 'C-j' 'ido-select-text)
(define-key ido-mode-map 'C-m' 'ido-exit-minibuffer)
(define-key ido-mode-map '?' 'ido-completion-help) ;; list completions
(define-key ido-mode-map [(control ? )] 'ido-restrict-to-matches)
(define-key ido-mode-map [(control ?@)] 'ido-restrict-to-matches)
;; cycle through matches
(define-key ido-mode-map 'C-r' 'ido-prev-match)
(define-key ido-mode-map 'C-s' 'ido-next-match)
(define-key ido-mode-map [right] 'ido-next-match)
(define-key ido-mode-map [left] 'ido-prev-match)
;; toggles
(define-key ido-mode-map 'C-t' 'ido-toggle-regexp) ;; same as in isearch
(define-key ido-mode-map 'C-p' 'ido-toggle-prefix)
(define-key ido-mode-map 'C-c' 'ido-toggle-case)
(define-key ido-mode-map 'C-a' 'ido-toggle-ignore)
;; keys used in file and dir environment
(when (memq ido-cur-item '(file dir))
(define-key ido-mode-map 'C-b' 'ido-enter-switch-buffer)
(define-key ido-mode-map 'C-d' 'ido-enter-dired)
(define-key ido-mode-map 'C-f' 'ido-fallback-command)
;; cycle among directories
;; use [left] and [right] for matching files
(define-key ido-mode-map [down] 'ido-next-match-dir)
(define-key ido-mode-map [up] 'ido-prev-match-dir)
;; backspace functions
(define-key ido-mode-map [backspace] 'ido-delete-backward-updir)
(define-key ido-mode-map 'd' 'ido-delete-backward-updir)
(define-key ido-mode-map [(meta backspace)] 'ido-delete-backward-word-updir)
(define-key ido-mode-map [(control backspace)] 'ido-up-directory)
;; I can't understand this
(define-key ido-mode-map [(meta ?d)] 'ido-wide-find-dir)
(define-key ido-mode-map [(meta ?f)] 'ido-wide-find-file)
(define-key ido-mode-map [(meta ?k)] 'ido-forget-work-directory)
(define-key ido-mode-map [(meta ?m)] 'ido-make-directory)
(define-key ido-mode-map [(meta down)] 'ido-next-work-directory)
(define-key ido-mode-map [(meta up)] 'ido-prev-work-directory)
(define-key ido-mode-map [(meta left)] 'ido-prev-work-file)
(define-key ido-mode-map [(meta right)] 'ido-next-work-file)
;; search in the directories
;; use C-_ to undo this
(define-key ido-mode-map [(meta ?s)] 'ido-merge-work-directories)
(define-key ido-mode-map [(control ?\_)] 'ido-undo-merge-work-directory)
)
(when (eq ido-cur-item 'file)
(define-key ido-mode-map 'C-k' 'ido-delete-file-at-head)
(define-key ido-mode-map 'C-l' 'ido-toggle-literal)
(define-key ido-mode-map 'C-o' 'ido-copy-current-word)
(define-key ido-mode-map 'C-v' 'ido-toggle-vc)
(define-key ido-mode-map 'C-w' 'ido-copy-current-file-name)
)

(when (eq ido-cur-item 'buffer)
(define-key ido-mode-map 'C-b' 'ido-fallback-command)
(define-key ido-mode-map 'C-f' 'ido-enter-find-file)
(define-key ido-mode-map 'C-k' 'ido-kill-buffer-at-head)
))

hvj的讨论和推广emacs贴8:

相信大部分在使用stardict或在将要使用linuxfans某开发组(好像有baif)的cutedict,我这里向大家推荐另外一个字典工具dictd。

dictd是一个字典服务器,dict是一个文本界面客户端。其实这个大家也应该比较熟悉,如kdict就是KDE桌面的dictd客户端。dictd的官方地址为:http://www. 。这是一个免费的字典服务器,有很多字典数据库给我们使用。

dictd的安装我就不讲了,很简单的。一般会同时安装客户端和服务器端。将dictd设为电脑启动的一个程序,这样电脑可以随时去查字典。默认的客户端为dict,常见用法就是dict -h localhost whatyourwanttolookup

在emacs下也有一个dictd的客户端,叫做dictionary.el。常用的有两种模式,一种就是查字典dictionary-lookup-definition,一种是字典提示模式(dictionary-toolip-mode),也就是有屏幕取词功能,当然这里指在Emacsl里取词。还有单词匹配功能、单词搜索功能等等......

目前这个有一些问题就是:
1,我添加了一些英汉词典,我忘了在那个网站有找的,大家可以搜搜,找不到的话,我传到Sir的ftp里。
2,目前的有关中文的词典很少(只有cdict,xdict,和stardic的默认字典,都是英汉的),而stardict的好字典很多。我现在的想法是将Stardict的字典格式能够改一下适合dictd使用。由于最近比较忙,一直托着没做,希望暑假能够去做一下。baif兄为libdict(cutedict的内核)开发字典,转了一下,我前几天看了一下,感觉还是不适合dictd使用。希望有兴趣的朋友能够参与这个给dictd增加有关中文的词典。

hvj-dictionary.el
PHP 代码:
;;在需要的时候加载所需的elisp
(autoload 'dictionary-search 'dictionary'
'Ask for a word and search it in all dictionaries' t)
(autoload 'dictionary-match-words 'dictionary'
'Ask for a word and search all matching words in the dictionaries' t)
(autoload 'dictionary-lookup-definition 'dictionary'
'Unconditionally lookup the word at point.' t)
(autoload 'dictionary 'dictionary'
'Create a new dictionary buffer' t)
(autoload 'dictionary-mouse-popup-matching-words 'dictionary'
'Display entries matching the word at the cursor' t)
(autoload 'dictionary-popup-matching-words 'dictionary'
'Display entries matching the word at the point' t)
(autoload 'dictionary-tooltip-mode 'dictionary'
'Display tooltips for the current word' t)
(autoload 'global-dictionary-tooltip-mode 'dictionary'
'Enable/disable dictionary-tooltip-mode for all buffers' t)

;;设定字典服务器为本地服务器
;;如果你在包月的宽带上,不妨设定为[url]http://www.[/url]
;;如果你在局域网上,而局域网的某台机器有dictd服务器,你将服务器设定为他的IP即可。
(setq dictionary-server 'localhost')
;;在字典提示模式中,使用wordnet字典数据库作为默认字典数据库
;;当然你可以修改,取决于你dictd服务器里的字典数据库
(setq dictionary-tooltip-dictionary 'wn')

;; 设定中文词典的解码
;; 由qtjava兄告知,谢谢!
(setq dictionary-coding-systems-for-dictionaries '(('cdict' . gb2312)
('xdict' . gbk2312)
('stardic' . gb2312)))



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)
'Print 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))


hvj的讨论和推广emacs贴10:

此帖讲讲在Emacs中看新闻组和收邮件。在emacs中看新闻组当仍不让的是gnus,收邮件的则比较多,我用过的就有gnus和mew。

这贴讲的是我以前的gnus的配置,可以看新闻组和收发邮件。

gnus的使用可以参考进化的鱼的网站和起配置文件:
网站:http://db.cs./people/WangChunyu
配置文件:http://www./bbs/showthre...threadid=57933

hvj-gnus-withemal.el
PHP 代码:
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;news/email服务器基本设置
;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;新闻和邮件服务器设置
;;常用新闻服务器:news.cn99.com和news.yaako.com
;;可更换使用,谁快用谁
(setq gnus-select-method '(nntp 'news.cn99.com'))


;;我的邮件用nnml通过pop3来收
;;hotmail和yahoo等Webmail虽说手册上写的是可以的,但我还没有成功过
;;这里也支持多邮箱的设置,直接在后面以同样格式添加即可
(add-to-list 'gnus-secondary-select-methods '(nnml ''))
(eval-after-load 'mail-source'
'(add-to-list 'mail-sources '(pop :server 'pop.citiz.net'
:user 'joanphan'
:password 'hvjhvjhvj')))


;;邮件发送配置
;;邮件通过smtp.citiz.com或本地服务器发送
;;由于有些邮箱(如hotmail.com)将本地服务器作为垃圾邮件处理,所以最好使用smtp.citiz.net
(setq send-mail-function 'smtpmail-send-it)
(setq message-send-mail-function 'smtpmail-send-it)
;;不过我还未配置好这个用外部smtp服务器,我就转用mew了
;;下面这一行是从一个地方找到的设置,大家可以试试
;(setq smtpmail-auth-credentials '(('smtp.citiz.com' 25 'hvj' nil)))
;;我以前用的都是本地服务器
(setq smtpmail-default-smtp-server '127.0.0.1')


;;启用gnus-agent可以脱页浏览
(gnus-agentize)



;;;;;;;;;;;;
;;外观设置
;;;;;;;;;;;;

;;中文设置
(setq gnus-default-charset 'cn-gb-2312
gnus-group-name-charset-group-alist '(('.*' . gb2312))
gnus-summary-show-article-charset-alist '((1 . cn-gb-2312) (2 . big5) (3 . chinese-gbk) (4 . utf-8))
gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown iso-8859-1)
gnus-group-posting-charset-alist '(('.*' gb2312 (gb2312))))
(define-coding-system-alias 'gb18030 'gb2312)

;;窗口设置
(gnus-add-configuration '(article (vertical 1.0 (summary .35 point) (article 1.0))))

;;Group Buffer设置
;;自动进入Topic-mode
(add-hook 'gnus-group-mode-hook 'gnus-topic-mode)

;;Sumarry Buffer设置
(setq gnus-summary-line-format ':%U%R %B %s %-60=|%4L |%-20,20f |%&user-date; \n')

;;Article Buffer设置
;;设定要显示的头消息格式
(setq gnus-visible-headers
'^\\(^To:\\|^CC:\\|^From:\\|^Subject:\\|^Date:\\|^Followup-To:
\\|^X-Newsreader:\\|^User-Agent:\\|^X-Mailer:
\\|Line:\\|Lines:\\|Content-Type:\\|NNTP-Posting-Host\\)')
;;自动断行,每行72个字符
(add-hook 'message-mode-hook (lambda ()
(setq fill-column 72)
(turn-on-auto-fill)))


;;;;;;;;;;;;;;;;;;
;; 回复和发送设置
;;;;;;;;;;;;;;;;;;

;;引用设置:不要原来的签名,引用全文
(setq message-cite-function 'message-cite-original-without-signature)
(add-hook 'mail-citation-hook 'sc-cite-original)

;;在新闻组中,提示确认是r(reply)还是f(follow)
(setq gnus-confirm-mail-reply-to-news t)

;;news/email基本回复设置
;;news的基本设置为将自己地址设为joanphanA@TcitizD.Tnet,避免被垃圾邮件者轻易搜到
;;email的基本设置使用公共邮件joanphan@citiz.com,私人邮箱可以在后面另设
(setq gnus-posting-styles
'(((message-mail-p)
(name 'Joanphan')
(address 'joanphan@citiz.net')
(User-Agent 'Emacs+gnus')
(signature-file '~/hvj/sig/default.sig')
)
((message-news-p)
(name 'Hans Joanphan')
(address 'joanphanA@TcitizD.Tnet')
)
))

;;goupe parameters设置
(setq gnus-parameters
;;下面是用正则表达式表达的我的文件夹mail.self和mail.local
'(('mail\\.\\(self\\|local\\).*'
(auto-expire . t)
(posting-style
(name 'Hans')
(address 'joanphan@vj.org')
;;带签名档就是如下这句
(signature-file '~/hvj/sig/default.sig')))
('mail\\.\\(misc\\|spam\\).*'
;;设定垃圾邮件自动过期
;;gnus中使用过期一词,表示邮件将会很快被删除
(auto-expire . t))
('mail\\.friends.*'
(posting-style
(name 'Joanphan')
;;给mail.friedns里的朋友回Email使用私人邮箱
;;安全原因,我这里将私人邮箱改了
;;以下的设置同上
(address 'joanphan@citiz.net')
(signature-file '~/hvj/sig/default.sig')))
('Send-.*'
(total-expire . t)
(expire-wait . 1))
('cn\\..*'
(auto-expire . t)
(posting-style
(name '永远的阿凡')
(address 'joanphanA@TcitizD.Tnet')
(User-Agent 'Slackware/Gnus')
(signature-file '~/hvj/sig/cn.sig')))
('\\(alt\\|comp\\|gnu\\|linux\\|sci\\)\\..*'
(auto-expire . t)
(posting-style
(name 'Hans Joanphan')
(address 'joanphanA@TcitizD.Tnet')
(User-Agent 'Emacs21.3/Gnus5.10.6')
(signature-file '~/hvj/sig/en.sig')))))

;;;;;;;;;;;;;;;;;;;;;
;;email/news管理设置
;;;;;;;;;;;;;;;;;;;;;

;;地址簿管理
(require 'bbdb)
(bbdb-initialize 'gnus 'message)

;;开启记分功能
(setq gnus-use-adaptive-scoring t)
(setq gnus-save-score t)
(add-hook 'message-sent-hook 'gnus-score-followup-article)
(add-hook 'message-sent-hook 'gnus-score-followup-thread)

;;定义自己的计分原则
(defvar gnus-default-adaptive-score-alist
'((gnus-kill-file-mark (from -10))
(gnus-unread-mark)
(gnus-read-mark (from 10) (subject 30))
(gnus-catchup-mark (subject -10))
(gnus-killed-mark (from -1) (subject -30))
(gnus-del-mark (from -2) (subject -15))
(gnus-ticked-mark (from 10))
(gnus-dormant-mark (from 5))))

(setq gnus-score-find-score-files-function
'(gnus-score-find-hierarchical gnus-score-find-bnews bbdb/gnus-score)
gnus-use-adaptive-scoring t)

;;archive设置
(setq gnus-message-archive-group
'((if (message-news-p)
(concat 'news.' (format-time-string '%Y-%m'))
(concat 'mail.' (format-time-string '%Y-%m')))))

;;;;;;;;;;;;;;;;
;;邮件分类
;;;;;;;;;;;;;;;;

;;保存发送的email和news分别到Send-Mail和Send-News
(setq gnus-message-archive-group
'((if (message-news-p)
'nnml:Send-News'
'nnml:Send-Mail')))

;;;使用split-fancy来分类,并取消一信多投和删除重复邮件
;;注意,这里的邮箱使用正则表达式表示,如j@linux.org应表示为j@linux.org
(setq nnmail-treat-duplicates 'delete)
;;不使用交叉投信,即下面的分类按先后有优先顺序
(setq nnmail-crosspost nil)
;;默认邮件分类不是这个,但我们所用的这个功能更强大
(setq nnmail-split-methods 'nnmail-split-fancy)
(setq nnmail-split-fancy
'(|
('from' mail (|
('subject' 'warn.*' 'mail.local')
'mail.misc'))
;;网页格式的email送入mail.html
('Content-Type' 'text/\\(html\\|richtest\\)' 'mail.html')
;;设定一些垃圾邮件过滤设置
('Content-Type' '\\(ks_c_5601-1987\\|EUC-KR\\|big5\\|iso-2022-jp\\)' 'mail.spam')
('Subject' '\\(This really work\\|XINGA\\|ADV:\\|XXX\\|adult\\|sex\\)' 'mail.spam')
('Subject' '\\(\=\?ks_c_5601-1987\?\\|\=\?euc-kr\?\\|\=\?big5\?\\)' 'mail.spam')
('X-Mailer' '\\(.*BulkMailer.*\\|.*MIME::Lite.*\\)' 'mail.spam')
('X-Mailer' '\\(.*CyberCreek Avalanche\\|.*http\:\/\/GetResponse\.com\\)' 'mail.spam')
('from' '\\(verizon\.net\\|prontomail\.com\\|money\\|ConsumerDirect\\)' 'mail.spam')
;;news-letter的设置
(any 'ding@gnus\\.org' 'list.gnus')
(any 'emacs-devel@gnu\\.org' 'list.emacs-devel')
('Subject' 'ding' 'list.ding')
;;自己给自发的邮件放入mail.self
('from' 'joanphan@vj\\.org' 'mail.self')
(to '\\(joanphan@citiz\\.net\\|joanphan@vip\\.ddd\\.com\\)'
(|
;;下面两个email是假的,用作实验
;;ddk@sina.com的邮件自动送到文件夹mail.linuxers
(from 'ddk@sina\\.com' 'mail.linuxers')
;;此处省略我的地址簿分类
;;kailiu@sina.com的邮件自动送到文件夹mail.friends
(from 'kailiu@sina\\.com' 'mail.friends')
;;接受者是我,但发送者不在以上分类,发到文件夹mail.misc
'mail.misc'))
;;其余无法归类的列为垃圾邮件,送入mail.spam
;;当然你愿意的时候可以去文件夹mail.spam看看是不是真的是垃圾邮件
'mail.spam'))

;;;;;;;;;;;;;;;;;;;;;;;
;; Misc Configurations
;;;;;;;;;;;;;;;;;;;;;;;

;;看html和richtext的email只看文本部分
(eval-after-load 'mm-decode'
'(progn
(add-to-list 'mm-discouraged-alternatives 'text/richtext')))
(setq mm-text-html-renderer 'w3m)
(setq mm-inline-text-html-with-w3m-keymap nil)

后来我用Gnus只看新闻组,设置稍微减了些,如下

hvj-gnus.el
PHP 代码:
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;news服务器基本设置
;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;新闻和邮件服务器设置
;;常用新闻服务器:news.cn99.com和news.yaako.com
;;可更换使用,谁快用谁
(setq gnus-select-method '(nntp 'news.cn99.com'))

;;启用gnus-agent可以脱页浏览
(gnus-agentize)


;;;;;;;;;;;;
;;外观设置
;;;;;;;;;;;;

;;中文设置
(setq gnus-default-charset 'cn-gb-2312
gnus-group-name-charset-group-alist '(('.*' . gb2312))
gnus-summary-show-article-charset-alist '((1 . cn-gb-2312) (2 . big5) (3 . chinese-gbk) (4 . utf-8))
gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown iso-8859-1)
gnus-group-posting-charset-alist '(('.*' gb2312 (gb2312))))
(define-coding-system-alias 'gb18030 'gb2312)

;;窗口设置
(gnus-add-configuration '(article (vertical 1.0 (summary .35 point) (article 1.0))))

;;Group Buffer设置, 自动进入Topic-mode
(add-hook 'gnus-group-mode-hook 'gnus-topic-mode)

;;Sumarry Buffer设置
(setq gnus-summary-line-format ':%U%R %B %s %-60=|%4L |%-20,20f |%&user-date; \n')

;;Article Buffer设置
;;设定要显示的头消息格式
(setq gnus-visible-headers
'^\\(^To:\\|^CC:\\|^From:\\|^Subject:\\|^Date:\\|^Followup-To:
\\|^X-Newsreader:\\|^User-Agent:\\|^X-Mailer:
\\|Line:\\|Lines:\\|Content-Type:\\|NNTP-Posting-Host\\)')
;;自动断行,每行72个字符
(add-hook 'message-mode-hook (lambda ()
(setq fill-column 72)
(turn-on-auto-fill)))


;;;;;;;;;;;;;;;;;;
;; 回复和发送设置
;;;;;;;;;;;;;;;;;;

;;引用设置:不要原来的签名,引用全文
(setq message-cite-function 'message-cite-original-without-signature)
(add-hook 'mail-citation-hook 'sc-cite-original)

;;在新闻组中,提示确认是r(reply)还是f(follow)
(setq gnus-confirm-mail-reply-to-news t)

;;news基本回复设置
(setq gnus-posting-styles
'(((message-news-p)
(name 'Hans Joanphan')
(address 'joanphanA@TcitizD.Tnet')
)
))

;;group parameters设置
(setq gnus-parameters
'(('Send-.*'
(total-expire . t)
(expire-wait . 1))
('cn\\..*'
(auto-expire . t)
(posting-style
(name '永远的阿凡')
(address 'joanphanA@TcitizD.Tnet')
(User-Agent 'Slackware/Gnus')
(signature-file '~/hvj/sig/cn.sig')))
('\\(alt\\|comp\\|gnu\\|linux\\|sci\\)\\..*'
(auto-expire . t)
(posting-style
(name 'Hans Joanphan')
(address 'joanphanA@TcitizD.Tnet')
(User-Agent 'Emacs21.3/Gnus5.10.6')
(signature-file '~/hvj/sig/en.sig')))))

;;;;;;;;;;;;;;;;;;;;;
;;news管理设置
;;;;;;;;;;;;;;;;;;;;;

;;开启记分功能
(setq gnus-use-adaptive-scoring t)
(setq gnus-save-score t)
(add-hook 'message-sent-hook 'gnus-score-followup-article)
(add-hook 'message-sent-hook 'gnus-score-followup-thread)

;;定义自己的计分原则
(defvar gnus-default-adaptive-score-alist
'((gnus-kill-file-mark (from -10))
(gnus-unread-mark)
(gnus-read-mark (from 10) (subject 30))
(gnus-catchup-mark (subject -10))
(gnus-killed-mark (from -1) (subject -30))
(gnus-del-mark (from -2) (subject -15))
(gnus-ticked-mark (from 10))
(gnus-dormant-mark (from 5))))

(setq gnus-score-find-score-files-function
'(gnus-score-find-hierarchical gnus-score-find-bnews bbdb/gnus-score)
gnus-use-adaptive-scoring t)

;;archive设置
(setq gnus-message-archive-group
'((if (message-news-p)
(concat 'news.' (format-time-string '%Y-%m')))))


;;保存发送的news分别到Send-News
(setq gnus-message-archive-group
'((if (message-news-p)
'nnml:Send-News')))


hvj的讨论和推广emacs贴11:

前面讲到用gnus收发Email,我们还有另外一个不错的选择,就是mew。

其实Gnus(注:安装emacs后需另升级gnus)和mew对中文支持差不多了,但是有两点理由我暂时转向了mew
1,gnus收新闻和email同时时很慢(两者没有影响,只是加起来就长了),而分开后感觉就快了
注:有朋友解决了这个问题,用fetchmail收邮件到本地,在用gnus看本地邮件,速度就快了
2,gnus没有将邮件保存在服务器的功能,对于一些我无法处理的Unicode解码的邮件我是无可奈何,但是mew可以,对于比较少数的unicode解码邮件,我大不了上网用浏览器看
注:有朋友解决了这个问题,fetchmail取信有保存邮件到邮件服务器的功能

当然了,mew没有gnus强大的邮件分类归档功能,对垃圾邮件处理不行。等到下一版emacs对unicode支持好了,我还是会用gnus。
注:emacs-cvs对unicode已经不错,大家可以去试用

下面是我的hvj-mew.el
PHP 代码:
;;;;;;;;;;;;;;;;;;;;;
;;启动和初始化mew的设置
;;将emacs收发邮件的默认设置为gnus改为mew
;;;;;;;;;;;;;;;;;;;;;
(autoload 'mew 'mew' nil t)
(autoload 'mew-send 'mew' nil t)
;;设定图表所在文件夹,这个和w3m类似,如果不正确,mew无法启动
(setq mew-icon-directory '/usr/share/mew')
(if (boundp 'read-mail-command)
(setq read-mail-command 'mew))
(autoload 'mew-user-agent-compose 'mew' nil t)
(if (boundp 'mail-user-agent)
(setq mail-user-agent 'mew-user-agent))
(if (fboundp 'define-mail-user-agent)
(define-mail-user-agent
'mew-user-agent
'mew-user-agent-compose
'mew-draft-send-message
'mew-draft-kill
'mew-send-hook))


;;;;;;;;;;;;;;;;;;;;;;
;;信件引用设置
;;;;;;;;;;;;;;;;;;;;;;
(setq mew-cite-fields '('From:' 'Subject:' 'Date:' 'Message-ID:'))
(setq mew-cite-format 'From: %s\nSubject: %s\nDate: %s\nMessage-ID: %s\n\n')
(setq mew-cite-prefix-function 'mew-cite-prefix-username)


;;;;;;;;;;;;;;;;;;;;;
;;用w3m来读html格式邮件
;;w3m的使用将在以后讲到
;;;;;;;;;;;;;;;;;;;;;
(setq mew-mime-multipart-alternative-list '('Text/Html' 'Text/Plain' '*.'))
(condition-case nil
(require 'mew-w3m)
(file-error nil))


;;;;;;;;;;;;;;;;;
;;一些其他设置,未归类
;;;;;;;;;;;;;;;;;
(setq mew-pop-size 0)
(setq toolbar-mail-reader 'Mew)
(set-default 'mew-decode-quoted 't)
;;设定公共钥匙所用程序,下面采用的是GnuPG
(setq mew-prog-pgp 'gpg')


;;;;;;;;;;;;
;;设定用户信息
;;;;;;;;;;;;
(setq mew-name 'Hans Joanphan')
(setq mew-user 'joanphan')


;;;;;;;;;;;;
;;设定smtp服务器
;;个人原因,这里不列出我的正确Email
;;;;;;;;;;;;
(setq mew-smtp-user 'joanphan@citiz.com')
(setq mew-mail-domain 'citiz.com')
(setq mew-smtp-server 'smtp.citiz.com')
;;smtp服务器认证设定
(setq mew-smtp-auth-list (quote ('CRAM-MD5' 'LOGIN' 'PLAIN')))
;;smtp服务器不用认证采用下面设定
;(setq mew-smtp-auth-list nil)


;;;;;;;;;;;
;;设定pop3服务器
;;个人原因,这里不列出我的正确Email
;;;;;;;;;;;
(setq mew-pop-server 'pop.citiz.net')
(setq mew-pop-user 'joanphan@citiz.com')
(setq mew-pop-auth 'pass) ;;认证方式
(setq mew-pop-delete nil) ;;将邮件留在服务器上

;;;;;;;;;;;;
;;设定将密码保存一段时间,默认20分钟
;;;;;;;;;;;;
(setq mew-use-cached-passwd t)
;;gnus可以将密码放在配置文件里,收邮件的时候就不用输入密码了
;;我找了一下,发现下面这个变量应该有类似功能,但没有搞掂,高人帮忙!
;(setq mew-passwd-alist '(hvjhvjhvj)

;;;;;;;;;;;;;;;;;;;;;
;;语言设置
;;这个不知道有用没,好像在下一版emacs对unicode支持好了就可以了
;;当然这个试用emacs-cvs
;;;;;;;;;;;;;;;;;;;;;
(when (boundp 'utf-translate-cjk)
(setq utf-translate-cjk t)
(custom-set-variables
'(utf-translate-cjk t)))
(if (fboundp 'utf-translate-cjk-mode)
(utf-translate-cjk-mode 1))

默认的邮件保存在~/Mail,里面的文件Addrbook是地址本设置,设置好,在写邮件时可以自动补全,同gnus里使用bbdb一样,也有组群发功能。

一个地址簿样本:

代码:
hvj hvj@hvj.org
hhh hhh@hvj.org
h hvj, hhh

hvj的讨论和推广emacs贴12:

emacs中浏览网页的工具包主要有两个w3和w3m,xemacs中会默认使用w3,而w3已经很久没有更新了,在GNU emacs中推荐使用w3m。

w3m是一个非常优秀的字符端网页浏览器,并且对CJK支持非常不错;在emacs中使用w3m是通过emacs-w3m扩展包使用w3m的。而w3是完全用elisp语言编写的一个给emacs使用的浏览器扩展包。相对而言,emacs-w3m速度更快,对中文支持更好,对网页的支持也更强一些。

安装w3m时如果要给emacs使用,还得安装emacs-w3m包;另,很重要的一点,要安装w3m的图标,否则emacs-w3m无法使用。

emacs-w3m不仅仅可用来单独浏览网页(支持图片),gnus或mew可以调用他来读html格式的邮件,所以对于一个爱好emacs的朋友,我还是推荐大家安装w3m;虽然大部分我们上网浏览网页还是用mozilla或opera。

下面是我的配置文件:
hvj-w3m.el
PHP 代码:
;;启动和初始化w3m.el
(autoload 'w3m 'w3m' 'Interface for w3m on Emacs.' t)
(autoload 'w3m-browse-url 'w3m' 'Ask a WWW browser to show a URL.' t)
(autoload 'w3m-search 'w3m-search' 'Search words using emacs-w3m.' t)
;;使用mule-ucs,只有在你安装mule-ucs elisp扩展包时这个才有用,可以看Unicode解码的网页
(setq w3m-use-mule-ucs t)
;;使用工具包
(setq w3m-use-toolbar t)
;;启用cookie
(setq w3m-use-cookies t)
;;设定w3m图标所在文件夹,gentoo的默认安装位置就是如下,大家可以根据自己的情况改一下
(setq w3m-icon-directory '/usr/share/emacs-w3m/emacs-w3m/icon')
;;设定w3m运行的参数,分别为使用cookie和使用框架
(setq w3m-command-arguments '('-cookie' '-F'))
;;用w3m浏览网页时也显示图片
(setq w3m-display-inline-image t)
;;设定w3m的语言设置,以便方便使用和阅读中文
;;书签解码设置
(setq w3m-bookmark-file-coding-system 'chinese-iso-8bit)
;;w3m的解码设置,后面最好都有,我也不详解了
(setq w3m-coding-system 'chinese-iso-8bit)
(setq w3m-default-coding-system 'chinese-iso-8bit)
(setq w3m-file-coding-system 'chinese-iso-8bit)
(setq w3m-file-name-coding-system 'chinese-iso-8bit)
(setq w3m-terminal-coding-system 'chinese-iso-8bit)
(setq w3m-input-coding-system 'chinese-iso-8bit)
(setq w3m-output-coding-system 'chinese-iso-8bit)
;;w3m是使用tab的,设定Tab的宽度
(setq w3m-tab-width 8)
;;设定w3m的主页,同mozilla的默认主页一样
(setq w3m-home-page 'file://home/hans/.w3m/bookmark.html')
;;以下都给倒忘了
(setq w3m-view-this-url-new-session-in-background t)
(add-hook 'w3m-fontify-after-hook 'remove-w3m-output-garbages)
;;好像是有利于中文搜索的
(defun remove-w3m-output-garbages ()
(interactive)
(let ((buffer-read-only))
(setf (point) (point-min))
(while (re-search-forward '[\200-\240]' nil t)
(replace-match ' '))
(set-buffer-multibyte t))
(set-buffer-modified-p nil))


hvj的讨论和推广emacs贴13:

sir的IRC已经开了,相信不少人想去聊天和讨论问题,也找了不少IRC客户端,如:Xchat, mirc, ircssi, chatzilla等等,这里就向大家推荐erc,emacs里的IRC客户端,对中文的支持也是非常好的。

下面是我的配置文件和讲解:hvj-erc.el

PHP 代码:
;;加载erc.el包
;;这个配置文件最好不要编译,否则下面定义的erc-sir等函数不能用
;;不过这个应该可以修改,我以后试试
(require 'erc)
;;设定一个有关方便连接IRC服务器的函数
(defmacro de-erc-connect (command server port nick)
'Create interactive command `command', for connecting to an IRC server. The
command uses interactive mode if passed an argument.'
(fset command
`(lambda (arg)
(interactive 'p')
(if (not (= 1 arg))
(erc-select ,server ,port ,nick)
(erc ,server ,port ,nick ,erc-user-full-name t)))))
;;这是咱们Sir的IRC,大家记得常去
(de-erc-connect erc-sir '' 6667 'hvj')
;;这是linuxfans的IRC,有些时日了
(de-erc-connect erc-fans 'irc.linuxfans.org' 6667 'hvj')
;;下面是我所在局域网里的IRC
(de-erc-connect erc-me '192.168.1.191' 6667 'hvj')
(de-erc-connect erc-van '192.168.1.14' 6667 'hvj')

;;设定一些有关变量
(custom-set-variables
;;进入linuxsir的IRC,自动加入#javalee频道,咱们的灌水频道,人气还不错
'(erc-autojoin-channels-alist '(('' '#javalee')
;;进入linuxfans的IRC,自动加入#linuxfans和#linuxer频道,不过linuxfans的IRC已经自动这样设置了
('irc.linuxfans.org' '#linuxfans' '#linuxer')))
;;在默认情况下IRC里我的ID是hvj
'(erc-email-userid 'hvj')
;;设定聊天时的行宽,方便阅读
'(erc-fill-column 67)
;;什么来着?
'(erc-fill-prefix ' ')
;;屏蔽掉的一些命令
'(erc-hide-list '('JOIN' 'PART' 'QUIT'))
;;默认的昵称,这和userid有什么区别?还不清楚,清大家告诉我。
'(erc-nick 'hvj')
;;默认的端口6667
'(erc-port 6667)
;;登录这些IRC不用密码登录
;;我在linuxfans已经注册了我的ID,我不用密码登录,将会一分钟后将我改名
;;下次我将改改这个变量
'(erc-prompt-for-password nil)
;;有关退出IRC的,什么意思来着?
'(erc-quit-reason 'erc-quit-reason-zippy)
;;不保存IRC聊天记录
;;大家可以找找,是可以保存的,只要你愿意
'(erc-save-buffer-on-part nil))

;;设定erc模式的一个滚动设置,保持输入在当前窗口的最后一行
(add-hook 'erc-mode-hook 'erc-add-scroll-to-bottom)

;;erc中文的关键设置,这个一定需要,否则你只能看中文,而不能“说”中文
(setq erc-encoding-default 'chinese-iso-8bit)


这贴讲一点emacs中的文件管理了。Emacs的文件管理默认有一个扩展包dired.el,这是一个同命令行式文件管理器相似但又功能非常强大的东东。我想对于emacs的爱好者,以及一些NO GNOME&NO KDE的用户,这是一个非常好的工具。

PHP 代码:
;;设定显示文件的参数,具体不记得了,以后再加上
(setq dired-listing-switches '-vl')
;;允许复制和删除时将文件夹里所有内容一起带上
(setq dired-recursive-copies t)
(setq dired-recursive-deletes t)
;;cvs时的一个浏览设置
(setq cvs-dired-use-hook 'always)
;;主要可以详细设置的地方
;;对于特定的文件,用什么程序打开
;;记住是用!,而不是enter键,enter键表示编辑,同v
;;记住在后面带上&,为后台运行,我们还要用Emacs做别的事情呢
;;下面的文件用的是正则表达式,要表达清楚
(add-hook 'dired-load-hook
(function (lambda ()
;;记住这里要加载另一个有关文件管理器的包dired-x.el,这个是dired的扩展,非常强大
(load 'dired-x')
(setq dired-guess-shell-alist-user
(list
(list '\\.tar\\.bz2$' 'tar jxvf * &')
'('\\.ps$' 'gv * &')
'('\\.html?$' 'rxvt -e w3m * &')
'('\\.pdf$' 'xpdf * &')
'('\\.\\(jpe?g\\|gif\\|png\\|bmp\\|xbm\\|fig\\|eps\\)$' 'display * &')
'('\\.\\([Ww][Mm][Vv]\\|[Vv][Oo][Bb]\\|[Mm][Pp][Ee]?[Gg]\\|asf\\|[Rr][Aa]?[Mm]\\)$' 'mplayer * &')
))
)))
;;这个也忘了,好像是不允许忽略掉某些文件
;;到底是哪些文件,我想想
(add-hook 'dired-mode-hook
(function (lambda ()
(setq dired-omit-files-p nil)
)))


hvj的讨论和推广emacs贴15:

上面讲了不少别的地方有,emacs中也有的工具,如文件管理器dired,IRC客户端erc,邮件客户端mew,新闻组阅读器gnus,字典emacs-dictionary等等,那么是否也有虚拟终端呢?

大家常用的是xterm, rxvt, mlterm, 等等,主要希望的就是对中文支持够好。而在emacs中也有类似的工具,虽然有的只是调用外面的程序而已。

前不久在sir里面讨论时,就发现原来emacs中只是有四种虚拟终端:eshell, shell, term, termianl-emulator。而我一直孤陋寡闻,使用的是eshell,这是一个由elisp写的,老感觉只是凑合而已。不过现在不同了,term真的不错,感觉就跟rxvt一样,非常方便,当然因为在Emacs里,还支持粘贴/复制呢。鄙人一直没搞定在rxvt和外部程序的粘贴复制

小知识:上面这些虚拟终端可以通过类似M-x term的命令来运行。

因为刚开始用,目前这方面还没有单独的配置文件,都是默认的。但是有几点大家可以注意一下:
1,eshell没有使用~/.bashrc配置文件的,所以你得单独写很多elisp来完成你在~/.bashrc里有的功能。不过eshell有个小功能不错,摁TAB键多几次,你会发现补全很有意思和效率。
2,term(shell, termianl-emulator?)是使用你得Bash配置文件的,这一点我非常喜欢。可能大家会觉得term里的提示符不大漂亮,可以在~/.bashrc里设置一下,大家可以通过命令
代码:
echo $TERM
获得当前的TERM变量来设置。term的TERM变量为eterm。
3,目前我只会在一个emacsl里打开一个term。我在用eshell的时候见过有人这样写的,通过修改eshell的buffer名称,可以同时打开几个Eshell。以后有空我会在term这里试试,不知可行性如何?


hvj的讨论和推广emacs贴16:

用wiki整理你的笔记和作小型网站。虽然html也不难,但是wiki更简单,做的网页也非常不错,管理站点也很好。目前Wiki有很多版本,我常用的就是emacs-wiki,和大家分享一下。不过目前没有用他作网站,只是管理笔记,感觉非常的灵活。下面就是我的配置文件:

hvj-wiki.el
PHP 代码:
;;加载emacs-wiki
(require 'emacs-wiki)
;;设置wiki所在文件夹
(setq emacs-wiki-directories '('~/hvj/wiki'))
;;设置wiki转换为html后所在的文件夹
(setq emacs-wiki-publishing-directory 'publish')
;;设置wiki转为html用的解码
;;但好像仍然有些问题,用firefox打开时有时仍需手动调整解码
(setq emacs-wiki-meta-charset 'gb2312')
;;设置wiki转为html的样式,不过目前我还没用
(setq emacs-wiki-style-sheet
'')
;;设置Wiki内图片的路径
(setq emacs-wiki-inline-relative-to 'default-directory)

;;现面两个函数,是由王垠编写的
;;预览生成网页的源码,即html源码
;;不过先将wiki生成html
(defun emacs-wiki-preview-source ()
(interactive)
(emacs-wiki-publish-this-page)
(find-file (emacs-wiki-published-file)))
;;这个函数是预览在浏览器中所生成的网页
;;这里用的是emacs-w3m浏览器,你也可使用外部浏览器,如firefox,这可能稍复杂点
(defun emacs-wiki-preview-html ()
(interactive)
(emacs-wiki-publish-this-page)
(w3m-browse-url (emacs-wiki-published-file)))

;;设定你的Wiki项目,有时候你可能拥有几个,一个给个人整理笔记用,一个用来发表为网站形式
(setq emacs-wiki-projects
'(('default' . ((emacs-wiki-directories . ('~/hvj/wiki'))))
('work' . ((fill-column . 65)
(emacs-wiki-directories . ('~/hvj/workwiki/'))))))


hvj的讨论和推广emacs贴17:

这里是我用的非emacs默认的扩展包,都是自己安装的,配置文件也不常,就集中在这里了。

hvj-other-elisp.el
PHP 代码:
;;有关解压缩的,以前用过,好久没用了
(require 'jka-compr)

;;desktop.el在.emacs文件中(贴1)讲过,需要放在Emacs配置文件的最后

;;session.el,同desktop.el,保存上次关闭时编辑文件所在的位置,而不仅仅只是打开那些文件
(require 'session)
;;将这个功能加到emacs初始化过程中
(add-hook 'after-init-hook 'session-initialize)

;;redo.el,与undo相反了,不过Emacs默认没有带这个功能
(require 'redo)

;;thumbs.el,看图的好东西,方便看大量的图片
;;他将图片都建立缩略图,所以第一次看比较慢,以后就方便了
;;不过我最近不用了,我喜欢用display *
;;(require 'thumbs)

;;tabbar.el,用firefox,opera的人都用过tab,很方便和人性化的一个功能
;;这里也有,并且按文件的模式分类
;;对于这个扩展包,我还用了一个绑定键,用来切换buffer,很方便
;;不过在非X下功能不全
(require 'tabbar)
(tabbar-mode)

;;table.el,图表功能,不错
;;还有一个适合双字节的一个类似的扩展包,大家可找找
;;好像是印度人写的
(require 'table)
(autoload 'table-insert 'table' 'WYGIWYS table editor')
(add-hook 'text-mode-hook 'table-recognize)

;;browse-kill-ring.el,emacs默认undo次数不多,用这个扩展包,可以极大的加强这个功能
;;有一次我在翻译一本书,翻译了一天,有好几万行了,朋友叫我去打排球,我就保存放在那里了
;;宿舍的一个朋友不懂emacs,在那用鼠标左键右键中键点了几次,却不知鼠标的键在emacs通过组合绑定了不少功能
;;可惜我的翻译文档,我回来的时候,全没了!
;;不过还好,有了这个包,我可以超强恢复,也不知道摁了多少次undo,所有的都恢复了
(require 'browse-kill-ring)
(browse-kill-ring-default-keybindings)

;;sawfish.el,我的窗口管理器是sawfish,我在编辑Sawfish的配置文件时,用这个模式可以正确的语法显示
(autoload 'sawfish-mode 'sawfish' 'sawfish-mode' t)

;;maxima.el,我很喜欢的数值计算工具maxima在emacs中使用所需的扩展包
;;maxima-mode只是普通的模式,同在终端上运行maxima类似
(autoload 'maxima 'maxima' 'Maxima interaction' t)
(autoload 'maxima-mode 'maxima' 'Maxima mode' t)
;;emaxima-mode,这个是非常漂亮的,因为掉用了tex,那可是对数学天生支持就好的
(autoload 'emaxima-mode 'emaxima' 'Emaxima' t)
(add-hook 'emaxmia-mode-hook 'emaxima-mark-file-as-emaxima)
(autoload 'imaxima 'imaxima' 'Image support for Maxima.' t)

;;htmlhelpmode.el,加强的html扩展包,对html等网页源码能更好的语法显亮
(autoload 'html-helper-mode 'html-helper-mode' 'Yay HTML' t)
;;css-mode.el,对css文件很配
(autoload 'css-mode 'css-mode' 'Mode for editing CSS files' t)

;;services.el,一个小巧的玩意,询问端口和对应服务的关系
(autoload 'services-lookup 'services' 'Perform a service lookup' t)
(autoload 'services-clear-cache 'services' 'Clear the service cache' t)

;;igrep.el,emacs中的egrep
(require 'igrep)


hvj的讨论和推广emacs贴18:

emacs和vim的一大有点就是对大量的文件有语法高亮显示,这里看一点emacs中的语法高亮显示。当然这里我们可以看到emacs所支持的好像没有vim多一点,但是无关紧要,Emacs的爱好者可以自个写的,我等着大家

hvj-mode.el
PHP 代码:
;;将默认模式从fundemental-mode改为text-mode
(setq default-major-mode 'text-mode)
;;启动语法高亮模式
(global-font-lock-mode t)
;;一些具体的设置,从别的地方拷过来的,目前编程较少,所以也没具体改了,感觉目前配置还是非常不错的
;;如果你是一个程序员,这块你可以仔细改改
(setq font-lock-maximum-decoration t)
(setq font-lock-global-modes '(not text-mode))
(setq font-lock-verbose t)
(setq font-lock-maximum-size '((t . 1048576) (vm-mode . 5250000)))

;;对相应的文件设定相应的模式,以便正确的语法显亮
;;文件名用正则表达式表示,注意不要后面覆盖了前面的而引起的误会
;;修改这个之前先C-h v auto-mode-alist查查已有的设置
(mapcar
(function (lambda (setting)
(setq auto-mode-alist
(cons setting auto-mode-alist))))
'(('\\.\\(xml\\|rdf\\)\\'' . sgml-mode)
('\\.\\([ps]?html?\\|cfm\\|asp\\)\\'' . html-helper-mode)
('\\.css\\'' . css-mode)
('\\.\\(emacs\\|session\\|gnus\\)\\'' . emacs-lisp-mode)
('\\.wiki\\'' . emacs-wiki-mode)
('\\.\\(jl\\|sawfishrc\\)\\'' . sawfish-mode)
('\\.scm\\'' . scheme-mode)
('\\.py\\'' . python-mode)
('\\.\\(ba\\)?sh\\'' . sh-mode)
('\\.l\\'' . c-mode)
('\\.max\\'' . maxima-mode)))


hvj的讨论和推广emacs贴19:

emacs中的键绑定吓跑了很多人,觉得太难记了,其实你完全可以自己来重新定义这些键。我的如下:

PHP 代码:
;;统一设置键帮定,并尽量放在配置文件的最后,以免被绑定的键不小心被后面的配置文件覆盖
;;常用习惯,F1打开帮助,常用帮助有info和woman(就是在emacs中看man)
(global-set-key [f1] 'info)
;;恢复,常用键
(global-set-key [f2] 'undo)
;;反恢复,不是很常用,但是绑定了还是方便些
(global-set-key [f3] 'redo)
;;F4,kill键,习惯设置,关闭当前buffer
(global-set-key [f4] 'kill-this-buffer)
;;打开一个终端,根据你的爱好可以绑定为:eshell,shell,terminal-emulator
(global-set-key [f5] 'term)
;;文件管理器,常用
(global-set-key [f6] 'dired-jump)
;;同clear相识,具体功能在hvj-functions.el讲过
(global-set-key [f7] 'hvj-line-to-top-of-window)
;;本人正在学scheme,常用
(global-set-key [f8] 'run-scheme)
;;看新闻组,常用的很,不过更多时间现在sir里
(global-set-key [f9] 'gnus)
;;习惯设置,打开/关闭菜单
(global-set-key [f10] 'menu-bar-mode)
;;编译等,暂时还不常用
(global-set-key [f11] 'compile)
(global-set-key [f12] 'gdb)

;;习惯设置,Home键设定光标到文件开头
(global-set-key [(home)] 'beginning-of-buffer)
;;习惯设置,End键设定光标到文件结尾
(global-set-key [(end)] 'end-of-buffer)

;;meta在常用PC键上就是Alt键
;;这三个绑定主要是光标移动的
(global-set-key [(meta down)] 'goto-line)
(global-set-key [(meta left)] 'backward-sexp)
(global-set-key [(meta right)] 'forward-sexp)

;;用Emacs时常用多个窗口,窗口之间的移动很常见
;;默认的绑定感觉不对劲,换了
(global-set-key [(control o)] 'other-window)
;;这就是我的切换buffer的设置,同windows操作相识
;;没法,windows用了两年多,有些习惯还真不好改
;;不过emacs的配置就是好配,随你配
(global-set-key [(control tab)] 'tabbar-forward)
;;这个设置是改变outline的快捷键前缀
;;outline主要用于编程等,目前用的不多
(setq outline-minor-mode-prefix [(control o)])

;;默认的Ctrl-z是什么来着,关闭emacs吧,好像还是强行关闭,不好,用C-x c就好了
;;我就将Ctrl-z作为我的键的绑定
(define-prefix-command 'ctl-z-map)
(global-set-key (kbd 'C-z') 'ctl-z-map)
;;编译当前emacs-lisp源码为elc
(global-set-key (kbd 'C-z b') 'emacs-lisp-byte-compile)
;;打开我得日历
(global-set-key (kbd 'C-z c') 'calendar)
;;字典功能,就是查单词
(global-set-key (kbd 'C-z d d') 'dictionary-lookup-definition)
;;与上面类似
(global-set-key (kbd 'C-z d s') 'dictionary-search)
;;查询当前单词的匹配的单词,用于补全单词
(global-set-key (kbd 'C-z d m') 'dictionary-match-words)
;;字典提示模式,同字典的自动取词功能相似
(global-set-key (kbd 'C-z d t') 'dictionary-tooltip-mode)
;;启动我的IRC客户端,到sir去
(global-set-key (kbd 'C-z e s') 'erc-irc)
;;到fans聊天去
(global-set-key (kbd 'C-z e f') 'erc-fans)
;;启动拼写检查模式,只检查打开后输入的单词
(global-set-key (kbd 'C-z f m') 'flyspell-mode)
;;对整个buffer进行拼写检查
(global-set-key (kbd 'C-z f b') 'flyspell-buffer)
;;打开gnus
(global-set-key (kbd 'C-z g') 'gnus)
;;数数本文件有多少文字
(global-set-key (kbd 'C-z h c') 'hvj-count-words-region)
;;同Clear键
(global-set-key (kbd 'C-z h l') 'hvj-line-to-top-of-window)
;;拼写检查
(global-set-key (kbd 'C-z i') 'ispell-minor-mode)
;;debug
(global-set-key (kbd 'C-z j') 'jdb)
;;查看前面删除的内容记录
(global-set-key (kbd 'C-z k') 'browse-kill-ring)
;;打印当前buffer
(global-set-key (kbd 'C-z l') 'lpr-buffer)
;;启动我得maxima,漂亮模式
(global-set-key (kbd 'C-z m') 'imaxima)
;;绑定两个narrow功能
(global-set-key (kbd 'C-z n n') 'narrow-to-region)
(global-set-key (kbd 'C-z n w') 'widen)
(global-set-key (kbd 'C-z o') 'occur)
;;几个小游戏
(global-set-key (kbd 'C-z p g') 'gomoku)
(global-set-key (kbd 'C-z p t') 'tetris)
;;由于在html-helper-mode模式中F4键失效,用这个绑定来关闭buffer
(global-set-key (kbd 'C-z q') 'kill-this-buffer)
;;带正则表达式的搜索
(global-set-key (kbd 'C-z r') 'query-replace-regexp)
;;我得scheme也是可以在emacs中运行的
(global-set-key (kbd 'C-z s') 'run-scheme)
;;我的终端
(global-set-key (kbd 'C-z t') 'term)
;;可以在emacs编辑文件使用vim习惯,常用的是vi-mode和viper-mode
(global-set-key (kbd 'C-z v') 'vi-mode)
;;我的文件管理器
(global-set-key (kbd 'C-z u d') 'dired-jump)
(global-set-key (kbd 'C-z u f') 'folding-mode)
(global-set-key (kbd 'C-z u o') 'outline-minor-mode)
;;查询service,见hvj-other-elisp
(global-set-key (kbd 'C-z u s') 'services-look-up)
;;wiki中的绑定设置,还用的不多
(global-set-key (kbd 'C-z w c') 'emacs-wiki-change-project)
(global-set-key (kbd 'C-z w f') 'emacs-wiki-find-file)
(global-set-key (kbd 'C-z w h') 'emacs-wiki-preview-html)
(global-set-key (kbd 'C-z w i') 'emacs-wiki-index)
(global-set-key (kbd 'C-z w p') 'emacs-wiki-publish)
(global-set-key (kbd 'C-z w s') 'emacs-wiki-search)
;;我的浏览器
(global-set-key (kbd 'C-z w w') 'w3m)
;;同C-z b有点不同,在编译后并加载
(global-set-key (kbd 'C-z x') 'emacs-lisp-byte-compile-and-load)
;;同yank有点不一样,但具体怎样忘了,感觉这个比yank好点
(global-set-key (kbd 'C-z y') 'clipboard-yank)
;;修改后的设定mark的绑定,由于经常忘了放住control键,就给这个功能两个绑定了
(global-set-key (kbd 'C-z z') 'set-mark-command)
(global-set-key (kbd 'C-z C-z') 'set-mark-command)

;;there are severl other key-map below in other files
;;ctrl-f-folding-mode-prefix
;;ido key-map
;;severl self define functions related key-bindings.

这是我配置文件总结的最后一贴了,有空我会修复其中的一些不足和错误之处。希望这对大家使用Emacs能有所帮助。也欢迎大家多提意见,对这些配置文件多一些修改意见



    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多