1 ;;; riece-alias.el --- define aliases for IRC names
2 ;; Copyright (C) 1998-2003 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Keywords: IRC, riece
7 ;; This file is part of Riece.
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)
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.
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., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
26 ;; NOTE: This is an add-on module for Riece.
28 ;; This add-on allows you to define aliases for IRC names.
30 ;; For example, if you want to define an alias `#r' for `#riece', you
31 ;; can customize riece-alias-alist as follows:
32 ;; (setq riece-alias-alist '(("#riece" . "#r")))
36 (require 'riece-identity)
37 (require 'riece-signal)
39 (defgroup riece-alias nil
40 "Aliases of channel/user names."
44 (defcustom riece-alias-percent-hack-mask "*.jp"
45 "The mask of local IRC network"
49 (defcustom riece-alias-enable-percent-hack t
50 "If non-nil, the target mask is abbreviated with `%'."
54 (defcustom riece-alias-alternate-separator "@"
55 "A string to separate prefix and server."
56 :type '(choice (const nil) string)
59 (defcustom riece-alias-alist nil
60 "An alist mapping aliases to names."
64 (defconst riece-alias-description
65 "Define aliases for IRC names.")
67 (defun riece-alias-abbrev-percent-hack (string)
68 (if (string-match (concat "^#\\([^ ]+\\):"
69 (regexp-quote riece-alias-percent-hack-mask)
72 (replace-match "%\\1\\2" nil nil string)
75 (defun riece-alias-expand-percent-hack (string)
76 (if (string-match "^%\\([^ ]+\\)\\( .+\\|$\\)" string)
77 (replace-match (concat "#\\1:" riece-alias-percent-hack-mask "\\2")
81 (defun riece-alias-escape-alternate-separator (string)
83 (while (string-match (regexp-quote riece-alias-alternate-separator)
85 (setq index (1+ (match-end 0))
86 string (replace-match (concat riece-alias-alternate-separator
87 riece-alias-alternate-separator)
91 (defun riece-alias-abbrev-alternate-separator (string)
92 (if (string-match " " string)
93 (let ((prefix (substring string 0 (match-beginning 0)))
94 (server (substring string (match-end 0))))
95 (concat (riece-alias-escape-alternate-separator prefix)
96 riece-alias-alternate-separator
97 (riece-alias-escape-alternate-separator server)))
98 (riece-alias-escape-alternate-separator string)))
100 (defun riece-alias-expand-alternate-separator (string)
104 (while (and (null prefix)
106 (concat (regexp-quote riece-alias-alternate-separator)
107 (regexp-quote riece-alias-alternate-separator)
109 (regexp-quote riece-alias-alternate-separator)
112 (if (match-beginning 1) ;found a separator
113 (setq prefix (substring string 0 (match-beginning 1))
115 (setq string (replace-match riece-alias-alternate-separator
117 index (- (match-end 0)
118 (length riece-alias-alternate-separator)))))
121 (setq server (substring string index)
123 (if (equal server "")
124 (while (string-match (regexp-quote
125 (concat riece-alias-alternate-separator
126 riece-alias-alternate-separator))
128 (setq server (replace-match riece-alias-alternate-separator
130 index (- (match-end 0)
131 (length riece-alias-alternate-separator))))
132 (concat prefix " " server)))))
134 (defun riece-alias-abbrev-identity-string (string)
135 (if riece-alias-enable-percent-hack
136 (setq string (riece-alias-abbrev-percent-hack string)))
137 (if riece-alias-alternate-separator
138 (setq string (riece-alias-abbrev-alternate-separator string)))
139 (let ((alist riece-alias-alist))
141 (if (equal (downcase (car (car alist))) (downcase string))
142 (setq string (cdr (car alist))
144 (setq alist (cdr alist)))))
145 (copy-sequence string))
147 (defun riece-alias-expand-identity-string (string)
148 (let ((alist riece-alias-alist))
150 (if (equal (downcase (cdr (car alist))) (downcase string))
151 (setq string (car (car alist))
153 (setq alist (cdr alist)))))
154 (if riece-alias-alternate-separator
155 (setq string (riece-alias-expand-alternate-separator string)))
156 (if riece-alias-enable-percent-hack
157 (setq string (riece-alias-expand-percent-hack string)))
158 (copy-sequence string))
160 (defun riece-alias-insinuate ()
163 (defun riece-alias-enable ()
164 (setq riece-abbrev-identity-string-function
165 #'riece-alias-abbrev-identity-string
166 riece-expand-identity-string-function
167 #'riece-alias-expand-identity-string)
168 (riece-emit-signal 'channel-list-changed))
170 (defun riece-alias-disable ()
171 (setq riece-abbrev-identity-string-function nil
172 riece-expand-identity-string-function nil)
173 (riece-emit-signal 'channel-list-changed))
175 (provide 'riece-alias)
177 ;;; riece-alias.el ends here