summaryrefslogtreecommitdiff
path: root/center-buffer.el
blob: 69d4a902af5788d5bdd2e5f99924324a08ee9f8c (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
;;; center-buffer.el --- Center the buffer -*- lexical-binding: t; -*-

;;; Commentary:

;;; This is some code I extracted from "olivetti" as a lightweight
;;; version of that package to center my buffer, only temporarily,
;;; unfortunately.

;;; Code:

;;;###autoload
(defvar center-buffer-width 80
  "The width of the body.")

;;;###autoload
(defun center-buffer-on ()
  "Center the buffer."
  (interactive)
  (let* ((mt (/ (- (window-total-width) 80) 2))
	 (fringes (window-fringes))
	 (lf (/ (car fringes) (float (frame-char-width))))
	 (rf (/ (cadr fringes) (float (frame-char-width))))
	 (lm (max (round (- mt lf)) 0))
	 (rm (max (round (- mt rf)) 0)))
    (set-window-margins (selected-window) lm rm)))

;;;###autoload
(defun center-buffer-off ()
  "Reset buffer."
  (interactive)
  (set-window-margins (selected-window) 0 0))





(provide 'center-bufrfer)
;;; center-bufrfer.el ends here.