]> code.delx.au - gnu-emacs/blobdiff - lisp/ansi-color.el
Add a provide statement.
[gnu-emacs] / lisp / ansi-color.el
index 10503df7ae765e4a390add807fd7a770bd2629f7..30350d69a9afd4e3a7dd1e96f81cfaacceaa0137 100644 (file)
@@ -4,8 +4,8 @@
 
 ;; Author: Alex Schroeder <alex@gnu.org>
 ;; Maintainer: Alex Schroeder <alex@gnu.org>
-;; Version: 3.4.0
-;; Keywords: comm processes
+;; Version: 3.4.2
+;; Keywords: comm processes terminals services
 
 ;; This file is part of GNU Emacs.
 
@@ -46,7 +46,6 @@
 ;;
 ;; If you decide you like this, add the following to your .emacs file:
 ;;
-;; (autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
 ;; (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
 ;;
 ;; SGR control sequences are defined in section 3.8.117 of the ECMA-48
@@ -172,12 +171,12 @@ in shell buffers.  You set this variable by calling one of:
 \\[ansi-color-for-comint-mode-on]
 \\[ansi-color-for-comint-mode-off]
 \\[ansi-color-for-comint-mode-filter]"
-  :version "20.8"
   :type '(choice (const :tag "Do nothing" nil)
                 (const :tag "Filter" filter)
                 (const :tag "Translate" t))
   :group 'ansi-colors)
 
+;;;###autoload
 (defun ansi-color-for-comint-mode-on ()
   "Set `ansi-color-for-comint-mode' to t."
   (interactive)
@@ -193,6 +192,7 @@ in shell buffers.  You set this variable by calling one of:
   (interactive)
   (setq ansi-color-for-comint-mode 'filter))
 
+;;;###autoload
 (defun ansi-color-process-output (string)
   "Maybe translate SGR control sequences of comint output into text-properties.
 
@@ -218,29 +218,32 @@ This is a good function to put in `comint-output-filter-functions'."
          'ansi-color-process-output)
 
 
-;; Alternative font-lock-unfontify-region-function
+;; Alternative font-lock-unfontify-region-function for Emacs only
 
 
 (eval-when-compile
 ;; We use this to preserve or protect things when modifying text
 ;; properties.  Stolen from lazy-lock and font-lock.  Ugly!!!
 ;; Probably most of this is not needed?
 (defmacro save-buffer-state (varlist &rest body)
-    "Bind variables according to VARLIST and eval BODY restoring buffer state."
-    (` (let* ((,@ (append varlist
-                  '((modified (buffer-modified-p)) (buffer-undo-list t)
-                    (inhibit-read-only t) (inhibit-point-motion-hooks t)
-                    before-change-functions after-change-functions
-                    deactivate-mark buffer-file-name buffer-file-truename))))
-        (,@ body)
-        (when (and (not modified) (buffer-modified-p))
-          (set-buffer-modified-p nil)))))
 (put 'save-buffer-state 'lisp-indent-function 1))
+ ;; We use this to preserve or protect things when modifying text
+ ;; properties.  Stolen from lazy-lock and font-lock.  Ugly!!!
+ ;; Probably most of this is not needed?
+ (defmacro save-buffer-state (varlist &rest body)
+   "Bind variables according to VARLIST and eval BODY restoring buffer state."
+   `(let* (,@(append varlist
+                     '((modified (buffer-modified-p)) (buffer-undo-list t)
+                       (inhibit-read-only t) (inhibit-point-motion-hooks t)
+                       before-change-functions after-change-functions
+                       deactivate-mark buffer-file-name buffer-file-truename)))
+     ,@body
+     (when (and (not modified) (buffer-modified-p))
+       (set-buffer-modified-p nil))))
+ (put 'save-buffer-state 'lisp-indent-function 1))
 
 (defun ansi-color-unfontify-region (beg end &rest xemacs-stuff)
-  "Replacement function for `font-lock-default-unfontify-region'.  
-When font-lock is active in a buffer, you cannot simply add face
-text-properties to the buffer.  Font-lock will remove the face
+  "Replacement function for `font-lock-default-unfontify-region'.
+
+As text-properties are implemented using extents in XEmacs, this
+function is probably not needed.  In Emacs, however, things are a bit
+different: When font-lock is active in a buffer, you cannot simply add
+face text-properties to the buffer.  Font-lock will remove the face
 text-property using `font-lock-unfontify-region-function'.  If you want
 to insert the strings returned by `ansi-color-apply' into such buffers,
 you must set `font-lock-unfontify-region-function' to
@@ -411,7 +414,7 @@ information will be used for the next call to
 start of the region and set the face with which to start.  Set
 `ansi-color-context-region' to nil if you don't want this."
   (let ((face (car ansi-color-context-region))
-       (start-marker (or (cadr ansi-color-context-region) 
+       (start-marker (or (cadr ansi-color-context-region)
                          (copy-marker begin)))
        (end-marker (copy-marker end))
        escape-sequence)
@@ -477,7 +480,7 @@ start of the region and set the face with which to start.  Set
 
 (defun ansi-color-make-face (property color)
   "Return a face with PROPERTY set to COLOR.
-PROPERTY can be either symbol `foreground' or symbol `background'.  
+PROPERTY can be either symbol `foreground' or symbol `background'.
 
 For Emacs, we just return the cons cell \(PROPERTY . COLOR).
 For XEmacs, we create a temporary face and return it."
@@ -550,7 +553,13 @@ case we return nil."
          ((eq (car new-faces) 'default)
           (cdr new-faces))
          (t
-          (append new-faces face)))))
+          ;; Like (append NEW-FACES FACES)
+          ;; but delete duplicates in FACES.
+          (let ((modified-faces (copy-sequence faces)))
+            (dolist (face (nreverse new-faces))
+              (setq modified-faces (delete face modified-faces))
+              (push face modified-faces))
+            modified-faces)))))
 
 (defun ansi-color-make-color-map ()
   "Creates a vector of face definitions and returns it.
@@ -633,9 +642,11 @@ ESCAPE-SEQ is a SGR control sequences such as \\033[34m.  The parameter
            ((eq val 'default)
             (setq f (list val)))
            (t
-            (add-to-list 'f val))))
+            (unless (member val f)
+              (push val f)))))
     f))
 
 (provide 'ansi-color)
 
+;;; arch-tag: 00726118-9432-44fd-b72d-d2af7591c99c
 ;;; ansi-color.el ends here