Initial Commit
[packages] / xemacs-packages / zenirc / src / zenirc-format.el
1 ;;; zenirc-format.el --- format nick!user@host for zenirc
2
3 ;; Copyright (C) 1993, 1994 Ben A. Mesander
4 ;; Copyright (C) 1995 Noah S. Friedman
5
6 ;; Author: Ben A. Mesander <ben@gnu.ai.mit.edu>
7 ;;         Charles Hannum <mycroft@gnu.ai.mit.edu>
8 ;;         Richard Todd <rmtodd@essex.ecn.uoknor.edu>
9 ;;         Noah Friedman <friedman@prep.ai.mit.edu>
10 ;; Maintainer: friedman@prep.ai.mit.edu
11 ;; Keywords: zenirc, extensions
12 ;; Created: 1993/06/03
13
14 ;; This program is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; any later version.
18 ;;
19 ;; This program is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 ;; GNU General Public License for more details.
23 ;;
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with this program; if not, you can either send email to this
26 ;; program's maintainer or write to: The Free Software Foundation,
27 ;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.
28
29 ;;; Commentary:
30
31 ;; Format nick!user@host info the first time you see someone as
32 ;; nick!user@host and thereafter as just nick.  Nick changes are detected
33 ;; and handled correctly.
34
35 ;; This was rewritten 1995-03-18 by friedman to use a hash table instead of
36 ;; an alist.
37
38 ;;; Code:
39
40 (require 'zenirc)
41
42 ;; 101 buckets should be a reasonable size for most people (remember to use
43 ;; a prime number to get good hashing characteristics).
44 ;; This is not the total number of nicks you can cache, but just the number
45 ;; of "buckets" in which nicks can be stored.  If you talk to thousands
46 ;; and thousands of people it might help to increase the size of this
47 ;; table, but even then it isn't necessary.
48 (defvar zenirc-nickuserhost-table (make-vector 101 0)
49   "Table used to store nicknames and corresponding nick!user@host.")
50
51 (defun zenirc-format-nickuserhost-fancy (nickuserhost)
52   (let ((nick (zenirc-extract-nick nickuserhost)))
53     (if nick
54         (let* ((nicksym (intern (zenirc-downcase-name nick)
55                                 zenirc-nickuserhost-table))
56                (cached (and (boundp nicksym)
57                             (symbol-value nicksym))))
58           ; possible BUG
59           (setq zenirc-run-next-hook nil)
60           (set nicksym nickuserhost)
61           (and cached
62                (string= cached nickuserhost)
63                (setq nickuserhost nick)))))
64   nickuserhost)
65
66 (zenirc-add-hook 'zenirc-format-nickuserhost-hook
67                  'zenirc-format-nickuserhost-fancy)
68
69 (defun zenirc-fancy-NICK (proc parsedmsg)
70   (let* ((userhost (zenirc-extract-userhost (aref parsedmsg 1)))
71          (to (aref parsedmsg 2)))
72     (set (intern (zenirc-downcase-name to) zenirc-nickuserhost-table)
73          (concat to "!" userhost))))
74
75 (zenirc-add-hook 'zenirc-server-NICK-hook 'zenirc-fancy-NICK)
76
77 ;; Also hook into the /who display.
78 ;; (added by rmtodd, rewritten by friedman)
79 (defun zenirc-fancy-352 (proc parsedmsg)
80   ;; If the 3 arg is "Channel", this is the header.
81   ;; One wonders why the header isn't a different numeric.
82   (or (string= (aref parsedmsg 3) "Channel")
83       (let* ((nick (aref parsedmsg 7))
84              (nickuserhost (concat nick "!" (aref parsedmsg 4) "@"
85                                    (aref parsedmsg 5)))
86              (nicksym (intern (zenirc-downcase-name nick)
87                               zenirc-nickuserhost-table)))
88         (set nicksym nickuserhost))))
89
90 \f
91 (zenirc-add-hook 'zenirc-server-352-hook 'zenirc-fancy-352)
92
93 (provide 'zenirc-format)
94
95 ;; zenirc-format.el ends here