Add description about riece-doctor.
[riece] / lisp / riece-alias.el
1 ;;; riece-alias.el --- define aliases of names
2 ;; Copyright (C) 1998-2003 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Keywords: IRC, riece
6
7 ;; This file is part of Riece.
8
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;; This add-on allows you to define aliases for IRC names.
25
26 ;; To use, add the following line to your ~/.riece/init.el:
27 ;; (add-to-list 'riece-addons 'riece-alias)
28
29 ;; For example, if you want to define an alias `#l' for `#Liece', you
30 ;; can customize riece-alias-alist as follows:
31 ;; (setq riece-alias-alist '(("#Liece" . "#l")))
32
33 ;;; Code:
34
35 (defgroup riece-alias nil
36   "Define aliases of names"
37   :prefix "riece-"
38   :group 'riece)
39
40 (defcustom riece-alias-percent-hack-mask "*.jp"
41   "The mask of local IRC network"
42   :type 'string
43   :group 'riece-alias)
44
45 (defcustom riece-alias-enable-percent-hack t
46   "If non-nil, the target mask is abbreviated with `%'."
47   :type 'boolean
48   :group 'riece-alias)
49
50 (defcustom riece-alias-alist nil
51   "An alist mapping aliases to names."
52   :type 'list
53   :group 'riece-alias)
54
55 (defun riece-alias-abbrev-percent-hack (string)
56   (if (string-match (concat "^#\\([^ ]+\\):"
57                             (regexp-quote riece-alias-percent-hack-mask)
58                             "\\( .+\\|$\\)")
59                     string)
60       (replace-match "%\\1\\2" nil nil string)
61     string))
62
63 (defun riece-alias-expand-percent-hack (string)
64   (if (string-match "^%\\([^ ]+\\)\\( .+\\|$\\)" string)
65       (replace-match (concat "#\\1:" riece-alias-percent-hack-mask "\\2")
66                      nil nil string)
67     string))
68
69 (defun riece-alias-abbrev-identity-string (string)
70   (if riece-alias-enable-percent-hack
71       (setq string (riece-alias-abbrev-percent-hack string)))
72   (let ((alist riece-alias-alist))
73     (catch 'done
74       (while alist
75         (if (equal (car (car alist)) string)
76             (throw 'done (cdr (car alist))))
77         (setq alist (cdr alist)))
78       string)))
79
80 (defun riece-alias-expand-identity-string (string)
81   (if riece-alias-enable-percent-hack
82       (setq string (riece-alias-expand-percent-hack string)))
83   (let ((alist riece-alias-alist))
84     (catch 'done
85       (while alist
86         (if (equal (cdr (car alist)) string)
87             (throw 'done (car (car alist))))
88         (setq alist (cdr alist)))
89       string)))
90
91 (defun riece-alias-insinuate ()
92   (setq riece-abbrev-identity-string-function
93         #'riece-alias-abbrev-identity-string
94         riece-expand-identity-string-function
95         #'riece-alias-expand-identity-string))
96
97 (provide 'riece-alias)
98
99 ;;; riece-alias.el ends here