erc-match.el 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. ;;; erc-match.el --- Highlight messages matching certain regexps
  2. ;; Copyright (C) 2002-2015 Free Software Foundation, Inc.
  3. ;; Author: Andreas Fuchs <asf@void.at>
  4. ;; Maintainer: emacs-devel@gnu.org
  5. ;; Keywords: comm, faces
  6. ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcMatch
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;; This file includes stuff to work with pattern matching in ERC. If
  20. ;; you were used to customizing erc-fools, erc-keywords, erc-pals,
  21. ;; erc-dangerous-hosts and the like, this file contains these
  22. ;; customizable variables.
  23. ;; Usage:
  24. ;; Put (erc-match-mode 1) into your init file.
  25. ;;; Code:
  26. (require 'erc)
  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. (defcustom erc-match-exclude-server-buffer nil
  188. "If true, don't perform match on the server buffer; this is
  189. useful for excluding all the things like MOTDs from the server
  190. and other miscellaneous functions."
  191. :group 'erc-match
  192. :version "24.3"
  193. :type 'boolean)
  194. ;; Internal variables:
  195. ;; This is exactly the same as erc-button-syntax-table. Should we
  196. ;; just put it in erc.el
  197. (defvar erc-match-syntax-table
  198. (let ((table (make-syntax-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. (modify-syntax-entry ?` "w" table)
  206. (modify-syntax-entry ?' "w" table)
  207. (modify-syntax-entry ?^ "w" table)
  208. (modify-syntax-entry ?- "w" table)
  209. (modify-syntax-entry ?_ "w" table)
  210. (modify-syntax-entry ?| "w" table)
  211. (modify-syntax-entry ?\\ "w" table)
  212. table)
  213. "Syntax table used when highlighting messages.
  214. This syntax table should make all the valid nick characters word
  215. constituents.")
  216. ;; Faces:
  217. (defface erc-current-nick-face '((t :weight bold :foreground "DarkTurquoise"))
  218. "ERC face for occurrences of your current nickname."
  219. :group 'erc-faces)
  220. (defface erc-dangerous-host-face '((t :foreground "red"))
  221. "ERC face for people on dangerous hosts.
  222. See `erc-dangerous-hosts'."
  223. :group 'erc-faces)
  224. (defface erc-pal-face '((t :weight bold :foreground "Magenta"))
  225. "ERC face for your pals.
  226. See `erc-pals'."
  227. :group 'erc-faces)
  228. (defface erc-fool-face '((t :foreground "dim gray"))
  229. "ERC face for fools on the channel.
  230. See `erc-fools'."
  231. :group 'erc-faces)
  232. (defface erc-keyword-face '((t :weight bold :foreground "pale green"))
  233. "ERC face for your keywords.
  234. Note that this is the default face to use if
  235. `erc-keywords' does not specify another."
  236. :group 'erc-faces)
  237. ;; Functions:
  238. (defun erc-add-entry-to-list (list prompt &optional completions)
  239. "Add an entry interactively to a list.
  240. LIST must be passed as a symbol
  241. The query happens using PROMPT.
  242. Completion is performed on the optional alist COMPLETIONS."
  243. (let ((entry (completing-read
  244. prompt
  245. completions
  246. (lambda (x)
  247. (not (erc-member-ignore-case (car x) (symbol-value list)))))))
  248. (if (erc-member-ignore-case entry (symbol-value list))
  249. (error "\"%s\" is already on the list" entry)
  250. (set list (cons entry (symbol-value list))))))
  251. (defun erc-remove-entry-from-list (list prompt)
  252. "Remove an entry interactively from a list.
  253. LIST must be passed as a symbol.
  254. The elements of LIST can be strings, or cons cells where the
  255. car is the string."
  256. (let* ((alist (mapcar (lambda (x)
  257. (if (listp x)
  258. x
  259. (list x)))
  260. (symbol-value list)))
  261. (entry (completing-read
  262. prompt
  263. alist
  264. nil
  265. t)))
  266. (if (erc-member-ignore-case entry (symbol-value list))
  267. ;; plain string
  268. (set list (delete entry (symbol-value list)))
  269. ;; cons cell
  270. (set list (delete (assoc entry (symbol-value list))
  271. (symbol-value list))))))
  272. ;;;###autoload
  273. (defun erc-add-pal ()
  274. "Add pal interactively to `erc-pals'."
  275. (interactive)
  276. (erc-add-entry-to-list 'erc-pals "Add pal: " (erc-get-server-nickname-alist)))
  277. ;;;###autoload
  278. (defun erc-delete-pal ()
  279. "Delete pal interactively to `erc-pals'."
  280. (interactive)
  281. (erc-remove-entry-from-list 'erc-pals "Delete pal: "))
  282. ;;;###autoload
  283. (defun erc-add-fool ()
  284. "Add fool interactively to `erc-fools'."
  285. (interactive)
  286. (erc-add-entry-to-list 'erc-fools "Add fool: "
  287. (erc-get-server-nickname-alist)))
  288. ;;;###autoload
  289. (defun erc-delete-fool ()
  290. "Delete fool interactively to `erc-fools'."
  291. (interactive)
  292. (erc-remove-entry-from-list 'erc-fools "Delete fool: "))
  293. ;;;###autoload
  294. (defun erc-add-keyword ()
  295. "Add keyword interactively to `erc-keywords'."
  296. (interactive)
  297. (erc-add-entry-to-list 'erc-keywords "Add keyword: "))
  298. ;;;###autoload
  299. (defun erc-delete-keyword ()
  300. "Delete keyword interactively to `erc-keywords'."
  301. (interactive)
  302. (erc-remove-entry-from-list 'erc-keywords "Delete keyword: "))
  303. ;;;###autoload
  304. (defun erc-add-dangerous-host ()
  305. "Add dangerous-host interactively to `erc-dangerous-hosts'."
  306. (interactive)
  307. (erc-add-entry-to-list 'erc-dangerous-hosts "Add dangerous-host: "))
  308. ;;;###autoload
  309. (defun erc-delete-dangerous-host ()
  310. "Delete dangerous-host interactively to `erc-dangerous-hosts'."
  311. (interactive)
  312. (erc-remove-entry-from-list 'erc-dangerous-hosts "Delete dangerous-host: "))
  313. (defun erc-match-current-nick-p (nickuserhost msg)
  314. "Check whether the current nickname is in MSG.
  315. NICKUSERHOST will be ignored."
  316. (with-syntax-table erc-match-syntax-table
  317. (and msg
  318. (string-match (concat "\\b"
  319. (regexp-quote (erc-current-nick))
  320. "\\b")
  321. msg))))
  322. (defun erc-match-pal-p (nickuserhost msg)
  323. "Check whether NICKUSERHOST is in `erc-pals'.
  324. MSG will be ignored."
  325. (and nickuserhost
  326. (erc-list-match erc-pals nickuserhost)))
  327. (defun erc-match-fool-p (nickuserhost msg)
  328. "Check whether NICKUSERHOST is in `erc-fools' or MSG is directed at a fool."
  329. (and msg nickuserhost
  330. (or (erc-list-match erc-fools nickuserhost)
  331. (erc-match-directed-at-fool-p msg))))
  332. (defun erc-match-keyword-p (nickuserhost msg)
  333. "Check whether any keyword of `erc-keywords' matches for MSG.
  334. NICKUSERHOST will be ignored."
  335. (and msg
  336. (erc-list-match
  337. (mapcar (lambda (x)
  338. (if (listp x)
  339. (car x)
  340. x))
  341. erc-keywords)
  342. msg)))
  343. (defun erc-match-dangerous-host-p (nickuserhost msg)
  344. "Check whether NICKUSERHOST is in `erc-dangerous-hosts'.
  345. MSG will be ignored."
  346. (and nickuserhost
  347. (erc-list-match erc-dangerous-hosts nickuserhost)))
  348. (defun erc-match-directed-at-fool-p (msg)
  349. "Check whether MSG is directed at a fool.
  350. In order to do this, every entry in `erc-fools' will be used.
  351. In any of the following situations, MSG is directed at an entry FOOL:
  352. - MSG starts with \"FOOL: \" or \"FOO, \"
  353. - MSG contains \", FOOL.\" (actually, \"\\s. FOOL\\s.\")"
  354. (let ((fools-beg (mapcar (lambda (entry)
  355. (concat "^" entry "[:,] "))
  356. erc-fools))
  357. (fools-end (mapcar (lambda (entry)
  358. (concat "\\s. " entry "\\s."))
  359. erc-fools)))
  360. (or (erc-list-match fools-beg msg)
  361. (erc-list-match fools-end msg))))
  362. (defun erc-match-message ()
  363. "Mark certain keywords in a region.
  364. Use this defun with `erc-insert-modify-hook'."
  365. ;; This needs some refactoring.
  366. (goto-char (point-min))
  367. (let* ((to-match-nick-dep '("pal" "fool" "dangerous-host"))
  368. (to-match-nick-indep '("keyword" "current-nick"))
  369. (vector (erc-get-parsed-vector (point-min)))
  370. (nickuserhost (erc-get-parsed-vector-nick vector))
  371. (nickname (and nickuserhost
  372. (nth 0 (erc-parse-user nickuserhost))))
  373. (old-pt (point))
  374. (nick-beg (and nickname
  375. (re-search-forward (regexp-quote nickname)
  376. (point-max) t)
  377. (match-beginning 0)))
  378. (nick-end (when nick-beg
  379. (match-end 0)))
  380. (message (buffer-substring
  381. (if (and nick-end
  382. (<= (+ 2 nick-end) (point-max)))
  383. ;; Message starts 2 characters after the nick
  384. ;; except for CTCP ACTION messages. Nick
  385. ;; surrounded by angle brackets only in normal
  386. ;; messages.
  387. (+ nick-end
  388. (if (eq ?> (char-after nick-end))
  389. 2
  390. 1))
  391. (point-min))
  392. (point-max))))
  393. (when (and vector
  394. (not (and erc-match-exclude-server-buffer
  395. (erc-server-buffer-p))))
  396. (mapc
  397. (lambda (match-type)
  398. (goto-char (point-min))
  399. (let* ((match-prefix (concat "erc-" match-type))
  400. (match-pred (intern (concat "erc-match-" match-type "-p")))
  401. (match-htype (eval (intern (concat match-prefix
  402. "-highlight-type"))))
  403. (match-regex (if (string= match-type "current-nick")
  404. (regexp-quote (erc-current-nick))
  405. (eval (intern (concat match-prefix "s")))))
  406. (match-face (intern (concat match-prefix "-face"))))
  407. (when (funcall match-pred nickuserhost message)
  408. (cond
  409. ;; Highlight the nick of the message
  410. ((and (eq match-htype 'nick)
  411. nick-end)
  412. (erc-put-text-property
  413. nick-beg nick-end
  414. 'face match-face (current-buffer)))
  415. ;; Highlight the nick of the message, or the current
  416. ;; nick if there's no nick in the message (e.g. /NAMES
  417. ;; output)
  418. ((and (string= match-type "current-nick")
  419. (eq match-htype 'nick-or-keyword))
  420. (if nick-end
  421. (erc-put-text-property
  422. nick-beg nick-end
  423. 'face match-face (current-buffer))
  424. (goto-char (+ 2 (or nick-end
  425. (point-min))))
  426. (while (re-search-forward match-regex nil t)
  427. (erc-put-text-property (match-beginning 0) (match-end 0)
  428. 'face match-face))))
  429. ;; Highlight the whole message
  430. ((eq match-htype 'all)
  431. (erc-put-text-property
  432. (point-min) (point-max)
  433. 'face match-face (current-buffer)))
  434. ;; Highlight all occurrences of the word to be
  435. ;; highlighted.
  436. ((and (string= match-type "keyword")
  437. (eq match-htype 'keyword))
  438. (mapc (lambda (elt)
  439. (let ((regex elt)
  440. (face match-face))
  441. (when (consp regex)
  442. (setq regex (car elt)
  443. face (cdr elt)))
  444. (goto-char (+ 2 (or nick-end
  445. (point-min))))
  446. (while (re-search-forward regex nil t)
  447. (erc-put-text-property
  448. (match-beginning 0) (match-end 0)
  449. 'face face))))
  450. match-regex))
  451. ;; Highlight all occurrences of our nick.
  452. ((and (string= match-type "current-nick")
  453. (eq match-htype 'keyword))
  454. (goto-char (+ 2 (or nick-end
  455. (point-min))))
  456. (while (re-search-forward match-regex nil t)
  457. (erc-put-text-property (match-beginning 0) (match-end 0)
  458. 'face match-face)))
  459. ;; Else twiddle your thumbs.
  460. (t nil))
  461. (run-hook-with-args
  462. 'erc-text-matched-hook
  463. (intern match-type)
  464. (or nickuserhost
  465. (concat "Server:" (erc-get-parsed-vector-type vector)))
  466. message))))
  467. (if nickuserhost
  468. (append to-match-nick-dep to-match-nick-indep)
  469. to-match-nick-indep)))))
  470. (defun erc-log-matches (match-type nickuserhost message)
  471. "Log matches in a separate buffer, determined by MATCH-TYPE.
  472. The behavior of this function is controlled by the variables
  473. `erc-log-matches-types-alist' and `erc-log-matches-flag'.
  474. Specify the match types which should be logged in the former,
  475. and deactivate/activate match logging in the latter.
  476. See `erc-log-match-format'."
  477. (let ((match-buffer-name (cdr (assq match-type
  478. erc-log-matches-types-alist)))
  479. (nick (nth 0 (erc-parse-user nickuserhost))))
  480. (when (and
  481. (or (eq erc-log-matches-flag t)
  482. (and (eq erc-log-matches-flag 'away)
  483. (erc-away-time)))
  484. match-buffer-name)
  485. (let ((line (format-spec erc-log-match-format
  486. (format-spec-make
  487. ?n nick
  488. ?t (format-time-string
  489. (or (and (boundp 'erc-timestamp-format)
  490. erc-timestamp-format)
  491. "[%Y-%m-%d %H:%M] "))
  492. ?c (or (erc-default-target) "")
  493. ?m message
  494. ?u nickuserhost))))
  495. (with-current-buffer (erc-log-matches-make-buffer match-buffer-name)
  496. (let ((inhibit-read-only t))
  497. (goto-char (point-max))
  498. (insert line)))))))
  499. (defun erc-log-matches-make-buffer (name)
  500. "Create or get a log-matches buffer named NAME and return it."
  501. (let* ((buffer-already (get-buffer name))
  502. (buffer (or buffer-already
  503. (get-buffer-create name))))
  504. (with-current-buffer buffer
  505. (unless buffer-already
  506. (insert " == Type \"q\" to dismiss messages ==\n")
  507. (erc-view-mode-enter nil (lambda (buffer)
  508. (when (y-or-n-p "Discard messages? ")
  509. (kill-buffer buffer)))))
  510. buffer)))
  511. (defun erc-log-matches-come-back (proc parsed)
  512. "Display a notice that messages were logged while away."
  513. (when (and (erc-away-time)
  514. (eq erc-log-matches-flag 'away))
  515. (mapc
  516. (lambda (match-type)
  517. (let ((buffer (get-buffer (cdr match-type)))
  518. (buffer-name (cdr match-type)))
  519. (when buffer
  520. (let* ((last-msg-time (erc-emacs-time-to-erc-time
  521. (with-current-buffer buffer
  522. (get-text-property (1- (point-max))
  523. 'timestamp))))
  524. (away-time (erc-emacs-time-to-erc-time (erc-away-time))))
  525. (when (and away-time last-msg-time
  526. (erc-time-gt last-msg-time away-time))
  527. (erc-display-message
  528. nil 'notice 'active
  529. (format "You have logged messages waiting in \"%s\"."
  530. buffer-name))
  531. (erc-display-message
  532. nil 'notice 'active
  533. (format "Type \"C-c C-k %s RET\" to view them."
  534. buffer-name)))))))
  535. erc-log-matches-types-alist))
  536. nil)
  537. ; This handler must be run _before_ erc-process-away is.
  538. (add-hook 'erc-server-305-functions 'erc-log-matches-come-back nil)
  539. (defun erc-go-to-log-matches-buffer ()
  540. "Interactively open an erc-log-matches buffer."
  541. (interactive)
  542. (let ((buffer-name (completing-read "Switch to ERC Log buffer: "
  543. (mapcar (lambda (x)
  544. (cons (cdr x) t))
  545. erc-log-matches-types-alist)
  546. (lambda (buffer-cons)
  547. (get-buffer (car buffer-cons))))))
  548. (switch-to-buffer buffer-name)))
  549. (define-key erc-mode-map "\C-c\C-k" 'erc-go-to-log-matches-buffer)
  550. (defun erc-hide-fools (match-type nickuserhost message)
  551. "Hide foolish comments.
  552. This function should be called from `erc-text-matched-hook'."
  553. (when (eq match-type 'fool)
  554. (erc-put-text-properties (point-min) (point-max)
  555. '(invisible intangible)
  556. (current-buffer))))
  557. (defun erc-beep-on-match (match-type nickuserhost message)
  558. "Beep when text matches.
  559. This function is meant to be called from `erc-text-matched-hook'."
  560. (when (member match-type erc-beep-match-types)
  561. (beep)))
  562. (provide 'erc-match)
  563. ;;; erc-match.el ends here
  564. ;;
  565. ;; Local Variables:
  566. ;; indent-tabs-mode: t
  567. ;; tab-width: 8
  568. ;; End: