summaryrefslogtreecommitdiff
path: root/center-buffer.el
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2021-01-09 14:22:00 +0800
committerJSDurand <mmemmew@gmail.com>2021-01-09 14:22:00 +0800
commitdc206ebe9397d656971ba7fc3a092009ef4e797a (patch)
treed963873011122fdf0eafeba89afd487115994bc5 /center-buffer.el
parenta2f7f2bf9077ba8acfc550575b9e21aa9ffe7bae (diff)
temporary state
Diffstat (limited to 'center-buffer.el')
-rw-r--r--center-buffer.el38
1 files changed, 38 insertions, 0 deletions
diff --git a/center-buffer.el b/center-buffer.el
new file mode 100644
index 0000000..69d4a90
--- /dev/null
+++ b/center-buffer.el
@@ -0,0 +1,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.