|
既然官方的erc不支持中文。咱们就偷梁换柱吧
From: "It's me FKtPp ;)" <anti-Spam@anti-virus.org>
Subject: 为了追新,呵呵
Newsgroups: cn.comp.os.linux
Date: Tue, 28 Oct 2003 22:12:43 +0800
Organization: Bentium Ltd. (CN99)
大家知道,erc的cvs版本使用了zenirc(好像是这个名子)的服务器消息处理代
码。结果导致很多本来可以正常显示的中文没法正常显示了。为了使用最新的
erc(俺是追新族)本来我准备自己修改erc的代码,然后做个patch一劳永逸的,
但是。。。功力有限啊、加上人家erc的源码更新很快。只好在配制文件里面做
文章了。
因为发现每次登录一个服务器,erc会自动evaluation那个.ercrc.el文件,而
emacs的函数定义有个特点,就是新定义的同名函数可以复盖先前的定义,哈哈,
有办法了。。
在~/.emacs里面加入:
- ;; To prevent ERC from loading at startup, you may use auto-load in
- ;; your ~/.emacs file. Here is an example:
- (autoload 'erc-select "erc" "IRC client." t)
- ;; This will add it to the Tools menu. It uses EasyMenu.
- (require 'easymenu)
- (easy-menu-add-item nil '("tools")
- ["IRC" erc-select t])
复制代码
再创建一个~/.ercrc.el文件,内容如下:
- ;; Add dcc support
- (require 'erc-xdcc)
- ;; In order to use timestamps, you need to load the module, and
- ;; activate the global minor mode:
- (require 'erc-stamp)
- (erc-timestamp-mode 1)
- ;; This will add a timestamp to new lines if at least a minute has
- ;; past since the last timestamping.
- ;; I prefer the timestamps on the left, and on every line:
- (setq erc-timestamp-only-if-changed-flag nil
- erc-insert-timestamp-function 'erc-insert-timestamp-left
- erc-timestamp-format "[%H:%M] "
- erc-fill-prefix " + "
- erc-fill-column 72)
- ;; ERC Highlighting primitives can be found in the module
- ;; 'erc-match. Use the following in your ~/.emacs to activate it.
- (require 'erc-match)
- (erc-match-mode 1)
- (setq erc-current-nick-highlight-type 'nick)
- ;; erc-notify.el allows you to keep track of the online status of
- ;; certain people.Use (require 'erc-notify) in your .emacs or M-x
- ;; load-library RET erc-notify RET to activate it.
- (require 'erc-notify)
- ;; Channel tracking is defined as global minor mode in
- ;; erc-track.el. Use `M-x erc-track-modified-channels-mode RET' to
- ;; activate it. This interactive function is auto-loaded, so you don't
- ;; need to (require 'erc-track).
- (require 'erc-track)
- (erc-track-mode 1)
- ;; Join #emacs and #emdummy. Then /leave #emdummy, but don't kill its
- ;; buffer. #emacs would continue showing up as #ema in the
- ;; modeline. Puzzled? Kill the #emdummy. buffer and #emacs will again
- ;; become #e. Also consider setting the variable
- ;; `erc-track-shorten-aggressively' to 'max, and looking at its
- ;; documentation.
- ;; using ProgrammableCompletion, in erc-pcomplete.el. To have
- ;; pcomplete work automatically, try this:
- (add-hook 'erc-mode-hook
- '(lambda ()
- (require 'erc-pcomplete)
- (pcomplete-erc-setup)
- (erc-completion-mode 1)))
- ;; Likewise, messages will land in the server buffer by default. To
- ;; cause new messages to automatically open up a query buffer with the
- ;; sender, add the following form to your startup files:
- (setq erc-auto-query t) ; open a query window when someone messages me
- ;; ERC Smiley mode is a tiny mode that uses `smiley-region', which is
- ;; defined in smiley.el, which is part of Oort Gnus. To enable it,
- ;; just add this to your ~/.emacs:
- (erc-smiley-mode 1)
- ;; define smilies for Gnus and Erc ;)
- (require 'smiley)
- (setq smiley-regexp-alist nil)
- (dolist (element '(("\\(:-?)\\)\\W" 1 "smile")
- ("\\(;-?)\\)\\W" 1 "blink")
- ("\\(:-?]\\)\\W" 1 "forced")
- ("\\(8-?)\\)\\W" 1 "braindamaged")
- ("\\(:-?|\\)\\W" 1 "indifferent")
- ("\\(:-/\\)\\W" 1 "wry")
- ("\\(:-?(\\)\\W" 1 "sad")
- ("\\(:-?{\\)\\W" 1 "frown")
- ("\\(X-?)\\)\\W" 1 "dead")
- ("\\((-?:\\)\\W" 1 "reverse-smile")
- ("\\(:-?D\\)\\W" 1 "grin")))
- (add-to-list 'smiley-regexp-alist element))
- ;; If you change the variable after having used the smileys, you need to
- ;; empty the cache and update it again. Usually this is not needed,
- ;; however.
- ;; (setq smiley-cached-regexp-alist nil)
- (smiley-update-cache)
- ;; And if you want other smileys, use `smiley-data-directory' to point
- ;; the smiley code at something else.
- (setq erc-default-coding-system '(chinese-iso-8bit . chinese-iso-8bit))
- ;; (setq erc-encoding-coding-alist '((".*" . chinese-iso-8bit)))
- ;;;;;;;; change two functions for non-ascii support
- (defun erc-parse-line-from-server (proc string)
- "Parse and act upon a complete line from a IRC server.
- PROC is the process (connection) from which STRING was received.
- PROCs process-buffer is current-buffer when this function is called."
- (unless (string= string "") ;; Ignore empty strings
- (setq string (erc-decode-coding-string string (cdr erc-default-coding-system)))
- (save-match-data
- (let ((posn (if (eq (aref string 0) ?:)
- (string-match " " string)
- 0))
- (msg (make-vector 32 nil))
- (n 2))
- (aset msg 1 (if (eq posn 0)
- erc-session-server
- (substring string 1 posn)))
- (aset msg 0 (let* ((bposn (string-match "[^ ]" string posn))
- (eposn (string-match " " string bposn)))
- (setq posn (and eposn
- (string-match "[^ ]" string eposn)))
- (substring string bposn eposn)))
- (while (and posn
- (not (eq (aref string posn) ?:)))
- (aset msg n (let* ((bposn posn)
- (eposn (string-match " " string bposn)))
- (setq posn (and eposn
- (string-match "[^ ]" string eposn)))
- (substring string bposn eposn)))
- (setq n (1+ n)))
- (if posn
- (aset msg n (substring string (1+ posn))))
- (if (member (aref msg 0) erc-prevent-duplicates)
- (progn
- (if (< (or
- (gethash (mapconcat 'identity msg "") erc-duplicates)
- 0)
- (- (erc-current-time) erc-duplicate-timeout))
- (erc-call-hooks proc msg))
- (puthash (mapconcat 'identity msg "")
- (erc-current-time)
- erc-duplicates))
- (erc-call-hooks proc msg))))))
- (defun erc-server-PRIVMSG-or-NOTICE (proc parsed)
- (let ((sender-spec (aref parsed 1))
- (cmd (aref parsed 0))
- (tgt (aref parsed 2))
- (msg (aref parsed 3)))
- (if (or (erc-ignored-user-p sender-spec)
- (erc-ignored-reply-p msg tgt proc))
- (when erc-minibuffer-ignored
- (message "Ignored %s from %s to %s" cmd sender-spec tgt))
- (let* ((sndr (erc-parse-user sender-spec))
- (nick (nth 0 sndr))
- (login (nth 1 sndr))
- (host (nth 2 sndr))
- (msgp (string= cmd "PRIVMSG"))
- (noticep (string= cmd "NOTICE"))
- ;; S.B. downcase *both* tgt and current nick
- (privp (erc-current-nick-p tgt))
- s buffer
- fnick
- ;; (msg (erc-decode-string-from-target msg (if privp sender-spec tgt)))
- )
- ;; (setf (aref parsed 3) msg)
- (setq buffer (erc-get-buffer (if privp nick tgt) proc))
- (when buffer
- (with-current-buffer buffer
- ;; update the chat partner info. Add to the list if private
- ;; message. We will accumulate private identities indefinitely
- ;; at this point.
- (if (erc-update-channel-member (if privp nick tgt) nick nick
- privp nil nil host login)
- (erc-update-channel-info-buffer (if privp nick tgt)))
- (setq fnick
- (apply erc-format-nick-function
- (assoc nick channel-members)))))
- (cond
- ((erc-is-message-ctcp-p msg)
- (setq s (if msgp
- (erc-process-ctcp-query proc parsed nick login host)
- (erc-process-ctcp-reply proc parsed nick login host
- (match-string 1 msg)))))
- (t
- (setcar last-peers nick)
- (setq s (erc-format-privmessage (or fnick nick) msg privp msgp))))
- (when s
- (when (and noticep privp erc-echo-notices-in-minibuffer-flag)
- (message "%s" (concat "NOTICE: " s)))
- (if (and noticep privp erc-echo-notices-in-current-buffer)
- (erc-display-message parsed nil 'active s)
- (erc-display-message parsed nil buffer s)))))))
复制代码
试试新的配制文件吧 ;) 这次大家满意了吧 ;;)
--
Q: How many mathematicians does it take to screw in a light bulb?
A: One. He gives it to six Californians, thereby reducing the problem
to the earlier joke. |
|