[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/rainbow-mode 65948a4 07/26: * rainbow-mode: update to 0
From: |
Stefan Monnier |
Subject: |
[elpa] externals/rainbow-mode 65948a4 07/26: * rainbow-mode: update to 0.6, add support for ANSI coloring |
Date: |
Tue, 1 Dec 2020 16:53:19 -0500 (EST) |
branch: externals/rainbow-mode
commit 65948a47ab221c8add00ca689c78897abdb62227
Author: Julien Danjou <julien@danjou.info>
Commit: Julien Danjou <julien@danjou.info>
* rainbow-mode: update to 0.6, add support for ANSI coloring
---
rainbow-mode.el | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 64 insertions(+), 1 deletion(-)
diff --git a/rainbow-mode.el b/rainbow-mode.el
index c653209..dc34cfd 100644
--- a/rainbow-mode.el
+++ b/rainbow-mode.el
@@ -4,7 +4,7 @@
;; Author: Julien Danjou <julien@danjou.info>
;; Keywords: faces
-;; Version: 0.5
+;; Version: 0.6
;; This file is part of GNU Emacs.
@@ -36,6 +36,9 @@
(require 'faces)
(require 'color)
+(unless (require 'xterm-color nil t)
+ (require 'ansi-color))
+
(defgroup rainbow nil
"Show color strings with a background color."
:tag "Rainbow"
@@ -282,6 +285,26 @@ will be enabled if a major mode has been detected from the
`rainbow-latex-colors-major-mode-list'."
:group 'rainbow)
+;; Shell colors
+(defvar rainbow-ansi-colors-font-lock-keywords
+ '(("\\(\\\\[eE]\\|\\\\033\\|\\\\x1[bB]\\|\033\\)\\[\\([0-9;]*m\\)"
+ (0 (rainbow-colorize-ansi))))
+ "Font-lock keywords to add for ANSI colors.")
+
+(defcustom rainbow-ansi-colors-major-mode-list
+ '(sh-mode c-mode c++-mode)
+ "List of major mode where ANSI colors are enabled when
+`rainbow-ansi-colors' is set to auto."
+ :group 'rainbow)
+
+(defcustom rainbow-ansi-colors 'auto
+ "When to enable ANSI colors.
+If set to t, the ANSI colors will be enabled. If set to nil, the
+ANSI colors will not be enabled. If set to auto, the ANSI colors
+will be enabled if a major mode has been detected from the
+`rainbow-ansi-colors-major-mode-list'."
+ :group 'rainbow)
+
;; Functions
(defun rainbow-colorize-match (color &optional match)
"Return a matched string propertized with a face whose
@@ -340,6 +363,40 @@ This will convert \"80 %\" to 204, \"100 %\" to 255 but
\"123\" to \"123\"."
(b (* (string-to-number (match-string-no-properties 3)) 255.0)))
(rainbow-colorize-match (format "#%02X%02X%02X" r g b))))
+(defun rainbow-colorize-ansi ()
+ "Return a matched string propertized with ansi color face."
+ (let ((xterm-color? (featurep 'xterm-color))
+ (string (match-string-no-properties 0))
+ color)
+ (save-match-data
+ (let* ((replaced (concat
+ (replace-regexp-in-string
+ "^\\(\\\\[eE]\\|\\\\033\\|\\\\x1[bB]\\)"
+ "\033" string) "x"))
+ xterm-color-current
+ ansi-color-context
+ (applied (funcall (if xterm-color?
+ 'xterm-color-filter
+ 'ansi-color-apply)
+ replaced))
+ (face-property (get-text-property
+ 0
+ (if xterm-color? 'face 'font-lock-face)
+ applied)))
+ (unless (listp (car face-property))
+ (setq face-property (list face-property)))
+ (setq color (funcall (if xterm-color? 'cadr 'cdr)
+ (or (assq (if xterm-color?
+ :foreground
+ 'foreground-color)
+ face-property)
+ (assq (if xterm-color?
+ :background
+ 'background-color)
+ face-property))))))
+ (when color
+ (rainbow-colorize-match color))))
+
(defun rainbow-color-luminance (red green blue)
"Calculate the luminance of color composed of RED, BLUE and GREEN.
Return a value between 0 and 1."
@@ -370,6 +427,12 @@ Return a value between 0 and 1."
(memq major-mode rainbow-latex-colors-major-mode-list)))
(font-lock-add-keywords nil
rainbow-latex-rgb-colors-font-lock-keywords))
+ ;; Activate ANSI colors?
+ (when (or (eq rainbow-ansi-colors t)
+ (and (eq rainbow-ansi-colors 'auto)
+ (memq major-mode rainbow-ansi-colors-major-mode-list)))
+ (font-lock-add-keywords nil
+ rainbow-ansi-colors-font-lock-keywords))
;; Activate HTML colors?
(when (or (eq rainbow-html-colors t)
(and (eq rainbow-html-colors 'auto)
- [elpa] branch externals/rainbow-mode created (now 347bd20), Stefan Monnier, 2020/12/01
- [elpa] externals/rainbow-mode d78fc41 03/26: rainbow-mode 0.3, Stefan Monnier, 2020/12/01
- [elpa] externals/rainbow-mode 1d90a91 05/26: rainbow-mode: version 0.5, Stefan Monnier, 2020/12/01
- [elpa] externals/rainbow-mode 83bb7be 06/26: rainbow-mode: fix some LaTex docstrings, Stefan Monnier, 2020/12/01
- [elpa] externals/rainbow-mode ea74dbb 01/26: Give every package its own directory in packages/, Stefan Monnier, 2020/12/01
- [elpa] externals/rainbow-mode 47c6ac1 04/26: rainbow-mode: version 0.4, Stefan Monnier, 2020/12/01
- [elpa] externals/rainbow-mode 65948a4 07/26: * rainbow-mode: update to 0.6, add support for ANSI coloring,
Stefan Monnier <=
- [elpa] externals/rainbow-mode bcc2bcd 10/26: rainbow-mode: 0.9, allow spaces in LaTeX colors, Stefan Monnier, 2020/12/01
- [elpa] externals/rainbow-mode cb47e83 13/26: rainbow: fix font-lock-mode refresh, Stefan Monnier, 2020/12/01
- [elpa] externals/rainbow-mode 3e5d506 19/26: rainbow-mode: release 1.0, Stefan Monnier, 2020/12/01
- [elpa] externals/rainbow-mode 313f105 15/26: Fix `rainbow-color-luminance' docstring, Stefan Monnier, 2020/12/01
- [elpa] externals/rainbow-mode 4cfdc5b 18/26: Allow outline-minor-mode to find section headings, Stefan Monnier, 2020/12/01
- [elpa] externals/rainbow-mode 2795d65 21/26: Fix a off-by-one error and some wording in rainbow-mode, Stefan Monnier, 2020/12/01
- [elpa] externals/rainbow-mode 1f37950 02/26: Update rainbow-mode to version 0.2, Stefan Monnier, 2020/12/01
- [elpa] externals/rainbow-mode 3a684c7 09/26: rainbow-mode: add support for R, bump version to 0.8, Stefan Monnier, 2020/12/01
- [elpa] externals/rainbow-mode 16afb8a 08/26: rainbow-mode: version 0.7, Stefan Monnier, 2020/12/01
- [elpa] externals/rainbow-mode fb7c982 20/26: * rainbow-mode/rainbow-mode.el: do not fail if face-property is a symbol, Stefan Monnier, 2020/12/01