blob: e5eafac3e0e43e2e6f8200e32da764c7d3a0bf2a (
plain)
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
|
;;; centered-window-mode.el --- Center the text when there's only one window
;;
;; Copyright (C) 2014 Anler Hp <http://anler.me>
;;
;; Author: Anler Hp <http://anler.me>
;; Version: 0.0.1
;; Keywords: faces, windows
;; URL: https://github.com/ikame/centered-window-mode
;; Compatibility: GNU Emacs 23.x, GNU Emacs 24.x
;;
;; This file is NOT part of GNU Emacs.
;;
;; 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 2
;; 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:
;;
;; Enable centered-window-mode and your text is going to be centered when there's
;; only one window in the frame.
;;
;;; Changes Log:
;;
;;; Code:
(defvar fringe-background nil "The background color used for the fringe")
(defadvice switch-to-buffer (after cwm/switch-to-buffer activate)
(cwm/window-configuration-change))
(defun cwm/setup ()
(add-hook 'window-configuration-change-hook
'cwm/window-configuration-change
nil
t)
(cwm/window-configuration-change))
(defun cwm/teardown ()
(remove-hook 'window-configuration-change-hook
'cwm/window-configuration-change
t)
(cwm/window-configuration-change))
(defadvice split-window-right (before cwm/reset-on-split activate)
"Disable cwm-mode presentation (if active) before splitting window"
(when fringe-mode
(cwm/reset)))
(defadvice load-theme (after cwm/set-faces-on-load-theme activate)
"Change the default fringe background whenever the theme changes"
(message "load theme after here")
(cwm/update-fringe-background))
(defun cwm/window-configuration-change ()
(if (or (> (length (window-list)) 1)
(null centered-window-mode))
(cwm/reset)
(cwm/center)))
(defun cwm/center ()
(set-window-fringes
nil
(/ (- (frame-pixel-width)
(* 110 (frame-char-width)))
2)))
(defun cwm/reset ()
(set-window-fringes nil nil))
(defun cwm/set-faces ()
(custom-set-faces
`(fringe ((t (:background ,fringe-background))))))
(defun cwm/update-fringe-background ()
(setq fringe-background (cwm/get-fringe-background))
(cwm/set-faces))
(defun cwm/get-fringe-background ()
(face-attribute 'default :background))
(cwm/update-fringe-background)
;;;###autoload
(define-minor-mode centered-window-mode
"Minor mode to cwm on the current buffer."
:init-value nil
:lighter " ⌗"
(if centered-window-mode
(cwm/setup)
(cwm/teardown)))
(provide 'centered-window-mode)
;;; centered-window-mode.el ends here
|