Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randomwangran/8faa505341deb1291ecc95f7d3bfbdf1 to your computer and use it in GitHub Desktop.
Save randomwangran/8faa505341deb1291ecc95f7d3bfbdf1 to your computer and use it in GitHub Desktop.
(defun center-window (window) ""
(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 (not (string-match-p (expand-file-name org-roam-directory) (format "%s" filename)))
(not (string= current-extension "org")))
;; Do nothing if this isn't an .md or .txt file.
()
(set-window-margins window margin margin))))
;; Adjust margins of all windows.
(defun center-windows () ""
(walk-windows (lambda (window) (center-window window)) nil 1))
;; Listen to window changes.
(add-hook 'window-configuration-change-hook 'center-windows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment