aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuanma Barranquero2013-06-20 03:03:57 +0200
committerJuanma Barranquero2013-06-20 03:03:57 +0200
commita5c581d827ff911a01226ca2ab99dc9eded29618 (patch)
tree5e27a5bed27c7c167eb024c64cfa096f4c096e72
parent5fc0acc0f5f3c6d24c36580b0c0eb77c4c5adc89 (diff)
downloademacs-a5c581d827ff911a01226ca2ab99dc9eded29618.tar.gz
emacs-a5c581d827ff911a01226ca2ab99dc9eded29618.zip
lisp/ansi-color.el: Convert to lexical binding.
(ansi-colors): Fix URL. (ansi-color-context, ansi-color-context-region): Use defvar-local. (ansi-color-apply-sequence, ansi-color-map): Fix typos in docstrings. (ansi-color-make-color-map): Rename local var ansi-color-map to map.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/ansi-color.el39
2 files changed, 26 insertions, 19 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a62df19a480..748b8ca5939 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,11 @@
12013-06-20 Juanma Barranquero <lekktu@gmail.com> 12013-06-20 Juanma Barranquero <lekktu@gmail.com>
2 2
3 * ansi-color.el: Convert to lexical binding.
4 (ansi-colors): Fix URL.
5 (ansi-color-context, ansi-color-context-region): Use defvar-local.
6 (ansi-color-apply-sequence, ansi-color-map): Fix typos in docstrings.
7 (ansi-color-make-color-map): Rename local var ansi-color-map to map.
8
3 * progmodes/prog-mode.el (prettify-symbols-mode) 9 * progmodes/prog-mode.el (prettify-symbols-mode)
4 (global-prettify-symbols-mode, prog-mode): Remove autoload cookies. 10 (global-prettify-symbols-mode, prog-mode): Remove autoload cookies.
5 11
diff --git a/lisp/ansi-color.el b/lisp/ansi-color.el
index 042bcfb3223..bbe44f9b20b 100644
--- a/lisp/ansi-color.el
+++ b/lisp/ansi-color.el
@@ -1,4 +1,4 @@
1;;; ansi-color.el --- translate ANSI escape sequences into faces 1;;; ansi-color.el --- translate ANSI escape sequences into faces -*- lexical-binding: t -*-
2 2
3;; Copyright (C) 1999-2013 Free Software Foundation, Inc. 3;; Copyright (C) 1999-2013 Free Software Foundation, Inc.
4 4
@@ -84,8 +84,9 @@
84This translation effectively colorizes strings and regions based upon 84This translation effectively colorizes strings and regions based upon
85SGR control sequences embedded in the text. SGR (Select Graphic 85SGR control sequences embedded in the text. SGR (Select Graphic
86Rendition) control sequences are defined in section 8.3.117 of the 86Rendition) control sequences are defined in section 8.3.117 of the
87ECMA-48 standard \(identical to ISO/IEC 6429), which is freely available 87ECMA-48 standard (identical to ISO/IEC 6429), which is freely available
88as a PDF file <URL:http://www.ecma.ch/ecma1/STAND/ECMA-048.HTM>." 88at <URL:http://www.ecma-international.org/publications/standards/Ecma-048.htm>
89as a PDF file."
89 :version "21.1" 90 :version "21.1"
90 :group 'processes) 91 :group 'processes)
91 92
@@ -119,7 +120,7 @@ map. This color map is stored in the variable `ansi-color-map'."
119 ["black" "red" "green" "yellow" "blue" "magenta" "cyan" "white"] 120 ["black" "red" "green" "yellow" "blue" "magenta" "cyan" "white"]
120 "Colors used for SGR control sequences determining a color. 121 "Colors used for SGR control sequences determining a color.
121This vector holds the colors used for SGR control sequences parameters 122This vector holds the colors used for SGR control sequences parameters
12230 to 37 \(foreground colors) and 40 to 47 (background colors). 12330 to 37 (foreground colors) and 40 to 47 (background colors).
123 124
124Parameter Color 125Parameter Color
125 30 40 black 126 30 40 black
@@ -234,14 +235,13 @@ This is a good function to put in `comint-output-filter-functions'."
234 'font-lock-default-unfontify-region "24.1") 235 'font-lock-default-unfontify-region "24.1")
235 236
236;; Working with strings 237;; Working with strings
237(defvar ansi-color-context nil 238(defvar-local ansi-color-context nil
238 "Context saved between two calls to `ansi-color-apply'. 239 "Context saved between two calls to `ansi-color-apply'.
239This is a list of the form (CODES FRAGMENT) or nil. CODES 240This is a list of the form (CODES FRAGMENT) or nil. CODES
240represents the state the last call to `ansi-color-apply' ended 241represents the state the last call to `ansi-color-apply' ended
241with, currently a list of ansi codes, and FRAGMENT is a string 242with, currently a list of ansi codes, and FRAGMENT is a string
242starting with an escape sequence, possibly the start of a new 243starting with an escape sequence, possibly the start of a new
243escape sequence.") 244escape sequence.")
244(make-variable-buffer-local 'ansi-color-context)
245 245
246(defun ansi-color-filter-apply (string) 246(defun ansi-color-filter-apply (string)
247 "Filter out all ANSI control sequences from STRING. 247 "Filter out all ANSI control sequences from STRING.
@@ -324,7 +324,8 @@ This function can be added to `comint-preoutput-filter-functions'."
324 (setq codes (ansi-color-apply-sequence escape-sequence codes))) 324 (setq codes (ansi-color-apply-sequence escape-sequence codes)))
325 ;; if the rest of the string should have a face, put it there 325 ;; if the rest of the string should have a face, put it there
326 (when codes 326 (when codes
327 (put-text-property start (length string) 'font-lock-face (ansi-color--find-face codes) string)) 327 (put-text-property start (length string)
328 'font-lock-face (ansi-color--find-face codes) string))
328 ;; save context, add the remainder of the string to the result 329 ;; save context, add the remainder of the string to the result
329 (let (fragment) 330 (let (fragment)
330 (if (string-match "\033" string start) 331 (if (string-match "\033" string start)
@@ -337,14 +338,13 @@ This function can be added to `comint-preoutput-filter-functions'."
337 338
338;; Working with regions 339;; Working with regions
339 340
340(defvar ansi-color-context-region nil 341(defvar-local ansi-color-context-region nil
341 "Context saved between two calls to `ansi-color-apply-on-region'. 342 "Context saved between two calls to `ansi-color-apply-on-region'.
342This is a list of the form (CODES MARKER) or nil. CODES 343This is a list of the form (CODES MARKER) or nil. CODES
343represents the state the last call to `ansi-color-apply-on-region' 344represents the state the last call to `ansi-color-apply-on-region'
344ended with, currently a list of ansi codes, and MARKER is a 345ended with, currently a list of ansi codes, and MARKER is a
345buffer position within an escape sequence or the last position 346buffer position within an escape sequence or the last position
346processed.") 347processed.")
347(make-variable-buffer-local 'ansi-color-context-region)
348 348
349(defun ansi-color-filter-region (begin end) 349(defun ansi-color-filter-region (begin end)
350 "Filter out all ANSI control sequences from region BEGIN to END. 350 "Filter out all ANSI control sequences from region BEGIN to END.
@@ -461,7 +461,7 @@ If FACE is nil, do nothing."
461 "Return a face with PROPERTY set to COLOR. 461 "Return a face with PROPERTY set to COLOR.
462PROPERTY can be either symbol `foreground' or symbol `background'. 462PROPERTY can be either symbol `foreground' or symbol `background'.
463 463
464For Emacs, we just return the cons cell \(PROPERTY . COLOR). 464For Emacs, we just return the cons cell (PROPERTY . COLOR).
465For XEmacs, we create a temporary face and return it." 465For XEmacs, we create a temporary face and return it."
466 (if (featurep 'xemacs) 466 (if (featurep 'xemacs)
467 (let ((face (make-face (intern (concat color "-" (symbol-name property))) 467 (let ((face (make-face (intern (concat color "-" (symbol-name property)))
@@ -530,9 +530,10 @@ Returns nil only if there's no match for `ansi-color-parameter-regexp'."
530 (nreverse codes))) 530 (nreverse codes)))
531 531
532(defun ansi-color-apply-sequence (escape-sequence codes) 532(defun ansi-color-apply-sequence (escape-sequence codes)
533 "Apply ESCAPE-SEQ to CODES and return the new list of codes. 533 "Apply ESCAPE-SEQUENCE to CODES and return the new list of codes.
534 534
535ESCAPE-SEQ is an escape sequence parsed by `ansi-color-parse-sequence'. 535ESCAPE-SEQUENCE is an escape sequence parsed by
536`ansi-color-parse-sequence'.
536 537
537For each new code, the following happens: if it is 1-7, add it to 538For each new code, the following happens: if it is 1-7, add it to
538the list of codes; if it is 21-25 or 27, delete appropriate 539the list of codes; if it is 21-25 or 27, delete appropriate
@@ -577,19 +578,19 @@ The index into the vector is an ANSI code. See the documentation of
577 578
578The face definitions are based upon the variables 579The face definitions are based upon the variables
579`ansi-color-faces-vector' and `ansi-color-names-vector'." 580`ansi-color-faces-vector' and `ansi-color-names-vector'."
580 (let ((ansi-color-map (make-vector 50 nil)) 581 (let ((map (make-vector 50 nil))
581 (index 0)) 582 (index 0))
582 ;; miscellaneous attributes 583 ;; miscellaneous attributes
583 (mapc 584 (mapc
584 (function (lambda (e) 585 (function (lambda (e)
585 (aset ansi-color-map index e) 586 (aset map index e)
586 (setq index (1+ index)) )) 587 (setq index (1+ index)) ))
587 ansi-color-faces-vector) 588 ansi-color-faces-vector)
588 ;; foreground attributes 589 ;; foreground attributes
589 (setq index 30) 590 (setq index 30)
590 (mapc 591 (mapc
591 (function (lambda (e) 592 (function (lambda (e)
592 (aset ansi-color-map index 593 (aset map index
593 (ansi-color-make-face 'foreground 594 (ansi-color-make-face 'foreground
594 (if (consp e) (car e) e))) 595 (if (consp e) (car e) e)))
595 (setq index (1+ index)) )) 596 (setq index (1+ index)) ))
@@ -598,12 +599,12 @@ The face definitions are based upon the variables
598 (setq index 40) 599 (setq index 40)
599 (mapc 600 (mapc
600 (function (lambda (e) 601 (function (lambda (e)
601 (aset ansi-color-map index 602 (aset map index
602 (ansi-color-make-face 'background 603 (ansi-color-make-face 'background
603 (if (consp e) (cdr e) e))) 604 (if (consp e) (cdr e) e)))
604 (setq index (1+ index)) )) 605 (setq index (1+ index)) ))
605 ansi-color-names-vector) 606 ansi-color-names-vector)
606 ansi-color-map)) 607 map))
607 608
608(defvar ansi-color-map (ansi-color-make-color-map) 609(defvar ansi-color-map (ansi-color-make-color-map)
609 "A brand new color map suitable for `ansi-color-get-face'. 610 "A brand new color map suitable for `ansi-color-get-face'.
@@ -613,9 +614,9 @@ The value of this variable is usually constructed by
613numbers included in an SGR control sequences point to the correct 614numbers included in an SGR control sequences point to the correct
614foreground or background colors. 615foreground or background colors.
615 616
616Example: The sequence \033[34m specifies a blue foreground. Therefore: 617Example: The sequence \\033[34m specifies a blue foreground. Therefore:
617 (aref ansi-color-map 34) 618 (aref ansi-color-map 34)
618 => \(foreground-color . \"blue\")") 619 => (foreground-color . \"blue\")")
619 620
620(defun ansi-color-map-update (symbol value) 621(defun ansi-color-map-update (symbol value)
621 "Update `ansi-color-map'. 622 "Update `ansi-color-map'.