erc-button.el 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. ;; erc-button.el --- A way of buttonizing certain things in ERC buffers
  2. ;; Copyright (C) 1996-2004, 2006-2012 Free Software Foundation, Inc.
  3. ;; Author: Mario Lang <mlang@delysid.org>
  4. ;; Keywords: irc, button, url, regexp
  5. ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcButton
  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. ;; Heavily borrowed from gnus-art.el. Thanks to the original authors.
  19. ;; This buttonizes nicks and other stuff to make it all clickable.
  20. ;; To enable, add to your ~/.emacs:
  21. ;; (require 'erc-button)
  22. ;; (erc-button-mode 1)
  23. ;;
  24. ;; Todo:
  25. ;; * Rewrite all this to do the same, but use button.el from GNU Emacs
  26. ;; if it's available for xemacs too. Why? button.el is much faster,
  27. ;; and much more elegant, and solves the problem we get with large buffers
  28. ;; and a large erc-button-marker-list.
  29. ;;; Code:
  30. (require 'erc)
  31. (require 'wid-edit)
  32. (require 'erc-fill)
  33. ;;; Minor Mode
  34. (defgroup erc-button nil
  35. "Define how text can be turned into clickable buttons."
  36. :group 'erc)
  37. ;;;###autoload (autoload 'erc-button-mode "erc-button" nil t)
  38. (define-erc-module button nil
  39. "This mode buttonizes all messages according to `erc-button-alist'."
  40. ((add-hook 'erc-insert-modify-hook 'erc-button-add-buttons 'append)
  41. (add-hook 'erc-send-modify-hook 'erc-button-add-buttons 'append)
  42. (add-hook 'erc-complete-functions 'erc-button-next-function)
  43. (add-hook 'erc-mode-hook 'erc-button-setup))
  44. ((remove-hook 'erc-insert-modify-hook 'erc-button-add-buttons)
  45. (remove-hook 'erc-send-modify-hook 'erc-button-add-buttons)
  46. (remove-hook 'erc-complete-functions 'erc-button-next-function)
  47. (remove-hook 'erc-mode-hook 'erc-button-setup)
  48. (when (featurep 'xemacs)
  49. (dolist (buffer (erc-buffer-list))
  50. (with-current-buffer buffer
  51. (kill-local-variable 'widget-button-face))))))
  52. ;;; Variables
  53. (defface erc-button '((t (:bold t)))
  54. "ERC button face."
  55. :group 'erc-faces)
  56. (defcustom erc-button-face 'erc-button
  57. "Face used for highlighting buttons in ERC buffers.
  58. A button is a piece of text that you can activate by pressing
  59. `RET' or `mouse-2' above it. See also `erc-button-keymap'."
  60. :type 'face
  61. :group 'erc-faces)
  62. (defcustom erc-button-nickname-face 'erc-nick-default-face
  63. "Face used for ERC nickname buttons."
  64. :type 'face
  65. :group 'erc-faces)
  66. (defcustom erc-button-mouse-face 'highlight
  67. "Face used for mouse highlighting in ERC buffers.
  68. Buttons will be displayed in this face when the mouse cursor is
  69. above them."
  70. :type 'face
  71. :group 'erc-faces)
  72. (defcustom erc-button-url-regexp
  73. (concat "\\(www\\.\\|\\(s?https?\\|"
  74. "ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\)"
  75. "\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?"
  76. "[-a-zA-Z0-9_=!?#$@~`%&*+\\/:;.,()]+[-a-zA-Z0-9_=#$@~`%&*+\\/()]")
  77. "Regular expression that matches URLs."
  78. :group 'erc-button
  79. :type 'regexp)
  80. (defcustom erc-button-wrap-long-urls nil
  81. "If non-nil, \"long\" URLs matching `erc-button-url-regexp' will be wrapped.
  82. If this variable is a number, consider URLs longer than its value to
  83. be \"long\". If t, URLs will be considered \"long\" if they are
  84. longer than `erc-fill-column'."
  85. :group 'erc-button
  86. :type '(choice integer boolean))
  87. (defcustom erc-button-buttonize-nicks t
  88. "Flag indicating whether nicks should be buttonized or not."
  89. :group 'erc-button
  90. :type 'boolean)
  91. (defcustom erc-button-rfc-url "http://www.faqs.org/rfcs/rfc%s.html"
  92. "*URL used to browse rfc references.
  93. %s is replaced by the number."
  94. :group 'erc-button
  95. :type 'string)
  96. (defcustom erc-button-google-url "http://www.google.com/search?q=%s"
  97. "*URL used to browse Google search references.
  98. %s is replaced by the search string."
  99. :group 'erc-button
  100. :type 'string)
  101. (defcustom erc-button-alist
  102. ;; Since the callback is only executed when the user is clicking on
  103. ;; a button, it makes no sense to optimize performance by
  104. ;; bytecompiling lambdas in this alist. On the other hand, it makes
  105. ;; things hard to maintain.
  106. '(('nicknames 0 erc-button-buttonize-nicks erc-nick-popup 0)
  107. (erc-button-url-regexp 0 t browse-url 0)
  108. ("<URL: *\\([^<> ]+\\) *>" 0 t browse-url 1)
  109. ("(\\(\\([^~\n \t@][^\n \t@]*\\)@\\([a-zA-Z0-9.:-]+\\)\\)" 1 t finger 2 3)
  110. ;; emacs internal
  111. ("[`]\\([a-zA-Z][-a-zA-Z_0-9]+\\)[']" 1 t erc-button-describe-symbol 1)
  112. ;; pseudo links
  113. ("\\bInfo:[\"]\\([^\"]+\\)[\"]" 0 t Info-goto-node 1)
  114. ("\\b\\(Ward\\|Wiki\\|WardsWiki\\|TheWiki\\):\\([A-Z][a-z]+\\([A-Z][a-z]+\\)+\\)"
  115. 0 t (lambda (page)
  116. (browse-url (concat "http://c2.com/cgi-bin/wiki?" page)))
  117. 2)
  118. ("EmacsWiki:\\([A-Z][a-z]+\\([A-Z][a-z]+\\)+\\)" 0 t erc-browse-emacswiki 1)
  119. ("Lisp:\\([a-zA-Z.+-]+\\)" 0 t erc-browse-emacswiki-lisp 1)
  120. ("\\bGoogle:\\([^ \t\n\r\f]+\\)"
  121. 0 t (lambda (keywords)
  122. (browse-url (format erc-button-google-url keywords)))
  123. 1)
  124. ("\\brfc[#: ]?\\([0-9]+\\)"
  125. 0 t (lambda (num)
  126. (browse-url (format erc-button-rfc-url num)))
  127. 1)
  128. ;; other
  129. ("\\s-\\(@\\([0-9][0-9][0-9]\\)\\)" 1 t erc-button-beats-to-time 2))
  130. "*Alist of regexps matching buttons in ERC buffers.
  131. Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
  132. REGEXP is the string matching text around the button or a symbol
  133. indicating a variable holding that string, or a list of
  134. strings, or an alist with the strings in the car. Note that
  135. entries in lists or alists are considered to be nicks or other
  136. complete words. Therefore they are enclosed in \\< and \\>
  137. while searching. REGEXP can also be the quoted symbol
  138. 'nicknames, which matches the nickname of any user on the
  139. current server.
  140. BUTTON is the number of the regexp grouping actually matching the
  141. button, This is ignored if REGEXP is 'nicknames.
  142. FORM is a lisp expression which must eval to true for the button to
  143. be added,
  144. CALLBACK is the function to call when the user push this button.
  145. CALLBACK can also be a symbol. Its variable value will be used
  146. as the callback function.
  147. PAR is a number of a regexp grouping whose text will be passed to
  148. CALLBACK. There can be several PAR arguments. If REGEXP is
  149. 'nicknames, these are ignored, and CALLBACK will be called with
  150. the nickname matched as the argument."
  151. :group 'erc-button
  152. :type '(repeat
  153. (list :tag "Button"
  154. (choice :tag "Matches"
  155. regexp
  156. (variable :tag "Variable containing regexp")
  157. (const :tag "Nicknames" 'nicknames))
  158. (integer :tag "Number of the regexp section that matches")
  159. (choice :tag "When to buttonize"
  160. (const :tag "Always" t)
  161. (sexp :tag "Only when this evaluates to non-nil"))
  162. (function :tag "Function to call when button is pressed")
  163. (repeat :tag "Sections of regexp to send to the function"
  164. :inline t
  165. (integer :tag "Regexp section number")))))
  166. (defcustom erc-emacswiki-url "http://www.emacswiki.org/cgi-bin/wiki.pl?"
  167. "*URL of the EmacsWiki Homepage."
  168. :group 'erc-button
  169. :type 'string)
  170. (defcustom erc-emacswiki-lisp-url "http://www.emacswiki.org/elisp/"
  171. "*URL of the EmacsWiki ELisp area."
  172. :group 'erc-button
  173. :type 'string)
  174. (defvar erc-button-keymap
  175. (let ((map (make-sparse-keymap)))
  176. (define-key map (kbd "RET") 'erc-button-press-button)
  177. (if (featurep 'xemacs)
  178. (define-key map (kbd "<button2>") 'erc-button-click-button)
  179. (define-key map (kbd "<mouse-2>") 'erc-button-click-button))
  180. (define-key map (kbd "TAB") 'erc-button-next)
  181. (define-key map (kbd "<backtab>") 'erc-button-previous)
  182. (define-key map [follow-link] 'mouse-face)
  183. (set-keymap-parent map erc-mode-map)
  184. map)
  185. "Local keymap for ERC buttons.")
  186. (defvar erc-button-syntax-table
  187. (let ((table (make-syntax-table)))
  188. (modify-syntax-entry ?\( "w" table)
  189. (modify-syntax-entry ?\) "w" table)
  190. (modify-syntax-entry ?\[ "w" table)
  191. (modify-syntax-entry ?\] "w" 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. table)
  202. "Syntax table used when buttonizing messages.
  203. This syntax table should make all the valid nick characters word
  204. constituents.")
  205. (defvar erc-button-keys-added nil
  206. "Internal variable used to keep track of whether we've added the
  207. global-level ERC button keys yet.")
  208. (defun erc-button-setup ()
  209. "Add ERC mode-level button movement keys. This is only done once."
  210. ;; Make XEmacs use `erc-button-face'.
  211. (when (featurep 'xemacs)
  212. (set (make-local-variable 'widget-button-face) nil))
  213. ;; Add keys.
  214. (unless erc-button-keys-added
  215. (define-key erc-mode-map (kbd "<backtab>") 'erc-button-previous)
  216. (setq erc-button-keys-added t)))
  217. (defun erc-button-add-buttons ()
  218. "Find external references in the current buffer and make buttons of them.
  219. \"External references\" are things like URLs, as
  220. specified by `erc-button-alist'."
  221. (interactive)
  222. (save-excursion
  223. (with-syntax-table erc-button-syntax-table
  224. (let ((buffer-read-only nil)
  225. (inhibit-point-motion-hooks t)
  226. (inhibit-field-text-motion t)
  227. (alist erc-button-alist)
  228. entry regexp data)
  229. (erc-button-remove-old-buttons)
  230. (dolist (entry alist)
  231. (if (equal (car entry) (quote (quote nicknames)))
  232. (erc-button-add-nickname-buttons entry)
  233. (progn
  234. (setq regexp (or (and (stringp (car entry)) (car entry))
  235. (and (boundp (car entry))
  236. (symbol-value (car entry)))))
  237. (cond ((stringp regexp)
  238. (erc-button-add-buttons-1 regexp entry))
  239. ((and (listp regexp) (stringp (car regexp)))
  240. (dolist (r regexp)
  241. (erc-button-add-buttons-1
  242. (concat "\\<" (regexp-quote r) "\\>")
  243. entry)))
  244. ((and (listp regexp) (listp (car regexp))
  245. (stringp (caar regexp)))
  246. (dolist (elem regexp)
  247. (erc-button-add-buttons-1
  248. (concat "\\<" (regexp-quote (car elem)) "\\>")
  249. entry)))))))))))
  250. (defun erc-button-add-nickname-buttons (entry)
  251. "Search through the buffer for nicknames, and add buttons."
  252. (let ((form (nth 2 entry))
  253. (fun (nth 3 entry))
  254. bounds word)
  255. (when (or (eq t form)
  256. (eval form))
  257. (goto-char (point-min))
  258. (while (forward-word 1)
  259. (setq bounds (bounds-of-thing-at-point 'word))
  260. (setq word (buffer-substring-no-properties
  261. (car bounds) (cdr bounds)))
  262. (when (or (and (erc-server-buffer-p) (erc-get-server-user word))
  263. (and erc-channel-users (erc-get-channel-user word)))
  264. (erc-button-add-button (car bounds) (cdr bounds)
  265. fun t (list word)))))))
  266. (defun erc-button-add-buttons-1 (regexp entry)
  267. "Search through the buffer for matches to ENTRY and add buttons."
  268. (goto-char (point-min))
  269. (while (re-search-forward regexp nil t)
  270. (let ((start (match-beginning (nth 1 entry)))
  271. (end (match-end (nth 1 entry)))
  272. (form (nth 2 entry))
  273. (fun (nth 3 entry))
  274. (data (mapcar 'match-string (nthcdr 4 entry))))
  275. (when (or (eq t form)
  276. (eval form))
  277. (erc-button-add-button start end fun nil data regexp)))))
  278. (defun erc-button-remove-old-buttons ()
  279. "Remove all existing buttons.
  280. This is called with narrowing in effect, just before the text is
  281. buttonized again. Removing a button means to remove all the properties
  282. that `erc-button-add-button' adds, except for the face."
  283. (remove-text-properties
  284. (point-min) (point-max)
  285. '(erc-callback nil
  286. erc-data nil
  287. mouse-face nil
  288. keymap nil)))
  289. (defun erc-button-add-button (from to fun nick-p &optional data regexp)
  290. "Create a button between FROM and TO with callback FUN and data DATA.
  291. NICK-P specifies if this is a nickname button.
  292. REGEXP is the regular expression which matched for this button."
  293. ;; Really nasty hack to <URL: > ise urls, and line-wrap them if
  294. ;; they're going to be wider than `erc-fill-column'.
  295. ;; This could be a lot cleaner, but it works for me -- lawrence.
  296. (let (fill-column)
  297. (when (and erc-button-wrap-long-urls
  298. (string= regexp erc-button-url-regexp)
  299. (> (- to from)
  300. (setq fill-column (- (if (numberp erc-button-wrap-long-urls)
  301. erc-button-wrap-long-urls
  302. erc-fill-column)
  303. (length erc-fill-prefix)))))
  304. (setq to (prog1 (point-marker) (insert ">"))
  305. from (prog2 (goto-char from) (point-marker) (insert "<URL: ")))
  306. (let ((pos (copy-marker from)))
  307. (while (> (- to pos) fill-column)
  308. (goto-char (+ pos fill-column))
  309. (insert "\n" erc-fill-prefix) ; This ought to figure out
  310. ; what type of filling we're
  311. ; doing, and indent accordingly.
  312. (move-marker pos (point))))))
  313. (if nick-p
  314. (when erc-button-nickname-face
  315. (erc-button-add-face from to erc-button-nickname-face))
  316. (when erc-button-face
  317. (erc-button-add-face from to erc-button-face)))
  318. (add-text-properties
  319. from to
  320. (nconc (and erc-button-mouse-face
  321. (list 'mouse-face erc-button-mouse-face))
  322. (list 'erc-callback fun)
  323. (list 'keymap erc-button-keymap)
  324. (list 'rear-nonsticky t)
  325. (and data (list 'erc-data data))))
  326. (when (featurep 'xemacs)
  327. (widget-convert-button 'link from to :action 'erc-button-press-button
  328. :suppress-face t
  329. ;; Make XEmacs use our faces.
  330. :button-face (if nick-p
  331. erc-button-nickname-face
  332. erc-button-face)
  333. ;; Make XEmacs behave with mouse-clicks, for
  334. ;; some reason, widget stuff overrides the
  335. ;; 'keymap text-property.
  336. :mouse-down-action 'erc-button-click-button)))
  337. (defun erc-button-add-face (from to face)
  338. "Add FACE to the region between FROM and TO."
  339. ;; If we just use `add-text-property', then this will overwrite any
  340. ;; face text property already used for the button. It will not be
  341. ;; merged correctly. If we use overlays, then redisplay will be
  342. ;; very slow with lots of buttons. This is why we manually merge
  343. ;; face text properties.
  344. (let ((old (erc-list (get-text-property from 'face)))
  345. (pos from)
  346. (end (next-single-property-change from 'face nil to))
  347. new)
  348. ;; old is the face at pos, in list form. It is nil if there is no
  349. ;; face at pos. If nil, the new face is FACE. If not nil, the
  350. ;; new face is a list containing FACE and the old stuff. end is
  351. ;; where this face changes.
  352. (while (< pos to)
  353. (setq new (if old (cons face old) face))
  354. (put-text-property pos end 'face new)
  355. (setq pos end
  356. old (erc-list (get-text-property pos 'face))
  357. end (next-single-property-change pos 'face nil to)))))
  358. ;; widget-button-click calls with two args, we ignore the first.
  359. ;; Since Emacs runs this directly, rather than with
  360. ;; widget-button-click, we need to fake an extra arg in the
  361. ;; interactive spec.
  362. (defun erc-button-click-button (ignore event)
  363. "Call `erc-button-press-button'."
  364. (interactive "P\ne")
  365. (save-excursion
  366. (mouse-set-point event)
  367. (erc-button-press-button)))
  368. ;; XEmacs calls this via widget-button-press with a bunch of arguments
  369. ;; which we don't care about.
  370. (defun erc-button-press-button (&rest ignore)
  371. "Check text at point for a callback function.
  372. If the text at point has a `erc-callback' property,
  373. call it with the value of the `erc-data' text property."
  374. (interactive)
  375. (let* ((data (get-text-property (point) 'erc-data))
  376. (fun (get-text-property (point) 'erc-callback)))
  377. (unless fun
  378. (message "No button at point"))
  379. (when (and fun (symbolp fun) (not (fboundp fun)))
  380. (error "Function %S is not bound" fun))
  381. (apply fun data)))
  382. (defun erc-button-next-function ()
  383. "Pseudo completion function that actually jumps to the next button.
  384. For use on `completion-at-point-functions'."
  385. (when (< (point) (erc-beg-of-input-line))
  386. `(lambda ()
  387. (let ((here ,(point)))
  388. (while (and (get-text-property here 'erc-callback)
  389. (not (= here (point-max))))
  390. (setq here (1+ here)))
  391. (while (and (not (get-text-property here 'erc-callback))
  392. (not (= here (point-max))))
  393. (setq here (1+ here)))
  394. (if (< here (point-max))
  395. (goto-char here)
  396. (error "No next button"))
  397. t))))
  398. (defun erc-button-next ()
  399. "Go to the next button in this buffer."
  400. (interactive)
  401. (let ((f (erc-button-next-function)))
  402. (if f (funcall f))))
  403. (defun erc-button-previous ()
  404. "Go to the previous button in this buffer."
  405. (interactive)
  406. (let ((here (point)))
  407. (when (< here (erc-beg-of-input-line))
  408. (while (and (get-text-property here 'erc-callback)
  409. (not (= here (point-min))))
  410. (setq here (1- here)))
  411. (while (and (not (get-text-property here 'erc-callback))
  412. (not (= here (point-min))))
  413. (setq here (1- here)))
  414. (if (> here (point-min))
  415. (goto-char here)
  416. (error "No previous button"))
  417. t)))
  418. (defun erc-browse-emacswiki (thing)
  419. "Browse to thing in the emacs-wiki."
  420. (browse-url (concat erc-emacswiki-url thing)))
  421. (defun erc-browse-emacswiki-lisp (thing)
  422. "Browse to THING in the emacs-wiki elisp area."
  423. (browse-url (concat erc-emacswiki-lisp-url thing)))
  424. ;;; Nickname buttons:
  425. (defcustom erc-nick-popup-alist
  426. '(("DeOp" . (erc-cmd-DEOP nick))
  427. ("Kick" . (erc-cmd-KICK (concat nick " "
  428. (read-from-minibuffer
  429. (concat "Kick " nick ", reason: ")))))
  430. ("Msg" . (erc-cmd-MSG (concat nick " "
  431. (read-from-minibuffer
  432. (concat "Message to " nick ": ")))))
  433. ("Op" . (erc-cmd-OP nick))
  434. ("Query" . (erc-cmd-QUERY nick))
  435. ("Whois" . (erc-cmd-WHOIS nick))
  436. ("Lastlog" . (erc-cmd-LASTLOG nick)))
  437. "*An alist of possible actions to take on a nickname.
  438. An entry looks like (\"Action\" . SEXP) where SEXP is evaluated with
  439. the variable `nick' bound to the nick in question.
  440. Examples:
  441. (\"DebianDB\" .
  442. (shell-command
  443. (format
  444. \"ldapsearch -x -P 2 -h db.debian.org -b dc=debian,dc=org ircnick=%s\"
  445. nick)))"
  446. :group 'erc-button
  447. :type '(repeat (cons (string :tag "Op")
  448. sexp)))
  449. (defun erc-nick-popup (nick)
  450. (let* ((completion-ignore-case t)
  451. (action (completing-read (concat "What action to take on '" nick "'? ")
  452. erc-nick-popup-alist))
  453. (code (cdr (assoc action erc-nick-popup-alist))))
  454. (when code
  455. (erc-set-active-buffer (current-buffer))
  456. (eval code))))
  457. ;;; Callback functions
  458. (defun erc-button-describe-symbol (symbol-name)
  459. "Describe SYMBOL-NAME.
  460. Use `describe-function' for functions, `describe-variable' for variables,
  461. and `apropos' for other symbols."
  462. (let ((symbol (intern-soft symbol-name)))
  463. (cond ((and symbol (fboundp symbol))
  464. (describe-function symbol))
  465. ((and symbol (boundp symbol))
  466. (describe-variable symbol))
  467. (t (apropos symbol-name)))))
  468. (defun erc-button-beats-to-time (beats)
  469. "Display BEATS in a readable time format."
  470. (let* ((seconds (- (* (string-to-number beats) 86.4)
  471. 3600
  472. (- (car (current-time-zone)))))
  473. (hours (mod (floor seconds 3600) 24))
  474. (minutes (mod (round seconds 60) 60)))
  475. (message (format "@%s is %d:%02d local time"
  476. beats hours minutes))))
  477. (provide 'erc-button)
  478. ;;; erc-button.el ends here
  479. ;; Local Variables:
  480. ;; indent-tabs-mode: nil
  481. ;; End: