|
1 | 1 | ;;; fireplace.el --- A cozy fireplace for emacs -*- lexical-binding: t; -*- |
2 | 2 |
|
3 | 3 | ;; Copyright (C) 2015 Johan Sivertsen |
4 | | -;;; Version: 0.1 |
| 4 | +;;; Version: 0.2 |
5 | 5 | ;;; Author: Johan Sivertsen <[email protected]> |
6 | 6 | ;;; URL: https://github.com/johanvts/emacs-fireplace |
7 | 7 | ;;; Released: December 2015 |
|
23 | 23 |
|
24 | 24 | ;;; Commentary: |
25 | 25 |
|
26 | | -;; Puts your emacs on fire |
| 26 | +;; Puts your Emacs on fire |
27 | 27 |
|
28 | 28 | ;;; Code: |
| 29 | + |
| 30 | +(defgroup fireplace nil |
| 31 | + "Config for `fireplace' ." |
| 32 | + :group 'applications) |
| 33 | + |
| 34 | + |
29 | 35 | ;; User definable Variables |
30 | | -(defvar fireplace-smoke-on nil |
31 | | - "Controls if smoke is drawn of not.") |
| 36 | +(defcustom fireplace-smoke-on nil |
| 37 | + "Controls if smoke is drawn of not." |
| 38 | + :type 'string :group 'fireplace) |
32 | 39 |
|
33 | | -(defvar fireplace-fury 0.85 |
34 | | - "The redraw speed of the fire. Between 0 and 1.") |
| 40 | +(defcustom fireplace-fury 0.85 |
| 41 | + "The redraw speed of the fire. Between 0 and 1." |
| 42 | + :type 'float :group 'fireplace) |
35 | 43 |
|
36 | | -(defvar fireplace-smoke-char ?\* |
37 | | - "Char used for drawing smoke.") |
| 44 | +(defcustom fireplace-smoke-char ?\* |
| 45 | + "Char used for drawing smoke." |
| 46 | + :type 'character :group 'fireplace) |
38 | 47 |
|
39 | | -(defvar fireplace-background-char ?\s |
40 | | - "Char used for filling in the background.") |
| 48 | +(defcustom fireplace-background-char ?\s |
| 49 | + "Char used for filling in the background." |
| 50 | + :type 'character :group 'fireplace) |
41 | 51 |
|
42 | | -(defvar fireplace-fill-char ?\s |
43 | | - "Char used for drawing smoke.") |
| 52 | +(defcustom fireplace-fill-char ?\s |
| 53 | + "Char used for drawing smoke." |
| 54 | + :type 'character :group 'fireplace) |
44 | 55 |
|
45 | | -(defvar fireplace-flame-pos '(0.5 0.2 0.8 0.36 0.64 ) |
46 | | - "Relative position and order for drawing flames.") |
| 56 | +(defcustom fireplace-flame-pos '(0.5 0.2 0.8 0.36 0.64 ) |
| 57 | + "Relative position and order for drawing flames." |
| 58 | + :type '(list float) :group 'fireplace) |
47 | 59 |
|
48 | 60 |
|
49 | | -(defvar fireplace-buffer-name "*fireplace*" |
50 | | - "Default name for fireplace buffer.") |
| 61 | +(defcustom fireplace-buffer-name "*fireplace*" |
| 62 | + "Default name for fireplace buffer." |
| 63 | + :type 'string :group 'fireplace) |
51 | 64 |
|
52 | 65 | ;; Program controlled variables |
53 | 66 |
|
|
59 | 72 | ;; Helper routines |
60 | 73 |
|
61 | 74 | (defun fireplace--make-grid () |
| 75 | + "Redraw backgound of buffer." |
62 | 76 | (erase-buffer) |
63 | 77 | (dotimes (i fireplace--bkgd-height) |
64 | 78 | (insert-char fireplace-background-char fireplace--bkgd-width) |
65 | 79 | (newline))) |
66 | 80 |
|
67 | 81 | (defun fireplace--gotoxy(x y) |
68 | | - (goto-char (+ 1 x (* (- fireplace--bkgd-height (+ 1 y)) (+ 1 fireplace--bkgd-width))))) |
| 82 | + "Move pointer to position X Y." |
| 83 | + (goto-char (+ 1 x (* (- fireplace--bkgd-height (+ 1 y)) |
| 84 | + (+ 1 fireplace--bkgd-width))))) |
69 | 85 |
|
70 | 86 |
|
71 | 87 | (defun draw-flame-stripe (x y width) |
| 88 | + "Draw fire stripes." |
72 | 89 | (fireplace--gotoxy x y) |
73 | 90 | (let* ((actual-width (min width (1+ (- fireplace--bkgd-width x)))) |
74 | 91 | (hot-core (/ actual-width 2))) |
|
82 | 99 | 'face `(:background ,"dark orange")))))) |
83 | 100 |
|
84 | 101 | (defun fireplace--smoke (x height) |
| 102 | + "Draw fire smoke." |
85 | 103 | (fireplace--gotoxy (if (>(random 3) 1) |
86 | 104 | (+ x (random (/ fireplace--bkgd-width 5))) |
87 | 105 | (max 0 (- x (random (/ fireplace--bkgd-width 5))))) |
|
91 | 109 | 'face `(:foreground, "slate grey")))) |
92 | 110 |
|
93 | 111 | (defun fireplace--flame (middle h) |
| 112 | + "Draw fire flames." |
94 | 113 | (setq cursor-type nil) |
95 | 114 | (let* ((width h) |
96 | 115 | (lower (truncate(* 0.2 h))) |
|
119 | 138 | (when fireplace-smoke-on (fireplace--smoke x h))))) |
120 | 139 |
|
121 | 140 | (defun draw-fireplace (buffer-name flame-pos flame-width) |
| 141 | + "Draw the whole fireplace in BUFFER-NAME from FLAME-POS with FLAME-WIDTH." |
122 | 142 | (with-current-buffer (get-buffer-create buffer-name) |
123 | 143 | (setq buffer-read-only nil) |
124 | 144 | (fireplace--make-grid) |
|
136 | 156 | "Turn on the fire like it's winter." |
137 | 157 | (interactive "P") |
138 | 158 | (with-current-buffer (get-buffer-create fireplace-buffer-name) |
| 159 | + (buffer-disable-undo) |
139 | 160 | (setq cursor-type nil) |
140 | 161 | (buffer-disable-undo) |
141 | 162 | (switch-to-buffer fireplace-buffer-name) |
|
155 | 176 | (kill-buffer fireplace-buffer-name))) |
156 | 177 |
|
157 | 178 | (defun fireplace-down () |
158 | | - (interactive) |
159 | 179 | "Push the fire further down" |
| 180 | + (interactive) |
160 | 181 | (setq fireplace--bkgd-height (+ fireplace--bkgd-height 1))) |
161 | 182 |
|
162 | 183 |
|
163 | 184 | (defun fireplace-up () |
| 185 | + "Move the fire further up." |
164 | 186 | (interactive) |
165 | | - "Move the fire further up" |
166 | 187 | (setq fireplace--bkgd-height (max 0 (- fireplace--bkgd-height 1)))) |
167 | 188 |
|
168 | 189 | (defun fireplace-toggle-smoke () |
| 190 | + "Toggle smoke on/off." |
169 | 191 | (interactive) |
170 | | - "Toggle smoke on/off" |
171 | 192 | (if fireplace-smoke-on |
172 | 193 | (setq fireplace-smoke-on nil) |
173 | 194 | (setq fireplace-smoke-on t))) |
174 | 195 |
|
175 | | -;;Key-bindings |
| 196 | +;;; Key-bindings |
176 | 197 |
|
177 | | -(define-derived-mode fireplace-mode special-mode "A cozy fireplace") |
| 198 | +(define-derived-mode fireplace-mode special-mode "A cozy fireplace.") |
178 | 199 |
|
179 | 200 | (define-key fireplace-mode-map (kbd "C-+") 'fireplace-down) |
180 | 201 | (define-key fireplace-mode-map (kbd "C--") 'fireplace-up) |
181 | 202 | (define-key fireplace-mode-map (kbd "C-*") 'fireplace-toggle-smoke) |
| 203 | +(define-key fireplace-mode-map (kbd "q") 'fireplace-off) |
182 | 204 |
|
183 | 205 | (provide 'fireplace) |
184 | 206 | ;;; fireplace.el ends here |
0 commit comments