diff --git a/ansi.el b/ansi.el index 644c1e5..f8ca738 100644 --- a/ansi.el +++ b/ansi.el @@ -1,13 +1,13 @@ -;;; ansi.el --- Turn string into ansi strings +;;; ansi.el --- Turn string into ansi strings -*- lexical-binding: t; -*- ;; Copyright (C) 2010-2013 Johan Andersson ;; Author: Johan Andersson ;; Maintainer: Johan Andersson ;; Version: 0.4.1 -;; Keywords: color, ansi +;; Keywords: terminals color ansi ;; URL: http://github.com/rejeep/ansi -;; Package-Requires: ((s "1.6.1") (dash "1.5.0")) +;; Package-Requires: ((emacs "24.4") (s "1.6.1") (dash "1.5.0")) ;; This file is NOT part of GNU Emacs. @@ -28,18 +28,19 @@ ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. +;;; Commentary: + +;; Turns simple strings to ansi strings. + +;; Turning a string into an ansi string can be to add color to a +;; text, add color in the background of a text or adding a style, +;; such as bold, underscore or italic. + ;;; Code: (require 'dash) (require 's) - -(when (version<= "24.3" emacs-version) - (require 'cl-lib)) - -;; Compatability alias for versions before cl-flet was introduced. -(defalias 'ansi--cl-flet (if (version<= "24.3" emacs-version) - 'cl-flet - 'flet)) +(require 'cl-lib) @@ -89,6 +90,7 @@ (defun ansi--concat (&rest sequences) + "Concat string elements in SEQUENCES." (apply 's-concat (-select 'stringp sequences))) (defun ansi--code (effect) @@ -110,8 +112,8 @@ (apply 'ansi-apply (cons ',effect (cons format-string objects)))))) (defmacro with-ansi (&rest body) - "In this block shortcut names (without ansi- prefix) can be used." - `(ansi--cl-flet + "Shortcut names (without ansi- prefix) can be used in this BODY." + `(cl-flet ,(-map (lambda (alias) (let ((fn (intern (format "ansi-%s" (symbol-name alias))))) @@ -124,7 +126,8 @@ ,(cons 'ansi--concat body))) (defun ansi-apply (effect-or-code format-string &rest objects) - "Apply EFFECT-OR-CODE to text." + "Apply EFFECT-OR-CODE to text. +FORMAT-STRING and OBJECTS are processed same as `apply'." (let ((code (if (numberp effect-or-code) effect-or-code (ansi--code effect-or-code)))