-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemcn-view.el
41 lines (33 loc) · 1.26 KB
/
emcn-view.el
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
;; emcn-view.el --- Nextcloud Notes Client for Emacs -*- lexical-binding: t; -*-
(defcustom emcn-note-width 80 "Character width of a note"
:type 'integer
:group 'emcn)
(defun emcn--collapse-margins (window)
(set-window-margins window 0 0))
(defun emcn--split-window-right (&optional size)
"Wraps `split-window-right` to still make it work with large
buffer margins"
(interactive "P")
(emcn--collapse-margins (selected-window))
(split-window-right size))
(defun emcn--window-configuration-change-hook ()
"Make sure the window keeps its styling when window sizes etc. change around"
(if emcn-mode
(emcn-style-window (selected-window))))
(defun emcn--get-viewport-width (window)
"Get body width + margin widths"
(let ((margins (window-margins window)))
(+ (window-body-width window)
(or (car margins) 0)
(or (cdr margins) 0))))
(defun emcn--adjust-margins (window)
"Adjust margins so that the window body is only as wide as
`emcn-note-width`"
(let* ((width (emcn--get-viewport-width window))
(margin (floor (/ (- width emcn-note-width) 2))))
(when (< margin 0)
(setq margin 0))
(set-window-margins window margin margin)))
(defun emcn-style-window (window)
(emcn--adjust-margins window))
(provide 'emcn-view)