Skip to content

Commit 4d6d345

Browse files
committed
Merge pull request #8 from AdrieanKhisbe/master
Autoloads cookie and minor refactors
2 parents 191dc21 + 8ba3d5f commit 4d6d345

File tree

3 files changed

+80
-58
lines changed

3 files changed

+80
-58
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
*.elc
2+
/.cask
3+
/test/sandbox
4+
/features/sandbox
5+
/dist
6+
/build
7+
/tmp

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ Key bind Function
2424
========================= ================================
2525
``C-+`` Move fire up
2626
``C--`` Move fire down
27-
``C-s`` Toggle smoke
27+
``C-*`` Toggle smoke
2828
========================= ================================
2929

30-
All variables starting with ''fireplace-'' can be customized. Use ''C-h v'' to read their documentation.
30+
All variables starting with ''fireplace-'' can be customized. Use ''C-h v'' to read their documentation.
3131

3232
Acknowledgment
3333
--------------

fireplace.el

Lines changed: 72 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
1-
;;; fireplace.el --- A cozy fireplace for emacs
2-
;;; Version: 1.0
1+
;;; fireplace.el --- A cozy fireplace for emacs -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2015 Johan Sivertsen
4+
;;; Version: 0.1
5+
;;; Author: Johan Sivertsen <[email protected]>
6+
;;; URL: https://github.com/johanvts/emacs-fireplace
7+
;;; Released: December 2015
8+
9+
;; Keywords: games
10+
11+
;; This program is free software; you can redistribute it and/or modify
12+
;; it under the terms of the GNU General Public License as published by
13+
;; the Free Software Foundation, either version 3 of the License, or
14+
;; (at your option) any later version.
15+
16+
;; This program is distributed in the hope that it will be useful,
17+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
;; GNU General Public License for more details.
20+
21+
;; You should have received a copy of the GNU General Public License
22+
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
324
;;; Commentary:
4-
;; Author: Johan Sivertsen <[email protected]>
5-
;; URL: https://github.com/johanvts/emacs-fireplace
6-
;; Released: December 2015
25+
26+
;; Puts your emacs on fire
727

828
;;; Code:
929
;; User definable Variables
@@ -31,118 +51,119 @@
3151

3252
;; Program controlled variables
3353

34-
(defvar fp-bkgd-height "Used for fireplace height, will be set from windows size")
35-
(defvar fp-bkgd-width "Used for fireplace width, will be set from windows size")
36-
(defvar fp-timer "Holds the active fireplace, kill using fireplace-off")
37-
(defvar fp-flame-width "Calculated width of flames")
54+
(defvar fireplace--bkgd-height "Used for fireplace height, will be set from windows size")
55+
(defvar fireplace--bkgd-width "Used for fireplace width, will be set from windows size")
56+
(defvar fireplace--timer "Holds the active fireplace, kill using fireplace-off")
57+
(defvar fireplace--flame-width "Calculated width of flames")
3858

3959
;; Helper routines
4060

41-
(defun make-grid ()
61+
(defun fireplace--make-grid ()
4262
(erase-buffer)
43-
(dotimes (i fp-bkgd-height)
44-
(insert-char fireplace-background-char fp-bkgd-width)
63+
(dotimes (i fireplace--bkgd-height)
64+
(insert-char fireplace-background-char fireplace--bkgd-width)
4565
(newline)))
4666

47-
(defun gotoxy (x y)
48-
(goto-char (+ 1 x (* (- fp-bkgd-height (+ 1 y)) (+ 1 fp-bkgd-width)))))
67+
(defun fireplace--gotoxy(x y)
68+
(goto-char (+ 1 x (* (- fireplace--bkgd-height (+ 1 y)) (+ 1 fireplace--bkgd-width)))))
4969

5070

5171
(defun draw-flame-stripe (x y width)
52-
(gotoxy x y)
53-
(let* ((actual-width (min width (1+ (- fp-bkgd-width x))))
72+
(fireplace--gotoxy x y)
73+
(let* ((actual-width (min width (1+ (- fireplace--bkgd-width x))))
5474
(hot-core (/ actual-width 2)))
5575
(delete-char actual-width)
5676
(insert (propertize (make-string actual-width fireplace-fill-char)
5777
'face `(:background ,"dark orange")))
5878
(when (> hot-core 1)
59-
(gotoxy (+ x (/ hot-core 2)) y)
79+
(fireplace--gotoxy (+ x (/ hot-core 2)) y)
6080
(delete-char hot-core)
6181
(insert (propertize (make-string hot-core fireplace-fill-char)
6282
'face `(:background ,"orange red"))))))
6383

64-
(defun smoke (x height)
65-
(gotoxy (if (>(random 3) 1)
66-
(+ x (random (/ fp-bkgd-width 5)))
67-
(max 0 (- x (random (/ fp-bkgd-width 5)))))
68-
(+ height (random (- fp-bkgd-height height))))
84+
(defun fireplace--smoke (x height)
85+
(fireplace--gotoxy (if (>(random 3) 1)
86+
(+ x (random (/ fireplace--bkgd-width 5)))
87+
(max 0 (- x (random (/ fireplace--bkgd-width 5)))))
88+
(+ height (random (- fireplace--bkgd-height height))))
6989
(delete-char 1)
7090
(insert (propertize (make-string 1 fireplace-smoke-char)
7191
'face `(:foreground, "slate grey"))))
7292

73-
(defun flame (middle h)
93+
(defun fireplace--flame (middle h)
7494
(setq cursor-type nil)
7595
(let* ((width h)
7696
(lower (truncate(* 0.2 h)))
7797
(high (- h lower))
7898
x
7999
line)
80100
(dotimes (y lower)
81-
(setq width (+ width y))
82-
(setq x (- middle (/ width 2)))
101+
(setq width (+ width y)
102+
x (- middle (/ width 2)))
83103
(when (< x 0)
84-
(setq width (+ width x))
85-
(setq x 0))
86-
(when (> (+ x width) fp-bkgd-width)
87-
(setq width (- fp-bkgd-width x)))
104+
(setq width (+ width x)
105+
x 0))
106+
(when (> (+ x width) fireplace--bkgd-width)
107+
(setq width (- fireplace--bkgd-width x)))
88108
(draw-flame-stripe x y width))
89109
(dotimes (y high)
90110
(setq line (+ lower y))
91111
(setq width (max 0 (- width 1 (random 3))))
92112
(setq x (- middle (/ width 2)))
93113
(when (< x 0)
94-
(setq width (+ width x))
95-
(setq x 0))
96-
(when (> (+ x width) fp-bkgd-width)
97-
(setq width (- fp-bkgd-width x)))
114+
(setq width (+ width x)
115+
x 0))
116+
(when (> (+ x width) fireplace--bkgd-width)
117+
(setq width (- fireplace--bkgd-width x)))
98118
(draw-flame-stripe x line width)
99-
(when fireplace-smoke-on (smoke x h)))))
119+
(when fireplace-smoke-on (fireplace--smoke x h)))))
100120

101121
(defun draw-fireplace (buffer-name flame-pos flame-width)
102122
(with-current-buffer (get-buffer-create buffer-name)
103123
(setq buffer-read-only nil)
104-
(make-grid)
124+
(fireplace--make-grid)
105125
(dolist (pos flame-pos)
106-
(flame (round (* pos fp-bkgd-width))
126+
(fireplace--flame (round (* pos fireplace--bkgd-width))
107127
(+
108128
(round (* (+ 0.2 (min pos (- 1 pos))) flame-width))
109129
(random 3))))
110130
(setq buffer-read-only t)))
111131

112132

113-
;;Commands
114-
133+
;; Commands
134+
;;;###autoload
115135
(defun fireplace (arg)
136+
"Turn on the fire like it's winter."
116137
(interactive "P")
117138
(with-current-buffer (get-buffer-create fireplace-buffer-name)
118139
(setq cursor-type nil)
119140
(buffer-disable-undo)
120141
(switch-to-buffer fireplace-buffer-name)
121-
(setq fp-bkgd-height (round (window-height (get-buffer-window fireplace-buffer-name))))
122-
(setq fp-bkgd-width (round (window-width (get-buffer-window fireplace-buffer-name))))
123-
(setq fp-flame-width (min fp-bkgd-height (round (/ fp-bkgd-width 2.5))))
124-
(make-grid)
142+
(setq fireplace--bkgd-height (round (window-height (get-buffer-window fireplace-buffer-name)))
143+
fireplace--bkgd-width (round (window-width (get-buffer-window fireplace-buffer-name)))
144+
fireplace--flame-width (min fireplace--bkgd-height (round (/ fireplace--bkgd-width 2.5))))
145+
(fireplace--make-grid)
125146
(fireplace-mode)
126-
(setq fp-timer (run-with-timer 1 (- 1 fireplace-fury)
127-
'draw-fireplace fireplace-buffer-name fireplace-flame-pos fp-flame-width))))
147+
(setq fireplace--timer (run-with-timer 1 (- 1 fireplace-fury)
148+
'draw-fireplace fireplace-buffer-name fireplace-flame-pos fireplace--flame-width))))
128149

129150
(defun fireplace-off ()
130151
"Put out the fire."
131152
(interactive)
132-
(when fp-timer
133-
(cancel-timer fp-timer)
153+
(when fireplace--timer
154+
(cancel-timer fireplace--timer)
134155
(kill-buffer fireplace-buffer-name)))
135156

136157
(defun fireplace-down ()
137158
(interactive)
138159
"Push the fire further down"
139-
(setq fp-bkgd-height (+ fp-bkgd-height 1)))
160+
(setq fireplace--bkgd-height (+ fireplace--bkgd-height 1)))
140161

141162

142163
(defun fireplace-up ()
143164
(interactive)
144165
"Move the fire further up"
145-
(setq fp-bkgd-height (max 0 (- fp-bkgd-height 1))))
166+
(setq fireplace--bkgd-height (max 0 (- fireplace--bkgd-height 1))))
146167

147168
(defun fireplace-toggle-smoke ()
148169
(interactive)
@@ -151,18 +172,13 @@
151172
(setq fireplace-smoke-on nil)
152173
(setq fireplace-smoke-on t)))
153174

154-
(provide 'fireplace)
155-
(provide 'fireplace-off)
156-
(provide 'fireplace-down)
157-
158175
;;Key-bindings
159176

160-
(define-derived-mode fireplace-mode special-mode
161-
"A cozy fireplace")
162-
177+
(define-derived-mode fireplace-mode special-mode "A cozy fireplace")
163178

164179
(define-key fireplace-mode-map (kbd "C-+") 'fireplace-down)
165180
(define-key fireplace-mode-map (kbd "C--") 'fireplace-up)
166-
(define-key fireplace-mode-map (kbd "C-s") 'fireplace-toggle-smoke)
181+
(define-key fireplace-mode-map (kbd "C-*") 'fireplace-toggle-smoke)
167182

183+
(provide 'fireplace)
168184
;;; fireplace.el ends here

0 commit comments

Comments
 (0)