X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/c04c01ca0d0e491855e55bcfd16a49dbd0f779a9..9478502212bb8eea71a5d96805fe40f3c9d29561:/lisp/ansi-color.el diff --git a/lisp/ansi-color.el b/lisp/ansi-color.el index 9b022876ca..58eed04f14 100644 --- a/lisp/ansi-color.el +++ b/lisp/ansi-color.el @@ -1,7 +1,7 @@ ;;; ansi-color.el --- translate ANSI escape sequences into faces ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, -;; 2005, 2006, 2007 Free Software Foundation, Inc. +;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. ;; Author: Alex Schroeder ;; Maintainer: Alex Schroeder @@ -10,20 +10,18 @@ ;; This file is part of GNU Emacs. -;; GNU Emacs is free software; you can redistribute it and/or modify it -;; under the terms of the GNU General Public License as published by the -;; Free Software Foundation; either version 3, or (at your option) any -;; later version. -;; -;; GNU Emacs is distributed in the hope that it will be useful, but -;; WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -;; General Public License for more details. -;; +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + ;; 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., 51 Franklin Street, Fifth Floor, -;; Boston, MA 02110-1301, USA. +;; along with GNU Emacs. If not, see . ;;; Commentary: @@ -32,23 +30,15 @@ ;; known as ANSI escape sequences) and tries to translate these into ;; faces. ;; -;; This allows you to run ls --color=yes in shell-mode. In order to -;; test this, proceed as follows: -;; -;; 1. start a shell: M-x shell -;; 2. load this file: M-x load-library RET ansi-color RET -;; 3. activate ansi-color: M-x ansi-color-for-comint-mode-on -;; 4. test ls --color=yes in the *shell* buffer +;; This allows you to run ls --color=yes in shell-mode. It is now +;; enabled by default; to disable it, set ansi-color-for-comint-mode +;; to nil. ;; ;; Note that starting your shell from within Emacs might set the TERM ;; environment variable. The new setting might disable the output of ;; SGR control sequences. Using ls --color=yes forces ls to produce ;; these. ;; -;; If you decide you like this, add the following to your .emacs file: -;; -;; (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 ;; standard (identical to ISO/IEC 6429), which is freely available as a ;; PDF file . The @@ -149,7 +139,7 @@ map. This color map is stored in the variable `ansi-color-map'." :initialize 'custom-initialize-default :group 'ansi-colors) -(defconst ansi-color-regexp "\033\\[\\([0-9;]*\\)m" +(defconst ansi-color-regexp "\033\\[\\([0-9;]*m\\)" "Regexp that matches SGR control sequences.") (defconst ansi-color-parameter-regexp "\\([0-9]*\\)[m;]" @@ -159,7 +149,7 @@ map. This color map is stored in the variable `ansi-color-map'." ;; Convenience functions for comint modes (eg. shell-mode) -(defcustom ansi-color-for-comint-mode nil +(defcustom ansi-color-for-comint-mode t "Determines what to do with comint output. If nil, do nothing. If the symbol `filter', then filter all SGR control sequences. @@ -177,7 +167,8 @@ in shell buffers. You set this variable by calling one of: :type '(choice (const :tag "Do nothing" nil) (const :tag "Filter" filter) (const :tag "Translate" t)) - :group 'ansi-colors) + :group 'ansi-colors + :version "23.2") ;;;###autoload (defun ansi-color-for-comint-mode-on () @@ -196,7 +187,7 @@ in shell buffers. You set this variable by calling one of: (setq ansi-color-for-comint-mode 'filter)) ;;;###autoload -(defun ansi-color-process-output (string) +(defun ansi-color-process-output (ignored) "Maybe translate SGR control sequences of comint output into text-properties. Depending on variable `ansi-color-for-comint-mode' the comint output is @@ -513,7 +504,7 @@ property." (defun ansi-color-set-extent-face (extent face) "Set the `face' property of EXTENT to FACE. XEmacs uses `set-extent-face', Emacs uses `overlay-put'." - (if (fboundp 'set-extent-face) + (if (featurep 'xemacs) (set-extent-face extent face) (overlay-put extent 'face face))) @@ -606,7 +597,7 @@ property of `ansi-color-faces-vector' and `ansi-color-names-vector'." ANSI-CODE is used as an index into the vector." (condition-case nil (aref ansi-color-map ansi-code) - ('args-out-of-range nil))) + (args-out-of-range nil))) (defun ansi-color-get-face (escape-seq) "Create a new face by applying all the parameters in ESCAPE-SEQ. @@ -616,13 +607,12 @@ the parameter 0), then the effect of all previous parameters is cancelled. ESCAPE-SEQ is a SGR control sequences such as \\033[34m. The parameter 34 is used by `ansi-color-get-face-1' to return a face definition." - (let ((ansi-color-r "[0-9][0-9]?") - (i 0) + (let ((i 0) f val) - (while (string-match ansi-color-r escape-seq i) + (while (string-match ansi-color-parameter-regexp escape-seq i) (setq i (match-end 0) val (ansi-color-get-face-1 - (string-to-number (match-string 0 escape-seq) 10))) + (string-to-number (match-string 1 escape-seq) 10))) (cond ((not val)) ((eq val 'default) (setq f (list val))) @@ -633,5 +623,5 @@ ESCAPE-SEQ is a SGR control sequences such as \\033[34m. The parameter (provide 'ansi-color) -;;; arch-tag: 00726118-9432-44fd-b72d-d2af7591c99c +;; arch-tag: 00726118-9432-44fd-b72d-d2af7591c99c ;;; ansi-color.el ends here