Make things a bit more configurable

This commit is contained in:
larstvei 2024-09-15 01:52:25 +02:00
parent 1db2c7bff6
commit f1a1c4a172

View File

@ -1,4 +1,4 @@
;;; center-content.el --- Center buffer content horizontally and vertically -*- lexical-binding: t; -*- ;;; center-content.el --- Center buffer content -*- lexical-binding: t; -*-
;;; Commentary: ;;; Commentary:
@ -9,13 +9,33 @@
(require 'face-remap) (require 'face-remap)
(defgroup center-content ()
"Center buffer content."
:group 'convinience
:prefix "center-content-")
(defcustom center-content-horizontal t
"Enable horizontal centering."
:type 'boolean
:group 'center-content)
(defcustom center-content-vertical t
"Enable vertical centering."
:type 'boolean
:group 'center-content)
(defcustom center-content-hide-mode-line t
"Hide mode-line when centering."
:type 'boolean
:group 'center-content)
(defvar-local center-content--horizontal-overlay nil (defvar-local center-content--horizontal-overlay nil
"Overlay used to add left margin for horizontal centering.") "Overlay used to add left margin for horizontal centering.")
(defvar-local center-content--original-header-line-format nil (defvar-local center-content--original-header-line-format header-line-format
"Stores the original `header-line-format` to restore upon disabling.") "Stores the original `header-line-format` to restore upon disabling.")
(defvar-local center-content--original-mode-line-format nil (defvar-local center-content--original-mode-line-format mode-line-format
"Stores the original `mode-line-format` to restore upon disabling.") "Stores the original `mode-line-format` to restore upon disabling.")
(defvar-local center-content--header-line-face-remap-cookie nil (defvar-local center-content--header-line-face-remap-cookie nil
@ -57,10 +77,13 @@
(defun center-content--enable () (defun center-content--enable ()
"Enable horizontal and vertical centering of content." "Enable horizontal and vertical centering of content."
(let* ((content-size (center-content--content-pixel-size))) (let* ((content-size (center-content--content-pixel-size)))
(center-content--horizontal (car content-size)) (when center-content-horizontal
(center-content--vertical (cdr content-size)) (center-content--horizontal (car content-size)))
(setq center-content--original-mode-line-format mode-line-format) (when center-content-vertical
(setq mode-line-format nil))) (center-content--vertical (cdr content-size)))
(when center-content-hide-mode-line
(setq center-content--original-mode-line-format mode-line-format)
(setq mode-line-format nil))))
(defun center-content--disable () (defun center-content--disable ()
"Disable centering of content." "Disable centering of content."
@ -74,13 +97,8 @@
(setq center-content--header-line-face-remap-cookie nil)) (setq center-content--header-line-face-remap-cookie nil))
;; Restore the header-line-format ;; Restore the header-line-format
(setq header-line-format center-content--original-header-line-format) (setq header-line-format center-content--original-header-line-format)
(setq center-content--original-mode-line-format nil)
;; Restore the original mode-line-format ;; Restore the original mode-line-format
(setq mode-line-format center-content--original-mode-line-format) (setq mode-line-format center-content--original-mode-line-format))
(setq center-content--original-header-line-format nil)
;; Force redisplay
(force-mode-line-update)
(redisplay))
;;;###autoload ;;;###autoload
(define-minor-mode center-content-mode (define-minor-mode center-content-mode