Merge branch 'xmlgen-bug-fixes'
[ShellArchive.git] / figlet.el
blobc40d1805ff52bebf05a7d599a4e43a99f674f71a
1 ;;; figlet.el --- Annoy people with big, ascii art text
3 ;; Copyright (C) 2008 Philip Jackson
5 ;; Author: Philip Jackson <phil@shellarchive.co.uk>
6 ;; Version: 0.5
8 ;; This file is not currently part of GNU Emacs.
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program ; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;;; Commentary:
27 ;; To use this feature simple eval (require 'figlet) type M-x figlet
28 ;; and you will be asked for a string. If you use a prefix (C-u M-x
29 ;; figlet) then you will be asked for a font.
31 ;; Have a look at `figlet-comment', `figlet-figletify-region' and
32 ;; `figlet-figletify-region-comment'.
34 ;; Warning, leaving large ascii art text in your teams codebase might
35 ;; cause an outbreak of physical violence.
37 (defvar figlet-fonts '())
38 (defvar figlet-default-font "small"
39 "Default font to use when none is supplied.")
40 (defvar figlet-fonts-dir-candidates
41 '("/usr/share/figlet"
42 "/usr/local/share/figlet")
43 "List of directories which are to be searched for fonts.")
44 (defvar figlet-options '()
45 "List of options for the figlet call.")
47 (defun figlet-get-font-list ()
48 "Get a list of potential figlet fonts by testing each directory
49 in `figlet-fonts-dir-candidates'"
50 (if (null figlet-fonts)
51 (setq figlet-fonts
52 (catch 'found
53 (mapc (lambda (d)
54 (let ((default-directory d)
55 (fonts (directory-files d nil "^[^.].+\.flf$")))
56 (when (length fonts)
57 (throw 'found fonts))))
58 figlet-fonts-dir-candidates)))
59 figlet-fonts))
61 (defun figlet (string)
62 "Pass a string through figlet and insert the output at
63 point. Use a prefix arg to be promted for a font."
64 (interactive "sTo be fug: ")
65 (let* ((fonts (figlet-get-font-list))
66 (font (if current-prefix-arg
67 (if fonts
68 (completing-read "Font: " fonts nil t)
69 (read-from-minibuffer "Font: " figlet-default-font))
70 figlet-default-font)))
71 (insert
72 (with-temp-buffer
73 (call-process "figlet" nil t t
74 (mapconcat 'identity figlet-options " ")
75 "-f" font string)
76 (goto-char (point-min))
77 (re-search-forward "^." nil t)
78 (delete-region (point-min) (point-at-bol))
79 (re-search-forward "^[[:blank:]]*$" nil t)
80 (delete-region (point) (point-max))
81 (delete-trailing-whitespace)
82 (buffer-substring (point-min) (point-max))))))
84 (defun figlet-comment (string)
85 "Insert a figlet string just as `figlet' would but comment the
86 result (using `comment-region')"
87 (interactive "sTo be fug: ")
88 (let ((start (point)))
89 (save-excursion
90 (figlet string)
91 (comment-region start (point)))))
93 (defun figlet-figletify-region (start end)
94 "Convert the region into a figlet string."
95 (interactive "r")
96 (let ((str (buffer-substring start end)))
97 (delete-region start end)
98 (figlet str)))
100 (defun figlet-figletify-region-comment (start end)
101 "Convert the region into a figlet string as with
102 `figlet-figletify-region' but comment it out too."
103 (interactive "r")
104 (let ((str (buffer-substring start end)))
105 (delete-region start end)
106 (figlet-comment str)))
108 (defun figlet-preview-fonts (&optional text)
109 "View an example of each font in a new buffer."
110 (interactive)
111 (switch-to-buffer (get-buffer-create "*Figlet Font Examples*"))
112 (delete-region (point-min) (point-max))
113 (mapconcat (lambda (x)
114 (let ((figlet-default-font x))
115 (insert (concat x ":\n"))
116 (figlet (or text (replace-regexp-in-string "\.flf$" "" x)))))
117 (figlet-get-font-list)
118 "\n"))
120 (provide 'figlet)