erc-match.el 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. ;;; erc-match.el --- Highlight messages matching certain regexps
  2. ;; Copyright (C) 2002-2012 Free Software Foundation, Inc.
  3. ;; Author: Andreas Fuchs <asf@void.at>
  4. ;; Keywords: comm, faces
  5. ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcMatch
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; This file includes stuff to work with pattern matching in ERC. If
  19. ;; you were used to customizing erc-fools, erc-keywords, erc-pals,
  20. ;; erc-dangerous-hosts and the like, this file contains these
  21. ;; customizable variables.
  22. ;; Usage:
  23. ;; Put (erc-match-mode 1) into your ~/.emacs file.
  24. ;;; Code:
  25. (require 'erc)
  26. (eval-when-compile (require 'cl))
  27. ;; Customization:
  28. (defgroup erc-match nil
  29. "Keyword and Friend/Foe/... recognition.
  30. Group containing all things concerning pattern matching in ERC
  31. messages."
  32. :group 'erc)
  33. ;;;###autoload (autoload 'erc-match-mode "erc-match")
  34. (define-erc-module match nil
  35. "This mode checks whether messages match certain patterns. If so,
  36. they are hidden or highlighted. This is controlled via the variables
  37. `erc-pals', `erc-fools', `erc-keywords', `erc-dangerous-hosts', and
  38. `erc-current-nick-highlight-type'. For all these highlighting types,
  39. you can decide whether the entire message or only the sending nick is
  40. highlighted."
  41. ((add-hook 'erc-insert-modify-hook 'erc-match-message 'append))
  42. ((remove-hook 'erc-insert-modify-hook 'erc-match-message)))
  43. ;; Remaining customizations
  44. (defcustom erc-pals nil
  45. "List of pals on IRC."
  46. :group 'erc-match
  47. :type '(repeat regexp))
  48. (defcustom erc-fools nil
  49. "List of fools on IRC."
  50. :group 'erc-match
  51. :type '(repeat regexp))
  52. (defcustom erc-keywords nil
  53. "List of keywords to highlight in all incoming messages.
  54. Each entry in the list is either a regexp, or a cons cell with the
  55. regexp in the car and the face to use in the cdr. If no face is
  56. specified, `erc-keyword-face' is used."
  57. :group 'erc-match
  58. :type '(repeat (choice regexp
  59. (list regexp face))))
  60. (defcustom erc-dangerous-hosts nil
  61. "List of regexps for hosts to highlight.
  62. Useful to mark nicks from dangerous hosts."
  63. :group 'erc-match
  64. :type '(repeat regexp))
  65. (defcustom erc-current-nick-highlight-type 'keyword
  66. "*Determines how to highlight text in which your current nickname appears
  67. \(does not apply to text sent by you\).
  68. The following values are allowed:
  69. nil - do not highlight the message at all
  70. 'keyword - highlight all instances of current nickname in message
  71. 'nick - highlight the nick of the user who typed your nickname
  72. 'nick-or-keyword - highlight the nick of the user who typed your nickname,
  73. or all instances of the current nickname if there was
  74. no sending user
  75. 'all - highlight the entire message where current nickname occurs
  76. Any other value disables highlighting of current nickname altogether."
  77. :group 'erc-match
  78. :type '(choice (const nil)
  79. (const nick)
  80. (const keyword)
  81. (const nick-or-keyword)
  82. (const all)))
  83. (defcustom erc-pal-highlight-type 'nick
  84. "*Determines how to highlight messages by pals.
  85. See `erc-pals'.
  86. The following values are allowed:
  87. nil - do not highlight the message at all
  88. 'nick - highlight pal's nickname only
  89. 'all - highlight the entire message from pal
  90. Any other value disables pal highlighting altogether."
  91. :group 'erc-match
  92. :type '(choice (const nil)
  93. (const nick)
  94. (const all)))
  95. (defcustom erc-fool-highlight-type 'nick
  96. "*Determines how to highlight messages by fools.
  97. See `erc-fools'.
  98. The following values are allowed:
  99. nil - do not highlight the message at all
  100. 'nick - highlight fool's nickname only
  101. 'all - highlight the entire message from fool
  102. Any other value disables fool highlighting altogether."
  103. :group 'erc-match
  104. :type '(choice (const nil)
  105. (const nick)
  106. (const all)))
  107. (defcustom erc-keyword-highlight-type 'keyword
  108. "*Determines how to highlight messages containing keywords.
  109. See variable `erc-keywords'.
  110. The following values are allowed:
  111. 'keyword - highlight keyword only
  112. 'all - highlight the entire message containing keyword
  113. Any other value disables keyword highlighting altogether."
  114. :group 'erc-match
  115. :type '(choice (const nil)
  116. (const keyword)
  117. (const all)))
  118. (defcustom erc-dangerous-host-highlight-type 'nick
  119. "*Determines how to highlight messages by nicks from dangerous-hosts.
  120. See `erc-dangerous-hosts'.
  121. The following values are allowed:
  122. 'nick - highlight nick from dangerous-host only
  123. 'all - highlight the entire message from dangerous-host
  124. Any other value disables dangerous-host highlighting altogether."
  125. :group 'erc-match
  126. :type '(choice (const nil)
  127. (const nick)
  128. (const all)))
  129. (defcustom erc-log-matches-types-alist '((keyword . "ERC Keywords"))
  130. "Alist telling ERC where to log which match types.
  131. Valid match type keys are:
  132. - keyword
  133. - pal
  134. - dangerous-host
  135. - fool
  136. - current-nick
  137. The other element of each cons pair in this list is the buffer name to
  138. use for the logged message."
  139. :group 'erc-match
  140. :type '(repeat (cons (choice :tag "Key"
  141. (const keyword)
  142. (const pal)
  143. (const dangerous-host)
  144. (const fool)
  145. (const current-nick))
  146. (string :tag "Buffer name"))))
  147. (defcustom erc-log-matches-flag 'away
  148. "Flag specifying when matched message logging should happen.
  149. When nil, don't log any matched messages.
  150. When t, log messages.
  151. When 'away, log messages only when away."
  152. :group 'erc-match
  153. :type '(choice (const nil)
  154. (const away)
  155. (const t)))
  156. (defcustom erc-log-match-format "%t<%n:%c> %m"
  157. "Format for matched Messages.
  158. This variable specifies how messages in the corresponding log buffers will
  159. be formatted. The various format specs are:
  160. %t Timestamp (uses `erc-timestamp-format' if non-nil or \"[%Y-%m-%d %H:%M] \")
  161. %n Nickname of sender
  162. %u Nickname!user@host of sender
  163. %c Channel in which this was received
  164. %m Message"
  165. :group 'erc-match
  166. :type 'string)
  167. (defcustom erc-beep-match-types '(current-nick)
  168. "Types of matches to beep for when a match occurs.
  169. The function `erc-beep-on-match' needs to be added to `erc-text-matched-hook'
  170. for beeping to work."
  171. :group 'erc-match
  172. :type '(choice (repeat :tag "Beep on match" (choice
  173. (const current-nick)
  174. (const keyword)
  175. (const pal)
  176. (const dangerous-host)
  177. (const fool)))
  178. (const :tag "Don't beep" nil)))
  179. (defcustom erc-text-matched-hook '(erc-log-matches)
  180. "Hook run when text matches a given match-type.
  181. Functions in this hook are passed as arguments:
  182. \(match-type nick!user@host message) where MATCH-TYPE is a symbol of:
  183. current-nick, keyword, pal, dangerous-host, fool"
  184. :options '(erc-log-matches erc-hide-fools erc-beep-on-match)
  185. :group 'erc-match
  186. :type 'hook)
  187. ;; Internal variables:
  188. ;; This is exactly the same as erc-button-syntax-table. Should we
  189. ;; just put it in erc.el
  190. (defvar erc-match-syntax-table
  191. (let ((table (make-syntax-table)))
  192. (modify-syntax-entry ?\( "w" table)
  193. (modify-syntax-entry ?\) "w" table)
  194. (modify-syntax-entry ?\[ "w" table)
  195. (modify-syntax-entry ?\] "w" table)
  196. (modify-syntax-entry ?\{ "w" table)
  197. (modify-syntax-entry ?\} "w" table)
  198. (modify-syntax-entry ?` "w" table)
  199. (modify-syntax-entry ?' "w" table)
  200. (modify-syntax-entry ?^ "w" table)
  201. (modify-syntax-entry ?- "w" table)
  202. (modify-syntax-entry ?_ "w" table)
  203. (modify-syntax-entry ?| "w" table)
  204. (modify-syntax-entry ?\\ "w" table)
  205. table)
  206. "Syntax table used when highlighting messages.
  207. This syntax table should make all the valid nick characters word
  208. constituents.")
  209. ;; Faces:
  210. (defface erc-current-nick-face '((t (:bold t :foreground "DarkTurquoise")))
  211. "ERC face for occurrences of your current nickname."
  212. :group 'erc-faces)
  213. (defface erc-dangerous-host-face '((t (:foreground "red")))
  214. "ERC face for people on dangerous hosts.
  215. See `erc-dangerous-hosts'."
  216. :group 'erc-faces)
  217. (defface erc-pal-face '((t (:bold t :foreground "Magenta")))
  218. "ERC face for your pals.
  219. See `erc-pals'."
  220. :group 'erc-faces)
  221. (defface erc-fool-face '((t (:foreground "dim gray")))
  222. "ERC face for fools on the channel.
  223. See `erc-fools'."
  224. :group 'erc-faces)
  225. (defface erc-keyword-face '((t (:bold t :foreground "pale green")))
  226. "ERC face for your keywords.
  227. Note that this is the default face to use if
  228. `erc-keywords' does not specify another."
  229. :group 'erc-faces)
  230. ;; Functions:
  231. (defun erc-add-entry-to-list (list prompt &optional completions)
  232. "Add an entry interactively to a list.
  233. LIST must be passed as a symbol
  234. The query happens using PROMPT.
  235. Completion is performed on the optional alist COMPLETIONS."
  236. (let ((entry (completing-read
  237. prompt
  238. completions
  239. (lambda (x)
  240. (not (erc-member-ignore-case (car x) (symbol-value list)))))))
  241. (if (erc-member-ignore-case entry (symbol-value list))
  242. (error "\"%s\" is already on the list" entry)
  243. (set list (cons entry (symbol-value list))))))
  244. (defun erc-remove-entry-from-list (list prompt)
  245. "Remove an entry interactively from a list.
  246. LIST must be passed as a symbol.
  247. The elements of LIST can be strings, or cons cells where the
  248. car is the string."
  249. (let* ((alist (mapcar (lambda (x)
  250. (if (listp x)
  251. x
  252. (list x)))
  253. (symbol-value list)))
  254. (entry (completing-read
  255. prompt
  256. alist
  257. nil
  258. t)))
  259. (if (erc-member-ignore-case entry (symbol-value list))
  260. ;; plain string
  261. (set list (delete entry (symbol-value list)))
  262. ;; cons cell
  263. (set list (delete (assoc entry (symbol-value list))
  264. (symbol-value list))))))
  265. ;;;###autoload
  266. (defun erc-add-pal ()
  267. "Add pal interactively to `erc-pals'."
  268. (interactive)
  269. (erc-add-entry-to-list 'erc-pals "Add pal: " (erc-get-server-nickname-alist)))
  270. ;;;###autoload
  271. (defun erc-delete-pal ()
  272. "Delete pal interactively to `erc-pals'."
  273. (interactive)
  274. (erc-remove-entry-from-list 'erc-pals "Delete pal: "))
  275. ;;;###autoload
  276. (defun erc-add-fool ()
  277. "Add fool interactively to `erc-fools'."
  278. (interactive)
  279. (erc-add-entry-to-list 'erc-fools "Add fool: "
  280. (erc-get-server-nickname-alist)))
  281. ;;;###autoload
  282. (defun erc-delete-fool ()
  283. "Delete fool interactively to `erc-fools'."
  284. (interactive)
  285. (erc-remove-entry-from-list 'erc-fools "Delete fool: "))
  286. ;;;###autoload
  287. (defun erc-add-keyword ()
  288. "Add keyword interactively to `erc-keywords'."
  289. (interactive)
  290. (erc-add-entry-to-list 'erc-keywords "Add keyword: "))
  291. ;;;###autoload
  292. (defun erc-delete-keyword ()
  293. "Delete keyword interactively to `erc-keywords'."
  294. (interactive)
  295. (erc-remove-entry-from-list 'erc-keywords "Delete keyword: "))
  296. ;;;###autoload
  297. (defun erc-add-dangerous-host ()
  298. "Add dangerous-host interactively to `erc-dangerous-hosts'."
  299. (interactive)
  300. (erc-add-entry-to-list 'erc-dangerous-hosts "Add dangerous-host: "))
  301. ;;;###autoload
  302. (defun erc-delete-dangerous-host ()
  303. "Delete dangerous-host interactively to `erc-dangerous-hosts'."
  304. (interactive)
  305. (erc-remove-entry-from-list 'erc-dangerous-hosts "Delete dangerous-host: "))
  306. (defun erc-match-current-nick-p (nickuserhost msg)
  307. "Check whether the current nickname is in MSG.
  308. NICKUSERHOST will be ignored."
  309. (with-syntax-table erc-match-syntax-table
  310. (and msg
  311. (string-match (concat "\\b"
  312. (regexp-quote (erc-current-nick))
  313. "\\b")
  314. msg))))
  315. (defun erc-match-pal-p (nickuserhost msg)
  316. "Check whether NICKUSERHOST is in `erc-pals'.
  317. MSG will be ignored."
  318. (and nickuserhost
  319. (erc-list-match erc-pals nickuserhost)))
  320. (defun erc-match-fool-p (nickuserhost msg)
  321. "Check whether NICKUSERHOST is in `erc-fools' or MSG is directed at a fool."
  322. (and msg nickuserhost
  323. (or (erc-list-match erc-fools nickuserhost)
  324. (erc-match-directed-at-fool-p msg))))
  325. (defun erc-match-keyword-p (nickuserhost msg)
  326. "Check whether any keyword of `erc-keywords' matches for MSG.
  327. NICKUSERHOST will be ignored."
  328. (and msg
  329. (erc-list-match
  330. (mapcar (lambda (x)
  331. (if (listp x)
  332. (car x)
  333. x))
  334. erc-keywords)
  335. msg)))
  336. (defun erc-match-dangerous-host-p (nickuserhost msg)
  337. "Check whether NICKUSERHOST is in `erc-dangerous-hosts'.
  338. MSG will be ignored."
  339. (and nickuserhost
  340. (erc-list-match erc-dangerous-hosts nickuserhost)))
  341. (defun erc-match-directed-at-fool-p (msg)
  342. "Check whether MSG is directed at a fool.
  343. In order to do this, every entry in `erc-fools' will be used.
  344. In any of the following situations, MSG is directed at an entry FOOL:
  345. - MSG starts with \"FOOL: \" or \"FOO, \"
  346. - MSG contains \", FOOL.\" (actually, \"\\s. FOOL\\s.\")"
  347. (let ((fools-beg (mapcar (lambda (entry)
  348. (concat "^" entry "[:,] "))
  349. erc-fools))
  350. (fools-end (mapcar (lambda (entry)
  351. (concat "\\s. " entry "\\s."))
  352. erc-fools)))
  353. (or (erc-list-match fools-beg msg)
  354. (erc-list-match fools-end msg))))
  355. (defun erc-match-message ()
  356. "Mark certain keywords in a region.
  357. Use this defun with `erc-insert-modify-hook'."
  358. ;; This needs some refactoring.
  359. (goto-char (point-min))
  360. (let* ((to-match-nick-dep '("pal" "fool" "dangerous-host"))
  361. (to-match-nick-indep '("keyword" "current-nick"))
  362. (vector (erc-get-parsed-vector (point-min)))
  363. (nickuserhost (erc-get-parsed-vector-nick vector))
  364. (nickname (and nickuserhost
  365. (nth 0 (erc-parse-user nickuserhost))))
  366. (old-pt (point))
  367. (nick-beg (and nickname
  368. (re-search-forward (regexp-quote nickname)
  369. (point-max) t)
  370. (match-beginning 0)))
  371. (nick-end (when nick-beg
  372. (match-end 0)))
  373. (message (buffer-substring (if (and nick-end
  374. (<= (+ 2 nick-end) (point-max)))
  375. (+ 2 nick-end)
  376. (point-min))
  377. (point-max))))
  378. (when vector
  379. (mapc
  380. (lambda (match-type)
  381. (goto-char (point-min))
  382. (let* ((match-prefix (concat "erc-" match-type))
  383. (match-pred (intern (concat "erc-match-" match-type "-p")))
  384. (match-htype (eval (intern (concat match-prefix
  385. "-highlight-type"))))
  386. (match-regex (if (string= match-type "current-nick")
  387. (regexp-quote (erc-current-nick))
  388. (eval (intern (concat match-prefix "s")))))
  389. (match-face (intern (concat match-prefix "-face"))))
  390. (when (funcall match-pred nickuserhost message)
  391. (cond
  392. ;; Highlight the nick of the message
  393. ((and (eq match-htype 'nick)
  394. nick-end)
  395. (erc-put-text-property
  396. nick-beg nick-end
  397. 'face match-face (current-buffer)))
  398. ;; Highlight the nick of the message, or the current
  399. ;; nick if there's no nick in the message (e.g. /NAMES
  400. ;; output)
  401. ((and (string= match-type "current-nick")
  402. (eq match-htype 'nick-or-keyword))
  403. (if nick-end
  404. (erc-put-text-property
  405. nick-beg nick-end
  406. 'face match-face (current-buffer))
  407. (goto-char (+ 2 (or nick-end
  408. (point-min))))
  409. (while (re-search-forward match-regex nil t)
  410. (erc-put-text-property (match-beginning 0) (match-end 0)
  411. 'face match-face))))
  412. ;; Highlight the whole message
  413. ((eq match-htype 'all)
  414. (erc-put-text-property
  415. (point-min) (point-max)
  416. 'face match-face (current-buffer)))
  417. ;; Highlight all occurrences of the word to be
  418. ;; highlighted.
  419. ((and (string= match-type "keyword")
  420. (eq match-htype 'keyword))
  421. (mapc (lambda (elt)
  422. (let ((regex elt)
  423. (face match-face))
  424. (when (consp regex)
  425. (setq regex (car elt)
  426. face (cdr elt)))
  427. (goto-char (+ 2 (or nick-end
  428. (point-min))))
  429. (while (re-search-forward regex nil t)
  430. (erc-put-text-property
  431. (match-beginning 0) (match-end 0)
  432. 'face face))))
  433. match-regex))
  434. ;; Highlight all occurrences of our nick.
  435. ((and (string= match-type "current-nick")
  436. (eq match-htype 'keyword))
  437. (goto-char (+ 2 (or nick-end
  438. (point-min))))
  439. (while (re-search-forward match-regex nil t)
  440. (erc-put-text-property (match-beginning 0) (match-end 0)
  441. 'face match-face)))
  442. ;; Else twiddle your thumbs.
  443. (t nil))
  444. (run-hook-with-args
  445. 'erc-text-matched-hook
  446. (intern match-type)
  447. (or nickuserhost
  448. (concat "Server:" (erc-get-parsed-vector-type vector)))
  449. message))))
  450. (if nickuserhost
  451. (append to-match-nick-dep to-match-nick-indep)
  452. to-match-nick-indep)))))
  453. (defun erc-log-matches (match-type nickuserhost message)
  454. "Log matches in a separate buffer, determined by MATCH-TYPE.
  455. The behavior of this function is controlled by the variables
  456. `erc-log-matches-types-alist' and `erc-log-matches-flag'.
  457. Specify the match types which should be logged in the former,
  458. and deactivate/activate match logging in the latter.
  459. See `erc-log-match-format'."
  460. (let ((match-buffer-name (cdr (assq match-type
  461. erc-log-matches-types-alist)))
  462. (nick (nth 0 (erc-parse-user nickuserhost))))
  463. (when (and
  464. (or (eq erc-log-matches-flag t)
  465. (and (eq erc-log-matches-flag 'away)
  466. (erc-away-time)))
  467. match-buffer-name)
  468. (let ((line (format-spec erc-log-match-format
  469. (format-spec-make
  470. ?n nick
  471. ?t (format-time-string
  472. (or (and (boundp 'erc-timestamp-format)
  473. erc-timestamp-format)
  474. "[%Y-%m-%d %H:%M] "))
  475. ?c (or (erc-default-target) "")
  476. ?m message
  477. ?u nickuserhost))))
  478. (with-current-buffer (erc-log-matches-make-buffer match-buffer-name)
  479. (let ((inhibit-read-only t))
  480. (goto-char (point-max))
  481. (insert line)))))))
  482. (defun erc-log-matches-make-buffer (name)
  483. "Create or get a log-matches buffer named NAME and return it."
  484. (let* ((buffer-already (get-buffer name))
  485. (buffer (or buffer-already
  486. (get-buffer-create name))))
  487. (with-current-buffer buffer
  488. (unless buffer-already
  489. (insert " == Type \"q\" to dismiss messages ==\n")
  490. (erc-view-mode-enter nil (lambda (buffer)
  491. (when (y-or-n-p "Discard messages? ")
  492. (kill-buffer buffer)))))
  493. buffer)))
  494. (defun erc-log-matches-come-back (proc parsed)
  495. "Display a notice that messages were logged while away."
  496. (when (and (erc-away-time)
  497. (eq erc-log-matches-flag 'away))
  498. (mapc
  499. (lambda (match-type)
  500. (let ((buffer (get-buffer (cdr match-type)))
  501. (buffer-name (cdr match-type)))
  502. (when buffer
  503. (let* ((last-msg-time (erc-emacs-time-to-erc-time
  504. (with-current-buffer buffer
  505. (get-text-property (1- (point-max))
  506. 'timestamp))))
  507. (away-time (erc-emacs-time-to-erc-time (erc-away-time))))
  508. (when (and away-time last-msg-time
  509. (erc-time-gt last-msg-time away-time))
  510. (erc-display-message
  511. nil 'notice 'active
  512. (format "You have logged messages waiting in \"%s\"."
  513. buffer-name))
  514. (erc-display-message
  515. nil 'notice 'active
  516. (format "Type \"C-c C-k %s RET\" to view them."
  517. buffer-name)))))))
  518. erc-log-matches-types-alist))
  519. nil)
  520. ; This handler must be run _before_ erc-process-away is.
  521. (add-hook 'erc-server-305-functions 'erc-log-matches-come-back nil)
  522. (defun erc-go-to-log-matches-buffer ()
  523. "Interactively open an erc-log-matches buffer."
  524. (interactive)
  525. (let ((buffer-name (completing-read "Switch to ERC Log buffer: "
  526. (mapcar (lambda (x)
  527. (cons (cdr x) t))
  528. erc-log-matches-types-alist)
  529. (lambda (buffer-cons)
  530. (get-buffer (car buffer-cons))))))
  531. (switch-to-buffer buffer-name)))
  532. (define-key erc-mode-map "\C-c\C-k" 'erc-go-to-log-matches-buffer)
  533. (defun erc-hide-fools (match-type nickuserhost message)
  534. "Hide foolish comments.
  535. This function should be called from `erc-text-matched-hook'."
  536. (when (eq match-type 'fool)
  537. (erc-put-text-properties (point-min) (point-max)
  538. '(invisible intangible)
  539. (current-buffer))))
  540. (defun erc-beep-on-match (match-type nickuserhost message)
  541. "Beep when text matches.
  542. This function is meant to be called from `erc-text-matched-hook'."
  543. (when (member match-type erc-beep-match-types)
  544. (beep)))
  545. (provide 'erc-match)
  546. ;;; erc-match.el ends here
  547. ;;
  548. ;; Local Variables:
  549. ;; indent-tabs-mode: t
  550. ;; tab-width: 8
  551. ;; End: