blob: 2a70cd680fc6df2a0ba9014d6ff2e8c0cac529a1 (
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
|
;;; -*- lexical-binding: t; -*-
;;; Commentary:
;; yanked from https://codeberg.org/daviwil/dotfiles/src/branch/master/emacs
;;; Code:
(defvar fill-column-desired-width 120
"The desired width of a document centered in the window.")
(defun fill-column--adjust-margins ()
"Resets window margins, then calculates the appropriate
margin given the window width and `fill-column-desired-width'
if fill-column-mode is t."
(set-window-parameter nil 'min-margins nil)
(set-window-margins nil nil)
(when fill-column-mode
(let ((margin-width (max 0
(truncate
(/ (- (window-width)
fill-column-desired-width)
2.0)))))
(when (> margin-width 0)
(set-window-parameter nil 'min-margins '(0 . 0))
(set-window-margins nil margin-width margin-width)))))
(define-minor-mode fill-column-mode
"Toggle centered text layout in the current buffer."
:lighter " Centered"
:group 'editing
(if fill-column-mode
(add-hook 'window-configuration-change-hook #'fill-column--adjust-margins 'append 'local)
(remove-hook 'window-configuration-change-hook #'fill-column--adjust-margins 'local))
(fill-column--adjust-margins))
(provide 'fill-column)
;;; fill-column ends here
|