Don't use old-style backquote in doc/ptexinfmt.el.
[riece] / lisp / riece-alias.el
index 9a45bd8..f2bb695 100644 (file)
@@ -1,4 +1,4 @@
-;;; riece-alias.el --- define aliases of names
+;;; riece-alias.el --- define aliases for IRC names
 ;; Copyright (C) 1998-2003 Daiki Ueno
 
 ;; Author: Daiki Ueno <ueno@unixuser.org>
 ;; Copyright (C) 1998-2003 Daiki Ueno
 
 ;; Author: Daiki Ueno <ueno@unixuser.org>
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 
-;; This add-on allows you to define aliases for IRC names.
+;;; Commentary:
+
+;; NOTE: This is an add-on module for Riece.
 
 
-;; To use, add the following line to your ~/.riece/init.el:
-;; (add-to-list 'riece-addons 'riece-alias)
+;; This add-on allows you to define aliases for IRC names.
 
 
-;; For example, if you want to define an alias `#l' for `#Liece', you
+;; For example, if you want to define an alias `#r' for `#riece', you
 ;; can customize riece-alias-alist as follows:
 ;; can customize riece-alias-alist as follows:
-;; (setq riece-alias-alist '(("#Liece" . "#l")))
+;; (setq riece-alias-alist '(("#riece" . "#r")))
 
 ;;; Code:
 
 
 ;;; Code:
 
@@ -36,7 +37,7 @@
 (require 'riece-signal)
 
 (defgroup riece-alias nil
 (require 'riece-signal)
 
 (defgroup riece-alias nil
-  "Define aliases of names"
+  "Aliases of channel/user names."
   :prefix "riece-"
   :group 'riece)
 
   :prefix "riece-"
   :group 'riece)
 
@@ -50,7 +51,7 @@
   :type 'boolean
   :group 'riece-alias)
 
   :type 'boolean
   :group 'riece-alias)
 
-(defcustom riece-alias-alternate-separator nil
+(defcustom riece-alias-alternate-separator "@"
   "A string to separate prefix and server."
   :type '(choice (const nil) string)
   :group 'riece-alias)
   "A string to separate prefix and server."
   :type '(choice (const nil) string)
   :group 'riece-alias)
   :type 'list
   :group 'riece-alias)
 
   :type 'list
   :group 'riece-alias)
 
-(defvar riece-alias-enabled nil)
-
 (defconst riece-alias-description
 (defconst riece-alias-description
-  "Define aliases of channel/user names")
+  "Define aliases for IRC names.")
 
 (defun riece-alias-abbrev-percent-hack (string)
   (if (string-match (concat "^#\\([^ ]+\\):"
 
 (defun riece-alias-abbrev-percent-hack (string)
   (if (string-match (concat "^#\\([^ ]+\\):"
 (defun riece-alias-expand-alternate-separator (string)
   (let ((index 0)
        prefix
 (defun riece-alias-expand-alternate-separator (string)
   (let ((index 0)
        prefix
-       server
-       length)
+       server)
     (while (and (null prefix)
                (string-match
     (while (and (null prefix)
                (string-match
-                (concat "\\("
+                (concat (regexp-quote riece-alias-alternate-separator)
+                        (regexp-quote riece-alias-alternate-separator)
+                        "\\|\\("
                         (regexp-quote riece-alias-alternate-separator)
                         (regexp-quote riece-alias-alternate-separator)
-                        "\\)+")
+                        "\\)")
                 string index))
                 string index))
-      (setq length (/ (- (match-end 0) (match-beginning 0))
-                     (length riece-alias-alternate-separator))
-           string (replace-match
-                   (mapconcat #'identity
-                              (make-list (/ length 2)
-                                         riece-alias-alternate-separator)
-                              "")
-                   nil t string)
-           index (+ (match-beginning 0)
-                    (* (/ length 2)
-                       (length riece-alias-alternate-separator))))
-      (unless (zerop (% length 2))
-       (setq prefix (substring string 0 index))))
+      (if (match-beginning 1)          ;found a separator
+         (setq prefix (substring string 0 (match-beginning 1))
+               index (match-end 1))
+       (setq string (replace-match riece-alias-alternate-separator
+                                   nil t string)
+             index (- (match-end 0)
+                      (length riece-alias-alternate-separator)))))
     (if (null prefix)
        string
       (setq server (substring string index)
     (if (null prefix)
        string
       (setq server (substring string index)
                                (concat riece-alias-alternate-separator
                                        riece-alias-alternate-separator))
                               server index)
                                (concat riece-alias-alternate-separator
                                        riece-alias-alternate-separator))
                               server index)
-           (setq server (replace-match
-                         riece-alias-alternate-separator
-                         nil t server)
-                 index (1- (match-end 0))))
+           (setq server (replace-match riece-alias-alternate-separator
+                                       nil t server)
+                 index (- (match-end 0)
+                          (length riece-alias-alternate-separator))))
        (concat prefix " " server)))))
 
 (defun riece-alias-abbrev-identity-string (string)
        (concat prefix " " server)))))
 
 (defun riece-alias-abbrev-identity-string (string)
   (if riece-alias-alternate-separator
       (setq string (riece-alias-abbrev-alternate-separator string)))
   (let ((alist riece-alias-alist))
   (if riece-alias-alternate-separator
       (setq string (riece-alias-abbrev-alternate-separator string)))
   (let ((alist riece-alias-alist))
-    (catch 'done
-      (while alist
-       (if (equal (car (car alist)) string)
-           (throw 'done (cdr (car alist))))
-       (setq alist (cdr alist)))
-      string)))
+    (while alist
+      (if (equal (downcase (car (car alist))) (downcase string))
+         (setq string (cdr (car alist))
+               alist nil)
+       (setq alist (cdr alist)))))
+  (copy-sequence string))
 
 (defun riece-alias-expand-identity-string (string)
   (let ((alist riece-alias-alist))
 
 (defun riece-alias-expand-identity-string (string)
   (let ((alist riece-alias-alist))
-    (catch 'done
-      (while alist
-       (if (equal (cdr (car alist)) string)
-           (throw 'done (car (car alist))))
-       (setq alist (cdr alist)))
-      string))
+    (while alist
+      (if (equal (downcase (cdr (car alist))) (downcase string))
+         (setq string (car (car alist))
+               alist nil)
+       (setq alist (cdr alist)))))
   (if riece-alias-alternate-separator
       (setq string (riece-alias-expand-alternate-separator string)))
   (if riece-alias-enable-percent-hack
   (if riece-alias-alternate-separator
       (setq string (riece-alias-expand-alternate-separator string)))
   (if riece-alias-enable-percent-hack
-      (setq string (riece-alias-expand-percent-hack string))))
+      (setq string (riece-alias-expand-percent-hack string)))
+  (copy-sequence string))
 
 (defun riece-alias-insinuate ()
   )
 
 (defun riece-alias-insinuate ()
   )
        #'riece-alias-abbrev-identity-string
        riece-expand-identity-string-function
        #'riece-alias-expand-identity-string)
        #'riece-alias-abbrev-identity-string
        riece-expand-identity-string-function
        #'riece-alias-expand-identity-string)
-  (riece-emit-signal 'channel-list-changed)
-  (setq riece-alias-enabled t))
+  (riece-emit-signal 'channel-list-changed))
 
 (defun riece-alias-disable ()
   (setq riece-abbrev-identity-string-function nil
        riece-expand-identity-string-function nil)
 
 (defun riece-alias-disable ()
   (setq riece-abbrev-identity-string-function nil
        riece-expand-identity-string-function nil)
-  (riece-emit-signal 'channel-list-changed)
-  (setq riece-alias-enabled nil))
+  (riece-emit-signal 'channel-list-changed))
 
 (provide 'riece-alias)
 
 
 (provide 'riece-alias)