erc-page.el 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ;; erc-page.el - CTCP PAGE support for ERC
  2. ;; Copyright (C) 2002, 2004, 2006-2017 Free Software Foundation, Inc.
  3. ;; Maintainer: emacs-devel@gnu.org
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; Requiring this file will make ERC react to CTCP PAGE messages
  17. ;; received, and it will provide a new /PAGE command to send such
  18. ;; messages yourself. To enable it, customize the variable
  19. ;; `erc-page-mode'.
  20. ;;; Code:
  21. (require 'erc)
  22. ;;;###autoload (autoload 'erc-page-mode "erc-page")
  23. (define-erc-module page ctcp-page
  24. "Process CTCP PAGE requests from IRC."
  25. nil nil)
  26. (erc-define-catalog-entry 'english 'CTCP-PAGE "Page from %n (%u@%h): %m")
  27. (defgroup erc-page nil
  28. "React to CTCP PAGE messages."
  29. :group 'erc)
  30. (defcustom erc-page-function nil
  31. "A function to process a \"page\" request.
  32. If nil, this prints the page message in the minibuffer and calls
  33. `beep'. If non-nil, it must be a function that takes two arguments:
  34. SENDER and MSG, both strings.
  35. Example for your init file:
  36. \(setq erc-page-function
  37. (lambda (sender msg)
  38. (play-sound-file \"/home/alex/elisp/erc/sounds/ni.wav\")
  39. (message \"IRC Page from %s: %s\" sender msg)))"
  40. :group 'erc-page
  41. :type '(choice (const nil)
  42. (function)))
  43. (defcustom erc-ctcp-query-PAGE-hook '(erc-ctcp-query-PAGE)
  44. "List of functions to be called when a CTCP PAGE is received.
  45. This is called from `erc-process-ctcp-query'. The functions are called
  46. with six arguments: PROC NICK LOGIN HOST TO MSG. Note that you can
  47. also set `erc-page-function' to a function, which only gets two arguments,
  48. SENDER and MSG, so that might be easier to use."
  49. :group 'erc-page
  50. :type '(repeat function))
  51. (defun erc-ctcp-query-PAGE (proc nick login host to msg)
  52. "Deal with an CTCP PAGE query, if `erc-page-mode' is non-nil.
  53. This will call `erc-page-function', if defined, or it will just print
  54. a message and `beep'. In addition to that, the page message is also
  55. inserted into the server buffer."
  56. (when (and erc-page-mode
  57. (string-match "PAGE\\(\\s-+.*\\)?$" msg))
  58. (let* ((m (match-string 1 msg))
  59. (page-msg (if m (erc-controls-interpret (substring m 1))
  60. "[no message]"))
  61. text)
  62. (if m (setq m (substring m 1)))
  63. (setq text (erc-format-message 'CTCP-PAGE
  64. ?n nick ?u login
  65. ?h host ?m page-msg))
  66. (if erc-page-function
  67. (funcall erc-page-function nick page-msg)
  68. ;; if no function is defined
  69. (message "%s" text)
  70. (beep))
  71. ;; insert text into buffer
  72. (erc-display-message
  73. nil 'notice nil text)))
  74. nil)
  75. (defun erc-cmd-PAGE (line &optional force)
  76. "Send a CTCP page to the user given as the first word in LINE.
  77. The rest of LINE is the message to send. Note that you will only
  78. receive pages if `erc-page-mode' is on."
  79. (when (string-match "^\\s-*\\(\\S-+\\) ?\\(.*\\)" line)
  80. (let ((nick (match-string 1 line))
  81. (msg (match-string 2 line)))
  82. (erc-cmd-CTCP nick "PAGE" msg))))
  83. (put 'erc-cmd-PAGE 'do-not-parse-args t)
  84. (provide 'erc-page)
  85. ;;; erc-page.el ends here
  86. ;;
  87. ;; Local Variables:
  88. ;; indent-tabs-mode: t
  89. ;; tab-width: 8
  90. ;; End: