作者 Anonymous [lisp] 2010-11-06 22:04 (点击下载)

  1. ;;; erc-nick-notify.el --- Notify popup for ERC
  2.  
  3. ;; Filename: erc-nick-notify.el
  4. ;; Description: Notify popup for ERC
  5. ;; Author: Andy Stewart lazycat.manatee@gmail.com
  6. ;; Maintainer: Andy Stewart lazycat.manatee@gmail.com
  7. ;; Copyright (C) 2008, 2009, Andy Stewart, all rights reserved.
  8. ;; Created: 2008-12-04 12:47:28
  9. ;; Version: 0.2.1
  10. ;; Last-Updated: 2009-01-31 10:47:32
  11. ;; By: Andy Stewart
  12. ;; URL: http://www.emacswiki.org/emacs/download/erc-nick-notify.el
  13. ;; Keywords: erc, notify
  14. ;; Compatibility: GNU Emacs 23.0.60.1
  15. ;;
  16. ;; Features that might be required by this library:
  17. ;;
  18. ;; `erc'
  19. ;;
  20.  
  21. ;;; This file is NOT part of GNU Emacs
  22.  
  23. ;;; License
  24. ;;
  25. ;; This program is free software; you can redistribute it and/or modify
  26. ;; it under the terms of the GNU General Public License as published by
  27. ;; the Free Software Foundation; either version 3, or (at your option)
  28. ;; any later version.
  29.  
  30. ;; This program is distributed in the hope that it will be useful,
  31. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. ;; GNU General Public License for more details.
  34.  
  35. ;; You should have received a copy of the GNU General Public License
  36. ;; along with this program; see the file COPYING. If not, write to
  37. ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  38. ;; Floor, Boston, MA 02110-1301, USA.
  39.  
  40. ;;; Commentary:
  41. ;;
  42. ;; Notify popup for ERC
  43. ;;
  44. ;; This extension use `notify-send' for notify.
  45. ;; So make you have install `notify-send' in your system.
  46. ;;
  47.  
  48. ;;; Installation:
  49. ;;
  50. ;; Put erc-nick-notify.el to your load-path.
  51. ;; The load-path is usually ~/elisp/.
  52. ;; It's set in your ~/.emacs like this:
  53. ;; (add-to-list 'load-path (expand-file-name "~/elisp"))
  54. ;;
  55. ;; And the following to your ~/.emacs startup file.
  56. ;;
  57. ;; (require 'erc-nick-notify)
  58. ;;
  59. ;; No need more.
  60.  
  61. ;;; Customize:
  62. ;;
  63. ;; `erc-nick-notify-delay'
  64. ;; The delay time that between two messages.
  65. ;; `erc-nick-notify-cmd'
  66. ;; The command that use for notify.
  67. ;; `erc-nick-notify-icon'
  68. ;; The file name of icon display.
  69. ;; `erc-nick-notify-timeout'
  70. ;; The timeout in milliseconds at which to expire the notification.
  71. ;; `erc-nick-notify-urgency'
  72. ;; The urgency level.
  73. ;; `erc-nick-notify-category'
  74. ;; The notification category.
  75. ;;
  76. ;; All of the above can be customize by:
  77. ;; M-x customize-group RET erc-nick-notify RET
  78. ;;
  79.  
  80. ;;; Change log:
  81. ;;
  82. ;; 2009/01/31
  83. ;; Fix doc.
  84. ;;
  85. ;; 2008/12/21
  86. ;; Fix `void-variable' bug.
  87. ;;
  88. ;; 2008/12/08
  89. ;; Add customize support.
  90. ;;
  91. ;; 2008/12/04
  92. ;; First released.
  93. ;;
  94.  
  95. ;;; Acknowledgements:
  96. ;;
  97. ;;
  98. ;;
  99.  
  100. ;;; TODO
  101. ;;
  102. ;;
  103. ;;
  104.  
  105. ;;; Require
  106. (require 'erc)
  107.  
  108. ;;; Code:
  109.  
  110. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  111. (defgroup erc-nick-notify nil
  112. "Notify popup for ERC."
  113. :group 'erc)
  114.  
  115. (defcustom erc-nick-notify-delay '(0 5 0)
  116. "The delay time that between two message.
  117. Default is 5 minutes."
  118. :type 'list
  119. :group 'erc-nick-notify)
  120.  
  121. (defcustom erc-nick-notify-cmd "notify-send"
  122. "The command that use for notify."
  123. :type 'string
  124. :group 'erc-nick-notify)
  125.  
  126. (defcustom erc-nick-notify-icon "/usr/share/pixmaps/pidgin/protocols/22/google-talk.png"
  127. "Specifies an icon filename or stock icon to display."
  128. :type 'string
  129. :group 'erc-nick-notify)
  130.  
  131. (defcustom erc-nick-notify-timeout 15000
  132. "Specifies the timeout in milliseconds at which to expire the notification."
  133. :type 'number
  134. :group 'erc-nick-notify)
  135.  
  136. (defcustom erc-nick-notify-urgency "low"
  137. "Specifies the urgency level (low, normal, critical)."
  138. :type 'string
  139. :group 'erc-nick-notify)
  140.  
  141. (defcustom erc-nick-notify-category "im.received"
  142. "Specifies the notification category: im, im.errors, im.received"
  143. :type 'string
  144. :group 'erc-nick-notify)
  145.  
  146. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Variable ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  147. (defvar erc-nick-notify-last '(0 0 0)
  148. "The last time that receive message.")
  149.  
  150. (defvar erc-privmsg-notify-last '(0 0 0)
  151. "The last time that receive message.")
  152.  
  153. (defvar erc-nick-notify-buffer nil
  154. "The buffer name of last notify me.")
  155.  
  156. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  157. (defun erc-nick-notify-jump-last-channel ()
  158. "Jump to last channel that notify me."
  159. (interactive)
  160. (if erc-nick-notify-buffer
  161. (switch-to-buffer erc-nick-notify-buffer)
  162. (message "Nobody notify you in IRC.")))
  163.  
  164.  
  165. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  166. (defun erc-nick-notify ()
  167. "Notify me when my nick show up.
  168. This function should be in the insert-post-hook."
  169. (let ((now (current-time)))
  170. (when (time-less-p erc-nick-notify-delay
  171. (time-since erc-nick-notify-last))
  172. (setq erc-nick-notify-last now)
  173. (goto-char (point-min))
  174. (when (re-search-forward
  175. (concat "\\("
  176. "\\(<\\([^>]*\\)>\\)" ; <someone> "<nickname>"
  177. "\\|" ;; 匹配只以《一个》*开头加一空格再接任意个非空字母开头(nick) 可能有bug "* nickname"
  178. "\\([^\\*]\\* \\([^\\(" (regexp-quote (erc-current-nick))"\\)][^ ]*\\)\\)"
  179. ;; todo 不匹配自己说的话 或者 /me 正则表达式不行?
  180. ;; "\\|"
  181. ;; "\\(\\* " (regexp-quote (erc-current-nick)) "\\)"
  182. "\\|"
  183. "\\(-\\([^-]*\\)-\\)" ;匹配 notice 信息中本昵称 "-nickname-"
  184. "\\)" ;; 此()匹配各种类发消息的nickname
  185. "\\(.*" (regexp-quote (erc-current-nick)) ".*\\)")
  186. nil t)
  187. (let ((msg (concat
  188. (when (> (length (match-string-no-properties 3)) 0) ;channel信息中send nick
  189. (concat "<b>&lt;" (match-string-no-properties 3)
  190. "&gt;</b> "))
  191. (when (> (length (match-string-no-properties 5)) 0) ; /me 信息包含的send nick
  192. (concat "<b>&lt;\*" (match-string-no-properties 5)
  193. "&gt;</b> "))
  194. (when (> (length (match-string-no-properties 6)) 0) ; /notice 信息包含的send nick
  195. (concat "<b>" (match-string-no-properties 6)
  196. "</b> "))
  197. ;;(match-string-no-properties 8))))
  198. (replace-regexp-in-string "<" "&lt;"
  199. (replace-regexp-in-string "&" "&amp;" (match-string-no-properties 8)))))) ;; 替换包括<和 &的语句。 >显示正常。 NOTE:必须先替换 & 再替换 <,否则 &lt;里的&会被替换成&amp; 不能正常显示
  200. (setq erc-nick-notify-buffer (buffer-name))
  201. (start-process-shell-command "nicknotify" nil
  202. (concat erc-nick-notify-cmd
  203. " -h " "int:x:1233"
  204. " -h " "int:y:788"
  205. " -i " erc-nick-notify-icon
  206. " -t " (int-to-string
  207. erc-nick-notify-timeout)
  208. " -u " erc-nick-notify-urgency
  209. " -c " erc-nick-notify-category
  210. " -- "
  211. " \"" erc-nick-notify-buffer "\""
  212. ;; " \""
  213. ;; (if (boundp 'msg)
  214. ;; msg "")
  215. ;; "\"")))))))
  216. " \"<span color='RoyalBlue'>"
  217. (if (boundp 'msg)
  218. msg "")
  219. "</span>\"")))))))
  220.  
  221. ;; Add `erc-nick-notify' to `erc-insert-post-hook'
  222. (add-hook 'erc-insert-post-hook 'erc-nick-notify)
  223.  
  224. ;; PRIVMSG Messages Pop up
  225. (defun my-erc-page-me-PRIVMSG (proc parsed)
  226. (let ((now (current-time))
  227. (nick (erc-extract-nick (erc-response.sender parsed)))
  228. (target (car (erc-response.command-args parsed)))
  229. (msg (replace-regexp-in-string "<" "&lt;"
  230. (replace-regexp-in-string "&" "&amp;"
  231. (erc-response.contents parsed)))))
  232. (when (and (erc-current-nick-p target)
  233. (not (erc-is-message-ctcp-and-not-action-p msg))
  234. (time-less-p erc-nick-notify-delay
  235. (time-since erc-privmsg-notify-last))
  236. ; (my-erc-page-allowed nick)
  237. )
  238. (setq erc-privmsg-notify-last now)
  239. (start-process-shell-command "privnotify" nil
  240. (concat erc-nick-notify-cmd
  241. " -h " "int:x:1233"
  242. " -h " "int:y:788"
  243. " -i " erc-nick-notify-icon
  244. " -t " (int-to-string
  245. erc-nick-notify-timeout)
  246. " -u " erc-nick-notify-urgency
  247. " -c " erc-nick-notify-category
  248. " -- "
  249. " \"" "<" nick ">" " says to you:" "\""
  250. " \"<i><span color='red'>"
  251. (if (boundp 'msg)
  252. msg "")
  253. "</span></i>\""))
  254. nil)))
  255. (add-hook 'erc-server-PRIVMSG-functions 'my-erc-page-me-PRIVMSG)
  256.  
  257.  
  258. (provide 'erc-nick-notify)
  259.  
  260. ;;; erc-nick-notify.el ends here
  261. ;;; LocalWords: erc cmd im msg lt

提交下面的校正或者修改. (点击这里开始一个新的帖子)
姓名: 在 cookie 中记住我的名字

屏幕抓图:(jpeg 或 png)