From f1a1c4a172215e84a70ef3daea482d259990bed5 Mon Sep 17 00:00:00 2001 From: larstvei Date: Sun, 15 Sep 2024 01:52:25 +0200 Subject: [PATCH] Make things a bit more configurable --- center-content.el | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/center-content.el b/center-content.el index 6bc66cc..521a666 100644 --- a/center-content.el +++ b/center-content.el @@ -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: @@ -9,13 +9,33 @@ (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 "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.") -(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.") (defvar-local center-content--header-line-face-remap-cookie nil @@ -57,10 +77,13 @@ (defun center-content--enable () "Enable horizontal and vertical centering of content." (let* ((content-size (center-content--content-pixel-size))) - (center-content--horizontal (car content-size)) - (center-content--vertical (cdr content-size)) - (setq center-content--original-mode-line-format mode-line-format) - (setq mode-line-format nil))) + (when center-content-horizontal + (center-content--horizontal (car content-size))) + (when center-content-vertical + (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 () "Disable centering of content." @@ -74,13 +97,8 @@ (setq center-content--header-line-face-remap-cookie nil)) ;; Restore the 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 - (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)) + (setq mode-line-format center-content--original-mode-line-format)) ;;;###autoload (define-minor-mode center-content-mode