Skip to content

Commit 84c5da2

Browse files
committed
Merge pull request #16 from AdrieanKhisbe/customs-and-tweaks
Customs and tweaks
2 parents 7deb30c + 8521913 commit 84c5da2

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Key bind Function
2626
``C-+`` Move fire up
2727
``C--`` Move fire down
2828
``C-*`` Toggle smoke
29+
``q`` Turn off fire
2930
========================= ================================
3031

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

fireplace.el

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
;;; fireplace.el --- A cozy fireplace for emacs -*- lexical-binding: t; -*-
22

33
;; Copyright (C) 2015 Johan Sivertsen
4-
;;; Version: 0.1
4+
;;; Version: 0.2
55
;;; Author: Johan Sivertsen <[email protected]>
66
;;; URL: https://github.com/johanvts/emacs-fireplace
77
;;; Released: December 2015
@@ -23,31 +23,44 @@
2323

2424
;;; Commentary:
2525

26-
;; Puts your emacs on fire
26+
;; Puts your Emacs on fire
2727

2828
;;; Code:
29+
30+
(defgroup fireplace nil
31+
"Config for `fireplace' ."
32+
:group 'applications)
33+
34+
2935
;; 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)
3239

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)
3543

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)
3847

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)
4151

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)
4455

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)
4759

4860

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)
5164

5265
;; Program controlled variables
5366

@@ -59,16 +72,20 @@
5972
;; Helper routines
6073

6174
(defun fireplace--make-grid ()
75+
"Redraw backgound of buffer."
6276
(erase-buffer)
6377
(dotimes (i fireplace--bkgd-height)
6478
(insert-char fireplace-background-char fireplace--bkgd-width)
6579
(newline)))
6680

6781
(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)))))
6985

7086

7187
(defun draw-flame-stripe (x y width)
88+
"Draw fire stripes."
7289
(fireplace--gotoxy x y)
7390
(let* ((actual-width (min width (1+ (- fireplace--bkgd-width x))))
7491
(hot-core (/ actual-width 2)))
@@ -82,6 +99,7 @@
8299
'face `(:background ,"dark orange"))))))
83100

84101
(defun fireplace--smoke (x height)
102+
"Draw fire smoke."
85103
(fireplace--gotoxy (if (>(random 3) 1)
86104
(+ x (random (/ fireplace--bkgd-width 5)))
87105
(max 0 (- x (random (/ fireplace--bkgd-width 5)))))
@@ -91,6 +109,7 @@
91109
'face `(:foreground, "slate grey"))))
92110

93111
(defun fireplace--flame (middle h)
112+
"Draw fire flames."
94113
(setq cursor-type nil)
95114
(let* ((width h)
96115
(lower (truncate(* 0.2 h)))
@@ -119,6 +138,7 @@
119138
(when fireplace-smoke-on (fireplace--smoke x h)))))
120139

121140
(defun draw-fireplace (buffer-name flame-pos flame-width)
141+
"Draw the whole fireplace in BUFFER-NAME from FLAME-POS with FLAME-WIDTH."
122142
(with-current-buffer (get-buffer-create buffer-name)
123143
(setq buffer-read-only nil)
124144
(fireplace--make-grid)
@@ -136,6 +156,7 @@
136156
"Turn on the fire like it's winter."
137157
(interactive "P")
138158
(with-current-buffer (get-buffer-create fireplace-buffer-name)
159+
(buffer-disable-undo)
139160
(setq cursor-type nil)
140161
(buffer-disable-undo)
141162
(switch-to-buffer fireplace-buffer-name)
@@ -155,30 +176,31 @@
155176
(kill-buffer fireplace-buffer-name)))
156177

157178
(defun fireplace-down ()
158-
(interactive)
159179
"Push the fire further down"
180+
(interactive)
160181
(setq fireplace--bkgd-height (+ fireplace--bkgd-height 1)))
161182

162183

163184
(defun fireplace-up ()
185+
"Move the fire further up."
164186
(interactive)
165-
"Move the fire further up"
166187
(setq fireplace--bkgd-height (max 0 (- fireplace--bkgd-height 1))))
167188

168189
(defun fireplace-toggle-smoke ()
190+
"Toggle smoke on/off."
169191
(interactive)
170-
"Toggle smoke on/off"
171192
(if fireplace-smoke-on
172193
(setq fireplace-smoke-on nil)
173194
(setq fireplace-smoke-on t)))
174195

175-
;;Key-bindings
196+
;;; Key-bindings
176197

177-
(define-derived-mode fireplace-mode special-mode "A cozy fireplace")
198+
(define-derived-mode fireplace-mode special-mode "A cozy fireplace.")
178199

179200
(define-key fireplace-mode-map (kbd "C-+") 'fireplace-down)
180201
(define-key fireplace-mode-map (kbd "C--") 'fireplace-up)
181202
(define-key fireplace-mode-map (kbd "C-*") 'fireplace-toggle-smoke)
203+
(define-key fireplace-mode-map (kbd "q") 'fireplace-off)
182204

183205
(provide 'fireplace)
184206
;;; fireplace.el ends here

0 commit comments

Comments
 (0)