大家好,在用 org-roam 的时候,我希望专注写东西。
以前进入 roam 之后, 整个屏幕我只开一个 window
,比较恼火的地方
是,我的目光得集中到屏幕的左上角。 而我希望的是,我写 roam 的卡片
的 window
在屏幕中央。
受到 Paul Rademacher elisp - Changing margin for emacs text-mode - Stack Overflow 的启发,小修改了一下他的函数,这样我就可以只在 roam 目录下集中我 的注意力了。
(defun center-window (window)
"Switch to column mode when:
1. within the org-roam folder
2. opening .org file
;; -------------------------------------------------------------
;; almost copy from https://stackoverflow.com/a/23731877/4565840
;; thanks to Paul Rademacher
"
(let* ((current-extension (file-name-extension (or (buffer-file-name) "foo.unknown")))
(filename (buffer-file-name (current-buffer)))
(max-text-width 80)
(margin (max 0 (/ (- (window-width window) max-text-width) 2))))
(if (and (string-match-p (expand-file-name org-roam-directory) (format "%s" filename))
(string= (file-name-extension (buffer-file-name (current-buffer))) "org"))
(set-window-margins window margin margin)
())))
(defun center-windows () ""
(walk-windows (lambda (window) (center-window window)) nil 1))
(add-hook 'window-configuration-change-hook 'center-windows)