about summary refs log tree commit diff
path: root/configs/shared/emacs/.emacs.d/elpa/zen-mode-20170723.139/zen-mode.el
blob: ed9acb7ea0cd6d8a32fd8607211ae255c6ee6299 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
;;; zen-mode.el --- Zen Editing Mode

;; Copyright (C) 2017 Akilan Elango

;; Author: Akilan Elango <akilan1997 [at] gmail.com>
;; Keywords: convenience
;; Package-Version: 20170723.139
;; X-URL: https://github.com/aki237/zen-mode
;; URL: https://github.com/aki237/zen-mode
;; Version: 0.0.1
;; Package-Requires: ((emacs "24.3"))

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:
;; Zen mode for Emacs is a distraction free editing mode for Emacs.
;;
;;; Installation:
;;
;;   (require 'zen-mode)
;;
;;; Use:
;; This is used to start a distraction free editing session in Emacs like in
;; Sublime Text.
;;
;;; Code:

;; require


;; variables
(defvar zen-mode-disable-mode-line t
  "Zen mode option to hide the mode line.  Set true to hide the mode line in Zen-mode.")

;; local variables
(defvar-local zen-run-mode nil
  "zen-run-mode variable is to set state of whether zen mode is enabled in the current buffer"
  )

(defvar-local zen-mode-margin-width (/ (/ (display-pixel-width) (/ (window-pixel-width) (window-width))) 5)
  "Zen mode option to specify the margin width."
  )

(defvar-local zen-mode-line-cache nil
  "zen-mode-line-cache variable is used to save the modeline format content for future when it is disabled"
  )

(defvar-local zen-menubar-state nil
  "zen-menubar-state variable is used to save whether menu-bar-mode is enabled before entering the zen mode"
  )

(defvar-local zen-toolbar-state nil
  "zen-toolbar-state variable is used to save whether tool-bar-mode is enabled before entering the zen mode"
  )

(defvar-local zen-linum-state nil
  "zen-linum-state variable is used to save whether linum-mode is enabled before entering the zen mode"
  )

(defvar-local zen-blink-cursor-state nil
  "zen-blink-cursor-state variable is used to save whether blink-cursor-mode is enabled before entering the zen mode"
  )

(defvar-local zen-lm-state 0
  "zm-lm-state variable is used to store the left margin width before the activation of zen-mode"
  )

(defvar-local zen-rm-state 0
  "zm-rm-state variable is used to store the right margin width before the activation of zen-mode"
  )


(defvar-local zen-lf-state 0
  "zm-lf-state variable is used to store the left fringe width before the activation of zen-mode"
  )

(defvar-local zen-rf-state 0
  "zm-rf-state variable is used to store the right fringe width before the activation of zen-mode"
  )

(defvar-local zen-fullscreen-state nil
  "zm-fullscreen-state variable is used to store fullscreen state before the activation of zen-mode"
  )

;;;###autoload
(define-minor-mode zen-mode
  "zen-mode is a distraction free editing mode for Emacs"
  :lighter " Zen"
  :keymap (let ((map (make-sparse-keymap)))
            (define-key map (kbd "C-c C-<") 'zen-mode-increase-margin-width)
            (define-key map (kbd "C-c C->") 'zen-mode-decrease-margin-width)
            map)
  (zen-run)
  )

;; functions
(defun zen-run()
  "zen-run is a lisp function which activates and deactivates the zen-mode"
  (if zen-run-mode
      (progn
        (message "Distraction free disabled")
        (setq window-size-change-functions (remove 'zen-mode-refresh-buffer 'window-size-change-functions))
	(if zen-linum-state
	    (linum-mode 1))

	(if zen-blink-cursor-state
          (blink-cursor-mode 1))

	(if zen-mode-disable-mode-line
          (progn
            (setq mode-line-format zen-mode-line-cache)))

	(if zen-toolbar-state
	    (tool-bar-mode 1))

	(if zen-menubar-state
	    (menu-bar-mode 1))
	(setq left-fringe-width zen-lf-state)
	(setq right-fringe-width zen-rf-state)
	(setq left-margin-width zen-lm-state)
        (setq right-margin-width zen-rm-state)
        (set-frame-parameter nil 'fullscreen 'zen-fullscreen-state)
        (set-window-buffer nil (current-buffer))
        (setq zen-run-mode nil))
    (progn
      (if zen-mode-disable-mode-line
          (progn
            (setq zen-mode-line-cache mode-line-format)
            (setq mode-line-format nil)))

      (setq zen-menubar-state (and (boundp 'menu-bar-mode) menu-bar-mode))

      (setq zen-toolbar-state (and (boundp 'tool-bar-mode) tool-bar-mode))

      (setq zen-linum-state (and (boundp 'linum-mode) linum-mode))

      (setq zen-blink-cursor-state (and (boundp 'blink-cursor-mode) blink-cursor-mode))

      (setq zen-lm-state left-margin-width)

      (setq zen-rm-state right-margin-width)

      (setq zen-lf-state left-fringe-width)

      (setq zen-rf-state right-fringe-width)

      (setq zen-fullscreen-state (frame-parameter (selected-frame) 'fullscreen))

      (message "Distraction free enabled")
      (add-to-list 'window-size-change-functions 'zen-mode-refresh-buffer)
      (set-frame-parameter nil 'fullscreen 'fullboth)
      (linum-mode -1)
      (setq right-fringe-width 0)
      (setq left-fringe-width 0)
      (menu-bar-mode -1)
      (tool-bar-mode -1)
      (blink-cursor-mode -1)
      (zen-mode-set-margins)
      (setq zen-run-mode t))))

(defun zen-mode-increase-margin-width()
  "zen-mode-increase-margin-width is a interactive lisp function to increase the margin width in zen-mode (by 5 units)."
  (interactive)
  (setq zen-mode-margin-width (+ zen-mode-margin-width 5))
  (zen-mode-set-margins)
  )

(defun zen-mode-decrease-margin-width()
  "zen-mode-increase-margin-width is a interactive lisp function to increase the margin width in zen-mode (by 5 units)."
  (interactive)
  (setq zen-mode-margin-width (+ zen-mode-margin-width -5))
  (zen-mode-set-margins)
  )

(defun zen-mode-set-margins()
  "zen-mode-set-margins is a lisp function to set the margin width (both left and right)."
  (setq left-margin-width zen-mode-margin-width)
  (setq right-margin-width zen-mode-margin-width)
  (set-window-buffer nil (current-buffer))
  )

(defun zen-mode-refresh-buffer(frame)
  "zen-mode-refresh-buffer is a lisp function to refresh the buffer's margin width when window is resized"
  (setq zen-mode-margin-width (/ (/ (display-pixel-width) (/ (window-pixel-width) (window-width))) 5))
  (zen-mode-set-margins)
  )

(provide 'zen-mode)

;; coding: utf-8
;; End:
;;; zen-mode.el ends here