Removed aliases for encode-coding-string & decode-coding-string since
[riece] / lisp / riece-ctlseq.el
index 87729d5..bf3d4b3 100644 (file)
@@ -1,4 +1,4 @@
-;;; riece-ctlseq.el --- highlight control sequences in channel buffers
+;;; riece-ctlseq.el --- mark up control sequences in IRC buffers
 ;; Copyright (C) 1998-2004 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
-;; 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.
 
 ;;; Commentary:
 
-;; To use, add the following line to your ~/.riece/init.el:
-;; (add-to-list 'riece-addons 'riece-ctlseq)
+;; NOTE: This is an add-on module for Riece.
 
 ;;; Code:
 
-(require 'riece-highlight)
+(require 'riece-message)
+(require 'riece-misc)
 
-(defvar riece-ctlseq-colors
+(defgroup riece-ctlseq nil
+  "Mark up control sequences in IRC buffer."
+  :prefix "riece-"
+  :group 'riece)
+
+(defcustom riece-ctlseq-colors
   '("white" "black" "red" "orange" "yellow" "LightGreen" "DarkOliveGreen"
     "cyan4" "turquoise" "blue" "black" "black" "black" "black" "black"
-    "DarkBlue" "purple1" "purple2" "purple3" "magenta"))
+    "DarkBlue" "purple1" "purple2" "purple3" "magenta")
+  "List of colors can be used with ^C<fg>,<bg>."
+  :group 'riece-ctlseq
+  :type '(repeat (string :tag "Color")))
+
+(defcustom riece-ctlseq-hide-controls t
+  "If non-nil, control characters are hidden."
+  :group 'riece-ctlseq
+  :type 'boolean)
+
+(defcustom riece-ctlseq-face-cache-size 128
+  "Maximum length of the internal face cache."
+  :group 'riece-ctlseq
+  :type 'integer)
 
 (defvar riece-ctlseq-face-cache nil)
-(defvar riece-ctlseq-face-cache-size 128)
 (defvar riece-ctlseq-face-counter 0)
 
+(defconst riece-ctlseq-description
+  "Mark up control sequences in IRC buffers.")
+
 (defun riece-ctlseq-compatible-attributes-p (this other)
   (let ((pointer this))
     (catch 'mismatched
     attrs)))
 
 (defun riece-ctlseq-message-filter (message)
-  (let ((start 0)
-       (end (length (riece-message-text message)))
-       attrs)
-    (while (string-match
-           "[\x2\xF\x16\x1F]\\|\x3\\([0-9]+\\)?\\(,[0-9]+\\)?"
-           (riece-message-text message) start)
-      (put-text-property (match-beginning 0) (match-end 0)
-                        'invisible 'riece-ctlseq (riece-message-text message))
-      (if attrs
-         (put-text-property start (match-beginning 0)
-                            'riece-ctlseq-attributes (copy-sequence attrs)
-                            (riece-message-text message)))
-      (setq start (match-end 0)
-           attrs (riece-ctlseq-update-attributes
-                  (match-string 0 (riece-message-text message)) attrs)))
-    (if (and (< start end) attrs)
-       (put-text-property start end
-                          'riece-ctlseq-attributes (copy-sequence attrs)
-                          (riece-message-text message))))
+  (if (get 'riece-ctlseq 'riece-addon-enabled)
+      (let ((start 0)
+           (end (length (riece-message-text message)))
+           attrs)
+       (while (string-match
+               "[\x2\xF\x16\x1F]\\|\x3\\([0-9]+\\)?\\(,[0-9]+\\)?"
+               (riece-message-text message) start)
+         (if riece-ctlseq-hide-controls
+             (put-text-property (match-beginning 0) (match-end 0)
+                                'invisible 'riece-ctlseq
+                                (riece-message-text message)))
+         (if attrs
+             (put-text-property start (match-beginning 0)
+                                'riece-ctlseq-attributes (copy-sequence attrs)
+                                (riece-message-text message)))
+         (setq start (match-end 0)
+               attrs (riece-ctlseq-update-attributes
+                      (match-string 0 (riece-message-text message)) attrs)))
+       (if (and (< start end) attrs)
+           (put-text-property start end
+                              'riece-overlay-face
+                              (riece-ctlseq-face-from-cache attrs)
+                              (riece-message-text message)))))
   message)
 
-(defun riece-ctlseq-scan-region (start end)
-  (riece-scan-property-region
-   'riece-ctlseq-attributes
-   start end
-   (lambda (start end)
-     (riece-overlay-put (riece-make-overlay start end)
-                       'face
-                       (riece-ctlseq-face-from-cache
-                        (get-text-property start
-                                           'riece-ctlseq-attributes))))))
-
 (defun riece-ctlseq-requires ()
   '(riece-highlight))
-                           
+
 (defun riece-ctlseq-insinuate ()
-  (add-hook 'riece-message-filter-functions 'riece-ctlseq-message-filter)
-  (add-hook 'riece-after-insert-functions 'riece-ctlseq-scan-region))
+  (add-hook 'riece-message-filter-functions 'riece-ctlseq-message-filter))
+
+(defun riece-ctlseq-uninstall ()
+  (remove-hook 'riece-message-filter-functions 'riece-ctlseq-message-filter))
 
 (provide 'riece-ctlseq)