LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 3831|回复: 2

hihi 为了使用cvs版本的erc ;)

[复制链接]
发表于 2003-10-28 22:40:05 | 显示全部楼层 |阅读模式
既然官方的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里面加入:

  1. ;; To prevent ERC from loading at startup, you may use auto-load in
  2. ;; your ~/.emacs file. Here is an example:
  3. (autoload 'erc-select "erc" "IRC client." t)

  4. ;; This will add it to the Tools menu. It uses EasyMenu.
  5. (require 'easymenu)
  6. (easy-menu-add-item  nil '("tools")
  7.                      ["IRC" erc-select t])
复制代码

再创建一个~/.ercrc.el文件,内容如下:

  1. ;; Add dcc support
  2. (require 'erc-xdcc)

  3. ;; In order to use timestamps, you need to load the module, and
  4. ;; activate the global minor mode:
  5. (require 'erc-stamp)
  6. (erc-timestamp-mode 1)
  7. ;; This will add a timestamp to new lines if at least a minute has
  8. ;; past since the last timestamping.

  9. ;; I prefer the timestamps on the left, and on every line:
  10. (setq erc-timestamp-only-if-changed-flag nil
  11.       erc-insert-timestamp-function 'erc-insert-timestamp-left
  12.       erc-timestamp-format "[%H:%M] "
  13.       erc-fill-prefix "      + "
  14.       erc-fill-column 72)

  15. ;; ERC Highlighting primitives can be found in the module
  16. ;; 'erc-match. Use the following in your ~/.emacs to activate it.
  17. (require 'erc-match)
  18. (erc-match-mode 1)
  19. (setq erc-current-nick-highlight-type 'nick)

  20. ;; erc-notify.el allows you to keep track of the online status of
  21. ;; certain people.Use (require 'erc-notify) in your .emacs or M-x
  22. ;; load-library RET erc-notify RET to activate it.
  23. (require 'erc-notify)

  24. ;; Channel tracking is defined as global minor mode in
  25. ;; erc-track.el. Use `M-x erc-track-modified-channels-mode RET' to
  26. ;; activate it. This interactive function is auto-loaded, so you don't
  27. ;; need to (require 'erc-track).
  28. (require 'erc-track)
  29. (erc-track-mode 1)
  30. ;; Join #emacs and #emdummy. Then /leave #emdummy, but don't kill its
  31. ;; buffer. #emacs would continue showing up as #ema in the
  32. ;; modeline. Puzzled? Kill the #emdummy. buffer and #emacs will again
  33. ;; become #e. Also consider setting the variable
  34. ;; `erc-track-shorten-aggressively' to 'max, and looking at its
  35. ;; documentation.

  36. ;; using ProgrammableCompletion, in erc-pcomplete.el. To have
  37. ;; pcomplete work automatically, try this:
  38. (add-hook 'erc-mode-hook
  39.           '(lambda ()
  40.              (require 'erc-pcomplete)
  41.              (pcomplete-erc-setup)
  42.              (erc-completion-mode 1)))

  43. ;; Likewise, messages will land in the server buffer by default. To
  44. ;; cause new messages to automatically open up a query buffer with the
  45. ;; sender, add the following form to your startup files:
  46. (setq erc-auto-query t) ; open a query window when someone messages me

  47. ;; ERC Smiley mode is a tiny mode that uses `smiley-region', which is
  48. ;; defined in smiley.el, which is part of Oort Gnus. To enable it,
  49. ;; just add this to your ~/.emacs:

  50. (erc-smiley-mode 1)

  51. ;; define smilies for Gnus and Erc ;)
  52. (require 'smiley)
  53. (setq smiley-regexp-alist nil)
  54. (dolist (element '(("\\(:-?)\\)\\W" 1 "smile")
  55.                    ("\\(;-?)\\)\\W" 1 "blink")
  56.                    ("\\(:-?]\\)\\W" 1 "forced")
  57.                    ("\\(8-?)\\)\\W" 1 "braindamaged")
  58.                    ("\\(:-?|\\)\\W" 1 "indifferent")
  59.                    ("\\(:-/\\)\\W" 1 "wry")
  60.                    ("\\(:-?(\\)\\W" 1 "sad")
  61.                    ("\\(:-?{\\)\\W" 1 "frown")
  62.                    ("\\(X-?)\\)\\W" 1 "dead")
  63.                    ("\\((-?:\\)\\W" 1 "reverse-smile")
  64.                    ("\\(:-?D\\)\\W" 1 "grin")))
  65.   (add-to-list 'smiley-regexp-alist element))

  66. ;; If you change the variable after having used the smileys, you need to
  67. ;; empty the cache and update it again. Usually this is not needed,
  68. ;; however.

  69. ;; (setq smiley-cached-regexp-alist nil)
  70. (smiley-update-cache)


  71. ;; And if you want other smileys, use `smiley-data-directory' to point
  72. ;; the smiley code at something else.

  73. (setq erc-default-coding-system '(chinese-iso-8bit . chinese-iso-8bit))
  74. ;; (setq erc-encoding-coding-alist '((".*" . chinese-iso-8bit)))


  75. ;;;;;;;; change two functions for non-ascii support
  76. (defun erc-parse-line-from-server (proc string)
  77.   "Parse and act upon a complete line from a IRC server.
  78. PROC is the process (connection) from which STRING was received.
  79. PROCs process-buffer is current-buffer when this function is called."
  80.   (unless (string= string "") ;; Ignore empty strings
  81.     (setq string (erc-decode-coding-string string (cdr erc-default-coding-system)))
  82.     (save-match-data
  83.       (let ((posn (if (eq (aref string 0) ?:)
  84.                       (string-match " " string)
  85.                     0))
  86.             (msg (make-vector 32 nil))
  87.             (n 2))
  88.         (aset msg 1 (if (eq posn 0)
  89.                         erc-session-server
  90.                       (substring string 1 posn)))

  91.         (aset msg 0 (let* ((bposn (string-match "[^ ]" string posn))
  92.                            (eposn (string-match " " string bposn)))
  93.                       (setq posn (and eposn
  94.                                       (string-match "[^ ]" string eposn)))
  95.                       (substring string bposn eposn)))

  96.         (while (and posn
  97.                     (not (eq (aref string posn) ?:)))
  98.           (aset msg n (let* ((bposn posn)
  99.                              (eposn (string-match " " string bposn)))
  100.                         (setq posn (and eposn
  101.                                         (string-match "[^ ]" string eposn)))
  102.                         (substring string bposn eposn)))
  103.           (setq n (1+ n)))
  104.         (if posn
  105.             (aset msg n (substring string (1+ posn))))
  106.         (if (member (aref msg 0) erc-prevent-duplicates)
  107.             (progn
  108.               (if (< (or
  109.                       (gethash (mapconcat 'identity msg "") erc-duplicates)
  110.                       0)
  111.                      (- (erc-current-time) erc-duplicate-timeout))
  112.                   (erc-call-hooks proc msg))
  113.               (puthash (mapconcat 'identity msg "")
  114.                        (erc-current-time)
  115.                        erc-duplicates))
  116.           (erc-call-hooks proc msg))))))


  117. (defun erc-server-PRIVMSG-or-NOTICE (proc parsed)
  118.   (let ((sender-spec (aref parsed 1))
  119.         (cmd (aref parsed 0))
  120.         (tgt (aref parsed 2))
  121.         (msg (aref parsed 3)))
  122.     (if (or (erc-ignored-user-p sender-spec)
  123.             (erc-ignored-reply-p msg tgt proc))
  124.         (when erc-minibuffer-ignored
  125.           (message "Ignored %s from %s to %s" cmd sender-spec tgt))
  126.       (let* ((sndr (erc-parse-user sender-spec))
  127.              (nick (nth 0 sndr))
  128.              (login (nth 1 sndr))
  129.              (host (nth 2 sndr))
  130.              (msgp (string= cmd "PRIVMSG"))
  131.              (noticep (string= cmd "NOTICE"))
  132.              ;; S.B. downcase *both* tgt and current nick
  133.              (privp (erc-current-nick-p tgt))
  134.              s buffer
  135.              fnick
  136.              ;; (msg (erc-decode-string-from-target msg (if privp sender-spec tgt)))
  137.              )
  138.         ;; (setf (aref parsed 3) msg)
  139.         (setq buffer (erc-get-buffer (if privp nick tgt) proc))
  140.         (when buffer
  141.           (with-current-buffer buffer
  142.             ;; update the chat partner info.  Add to the list if private
  143.             ;; message.         We will accumulate private identities indefinitely
  144.             ;; at this point.
  145.             (if (erc-update-channel-member (if privp nick tgt) nick nick
  146.                                            privp nil nil host login)
  147.                 (erc-update-channel-info-buffer (if privp nick tgt)))
  148.             (setq fnick
  149.                   (apply erc-format-nick-function
  150.                          (assoc nick channel-members)))))
  151.         (cond
  152.          ((erc-is-message-ctcp-p msg)
  153.           (setq s (if msgp
  154.                       (erc-process-ctcp-query proc parsed nick login host)
  155.                     (erc-process-ctcp-reply proc parsed nick login host
  156.                                             (match-string 1 msg)))))
  157.          (t
  158.           (setcar last-peers nick)
  159.           (setq s (erc-format-privmessage (or fnick nick) msg privp msgp))))
  160.         (when s
  161.           (when (and noticep privp erc-echo-notices-in-minibuffer-flag)
  162.             (message "%s" (concat "NOTICE: " s)))
  163.           (if (and noticep privp erc-echo-notices-in-current-buffer)
  164.               (erc-display-message parsed nil 'active s)
  165.             (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.
发表于 2003-10-28 22:48:08 | 显示全部楼层
我的还没有配置好呢!!!
 楼主| 发表于 2003-11-10 21:17:11 | 显示全部楼层

问题修正!

~/.emacs 里面部分修改如下

  1. ;; To prevent ERC from loading at startup, you may use auto-load in
  2. ;; your ~/.emacs file. Here is an example:
  3. (autoload 'erc-select "erc" "IRC client." t)
  4.                                                                                 
  5. ;; This will add it to the Tools menu. It uses EasyMenu.
  6. (require 'easymenu)
  7. (easy-menu-add-item  nil '("tools")
  8.                      ["IRC" erc-select t])
  9.                                                                                 
  10. ;; erc-auto-join list
  11. (setq erc-autojoin-channels-alist '(("irc.linuxfans.org" "#Debian")))
复制代码

~/.ercrc.el 内容如下

  1. ;; Add dcc support
  2. (require 'erc-xdcc)

  3. ;; In order to use timestamps, you need to load the module, and
  4. ;; activate the global minor mode:
  5. (require 'erc-stamp)
  6. (erc-timestamp-mode 1)
  7. ;; This will add a timestamp to new lines if at least a minute has
  8. ;; past since the last timestamping.

  9. ;; I prefer the timestamps on the left, and on every line:
  10. (setq erc-timestamp-only-if-changed-flag nil
  11.       erc-insert-timestamp-function 'erc-insert-timestamp-left
  12.       erc-timestamp-format "[%H:%M] "
  13.       erc-fill-prefix "      + "
  14.       erc-fill-column 72)

  15. ;; ERC Highlighting primitives can be found in the module
  16. ;; 'erc-match. Use the following in your ~/.emacs to activate it.
  17. (require 'erc-match)
  18. (erc-match-mode 1)
  19. (setq erc-current-nick-highlight-type 'nick)

  20. ;; erc-notify.el allows you to keep track of the online status of
  21. ;; certain people.Use (require 'erc-notify) in your .emacs or M-x
  22. ;; load-library RET erc-notify RET to activate it.
  23. (require 'erc-notify)

  24. ;; Channel tracking is defined as global minor mode in
  25. ;; erc-track.el. Use `M-x erc-track-modified-channels-mode RET' to
  26. ;; activate it. This interactive function is auto-loaded, so you don't
  27. ;; need to (require 'erc-track).
  28. (require 'erc-track)
  29. (erc-track-mode 1)
  30. ;; Join #emacs and #emdummy. Then /leave #emdummy, but don't kill its
  31. ;; buffer. #emacs would continue showing up as #ema in the
  32. ;; modeline. Puzzled? Kill the #emdummy. buffer and #emacs will again
  33. ;; become #e. Also consider setting the variable
  34. ;; `erc-track-shorten-aggressively' to 'max, and looking at its
  35. ;; documentation.

  36. ;; using ProgrammableCompletion, in erc-pcomplete.el. To have
  37. ;; pcomplete work automatically, try this:
  38. (add-hook 'erc-mode-hook
  39.           '(lambda ()
  40.              (require 'erc-pcomplete)
  41.              (pcomplete-erc-setup)
  42.              (erc-completion-mode 1)))

  43. ;; Likewise, messages will land in the server buffer by default. To
  44. ;; cause new messages to automatically open up a query buffer with the
  45. ;; sender, add the following form to your startup files:
  46. (setq erc-auto-query t) ; open a query window when someone messages me

  47. ;; ERC Smiley mode is a tiny mode that uses `smiley-region', which is
  48. ;; defined in smiley.el, which is part of Oort Gnus. To enable it,
  49. ;; just add this to your ~/.emacs:

  50. (erc-smiley-mode 1)

  51. ;; define smilies for Gnus and Erc ;)
  52. (require 'smiley)
  53. (setq smiley-regexp-alist nil)
  54. (dolist (element '(("\\(:-?)\\)\\W" 1 "smile")
  55.                    ("\\(;-?)\\)\\W" 1 "blink")
  56.                    ("\\(:-?]\\)\\W" 1 "forced")
  57.                    ("\\(8-?)\\)\\W" 1 "braindamaged")
  58.                    ("\\(:-?|\\)\\W" 1 "indifferent")
  59.                    ("\\(:-/\\)\\W" 1 "wry")
  60.                    ("\\(:-?(\\)\\W" 1 "sad")
  61.                    ("\\(:-?{\\)\\W" 1 "frown")
  62.                    ("\\(X-?)\\)\\W" 1 "dead")
  63.                    ("\\((-?:\\)\\W" 1 "reverse-smile")
  64.                    ("\\(:-?D\\)\\W" 1 "grin")))
  65.   (add-to-list 'smiley-regexp-alist element))

  66. ;; If you change the variable after having used the smileys, you need to
  67. ;; empty the cache and update it again. Usually this is not needed,
  68. ;; however.

  69. ;; (setq smiley-cached-regexp-alist nil)
  70. (smiley-update-cache)


  71. ;; And if you want other smileys, use `smiley-data-directory' to point
  72. ;; the smiley code at something else.

  73. (setq erc-default-coding-system '(chinese-iso-8bit . chinese-iso-8bit))
  74. ;; (setq erc-encoding-coding-alist '((".*" . chinese-iso-8bit)))


  75. ;;;;;;;; change two functions for non-ascii support
  76. (defun erc-parse-line-from-server (proc string)
  77.   "Parse and act upon a complete line from a IRC server.
  78. PROC is the process (connection) from which STRING was received.
  79. PROCs process-buffer is current-buffer when this function is called."
  80.   (unless (string= string "") ;; Ignore empty strings
  81.     (setq string (if (string-match "\\(#.*? \\)" string)
  82.                      (erc-decode-string-from-target string (match-string 1 string ))
  83.                    (erc-decode-coding-string string (cdr erc-default-coding-system))))
  84.     (save-match-data
  85.       (let ((posn (if (eq (aref string 0) ?:)
  86.                       (string-match " " string)
  87.                     0))
  88.             (msg (make-vector 32 nil))
  89.             (n 2))
  90.         (aset msg 1 (if (eq posn 0)
  91.                         erc-session-server
  92.                       (substring string 1 posn)))

  93.         (aset msg 0 (let* ((bposn (string-match "[^ ]" string posn))
  94.                            (eposn (string-match " " string bposn)))
  95.                       (setq posn (and eposn
  96.                                       (string-match "[^ ]" string eposn)))
  97.                       (substring string bposn eposn)))

  98.         (while (and posn
  99.                     (not (eq (aref string posn) ?:)))
  100.           (aset msg n (let* ((bposn posn)
  101.                              (eposn (string-match " " string bposn)))
  102.                         (setq posn (and eposn
  103.                                         (string-match "[^ ]" string eposn)))
  104.                         (substring string bposn eposn)))
  105.           (setq n (1+ n)))
  106.         (if posn
  107.             (aset msg n (substring string (1+ posn))))
  108.         (if (member (aref msg 0) erc-prevent-duplicates)
  109.             (progn
  110.               (if (< (or
  111.                       (gethash (mapconcat 'identity msg "") erc-duplicates)
  112.                       0)
  113.                      (- (erc-current-time) erc-duplicate-timeout))
  114.                   (erc-call-hooks proc msg))
  115.               (puthash (mapconcat 'identity msg "")
  116.                        (erc-current-time)
  117.                        erc-duplicates))
  118.           (erc-call-hooks proc msg))))))


  119. (defun erc-server-PRIVMSG-or-NOTICE (proc parsed)
  120.   (let ((sender-spec (aref parsed 1))
  121.         (cmd (aref parsed 0))
  122.         (tgt (aref parsed 2))
  123.         (msg (aref parsed 3)))
  124.     (if (or (erc-ignored-user-p sender-spec)
  125.             (erc-ignored-reply-p msg tgt proc))
  126.         (when erc-minibuffer-ignored
  127.           (message "Ignored %s from %s to %s" cmd sender-spec tgt))
  128.       (let* ((sndr (erc-parse-user sender-spec))
  129.              (nick (nth 0 sndr))
  130.              (login (nth 1 sndr))
  131.              (host (nth 2 sndr))
  132.              (msgp (string= cmd "PRIVMSG"))
  133.              (noticep (string= cmd "NOTICE"))
  134.              ;; S.B. downcase *both* tgt and current nick
  135.              (privp (erc-current-nick-p tgt))
  136.              s buffer
  137.              fnick
  138.              ;; (msg (erc-decode-string-from-target msg (if privp sender-spec tgt)))
  139.              )
  140.         ;; (setf (aref parsed 3) msg)
  141.         (setq buffer (erc-get-buffer (if privp nick tgt) proc))
  142.         (when buffer
  143.           (with-current-buffer buffer
  144.             ;; update the chat partner info.  Add to the list if private
  145.             ;; message.         We will accumulate private identities indefinitely
  146.             ;; at this point.
  147.             (if (erc-update-channel-member (if privp nick tgt) nick nick
  148.                                            privp nil nil host login)
  149.                 (erc-update-channel-info-buffer (if privp nick tgt)))
  150.             (setq fnick
  151.                   (apply erc-format-nick-function
  152.                          (assoc nick channel-members)))))
  153.         (cond
  154.          ((erc-is-message-ctcp-p msg)
  155.           (setq s (if msgp
  156.                       (erc-process-ctcp-query proc parsed nick login host)
  157.                     (erc-process-ctcp-reply proc parsed nick login host
  158.                                             (match-string 1 msg)))))
  159.          (t
  160.           (setcar last-peers nick)
  161.           (setq s (erc-format-privmessage (or fnick nick) msg privp msgp))))
  162.         (when s
  163.           (when (and noticep privp erc-echo-notices-in-minibuffer-flag)
  164.             (message "%s" (concat "NOTICE: " s)))
  165.           (if (and noticep privp erc-echo-notices-in-current-buffer)
  166.               (erc-display-message parsed nil 'active s)
  167.             (erc-display-message parsed nil buffer s)))))))

  168. (defun erc-server-TOPIC (proc parsed)
  169.   (let* ((sender-spec (aref parsed 1))
  170.          (ch (aref parsed 2))
  171.          (topic (erc-trim-string (aref parsed 3)))
  172.          (sndr (erc-parse-user sender-spec))
  173.          (nick (nth 0 sndr))
  174.          (login (nth 1 sndr))
  175.          (host (nth 2 sndr))
  176.          (time (format-time-string "%T %m/%d/%y" (current-time))))
  177.     (erc-update-channel-member ch nick nick nil nil nil host login)
  178.     (erc-update-channel-topic ch (format "%s\C-c (%s, %s)" topic nick time))
  179.     (erc-update-channel-info-buffer ch)
  180.     (unless (member "TOPIC" erc-hide-list)
  181.       (erc-display-message
  182.        parsed 'notice (erc-get-buffer ch proc)
  183.        'TOPIC ?n nick ?u login ?h host ?c ch ?T topic))))
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表