Skip to content

Commit

Permalink
revert: replace writeroom-mode with simpler config
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Mar 23, 2023
1 parent 6d2550c commit 4c2255d
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 80 deletions.
23 changes: 23 additions & 0 deletions core/me-loaddefs.el
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,29 @@ Register dictionaries for `LANGS` to spell-fu's multi-dict.

(register-definition-prefixes "me-vars" '("+env-save-vars" "emacs/features" "minemacs-" "os/" "sys/arch"))


;;; Generated autoloads from ../modules/extras/me-writing-mode.el

(autoload '+writing-mode "../modules/extras/me-writing-mode" "\
A mode for writing without distraction.
This is a minor mode. If called interactively, toggle the
`+Writing mode' mode. If the prefix argument is positive, enable
the mode, and if it is zero or negative, disable the mode.
If called from Lisp, toggle the mode if ARG is `toggle'. Enable
the mode if ARG is nil, omitted, or is a positive number.
Disable the mode if ARG is a negative number.
To check whether the minor mode is enabled in the current buffer,
evaluate `+writing-mode'.
The mode's hook is called both when the mode is enabled and when
it is disabled.
(fn &optional ARG)" t)
(register-definition-prefixes "../modules/extras/me-writing-mode" '("+writing-"))


;;; Generated autoloads from ../elisp/netextender.el

Expand Down
97 changes: 97 additions & 0 deletions modules/extras/me-writing-mode.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
;;; me-write-mode.el --- Simple writing-centered mode -*- lexical-binding: t; -*-

;; Copyright (C) 2022-2023 Abdelhak Bougouffa

;; Author: Abdelhak Bougouffa (concat "abougouffa" "@" "fedora" "project" "." "org")

(require 'visual-fill-column)
(require 'mixed-pitch nil t)

(defcustom +writing-mode-enable-hook nil
"Execute hooks on enable."
:group 'minemacs-ui
:type 'hook)

(defcustom +writing-mode-disable-hook nil
"Execute hooks on disable."
:group 'minemacs-ui
:type 'hook)

(defcustom +writing-text-scale 1.7
"The text-scaling level for `+writing-mode'."
:group 'minemacs-ui
:type 'float)

(defcustom +writing-text-width nil
"Like `visual-fill-column-width'."
:group 'minemacs-ui
:type '(choice
(const :tag "Use `fill-column'" :value nil)
(integer :tag "Specify width" :value 70)))

(defcustom +writing-mixed-pitch-enable t
"Enable `mixed-pitch-mode' with `+writing-mode' for some modes defined in `+writing-mixed-pitch-modes'."
:group 'minemacs-ui
:type 'boolean)

(defcustom +writing-mixed-pitch-modes
'(rst-mode markdown-mode org-mode)
"Enable `mixed-pitch-mode' with `+writing-mode' for these modes."
:group 'minemacs-ui
:type '(repeat symbol))

(defvar-local +writing--line-nums-active-p nil)
(defvar-local +writing--org-format-latex-scale nil)

(defun +writing--scale-up-org-latex ()
(setq-local
+writing--org-format-latex-scale
(plist-get org-format-latex-options :scale)
org-format-latex-options
(plist-put
org-format-latex-options
:scale
(* ;; The scale from current font
(/ (float (or (face-attribute 'default :height) 100)) 100.0)
;; Proportional upscaling
(/ +writing-text-scale (if (+emacs-features-p 'pgtk) 1.8 1.4))))))

(defun +writing--scale-down-org-latex ()
(setq-local
org-format-latex-options
(plist-put org-format-latex-options
:scale (or +writing--org-format-latex-scale 1.0))))

;;;###autoload
(define-minor-mode +writing-mode
"A mode for writing without distraction."
:init-value nil :lighter "Zen" :global nil
(let ((mixed-pitch-mode-p (seq-filter #'derived-mode-p +writing-mixed-pitch-modes)))
(if +writing-mode
;; Enable
(progn
(setq-local visual-fill-column-center-text t
visual-fill-column-width +writing-text-width)
(when (and mixed-pitch-mode-p (bound-and-true-p display-line-numbers-mode))
(setq-local +writing--line-nums-active-p display-line-numbers-type)
(display-line-numbers-mode -1))
(+writing--scale-up-org-latex)
(run-hooks +writing-mode-enable-hook))
;; Disable
(kill-local-variable 'visual-fill-column-center-text)
(kill-local-variable 'visual-fill-column-width)
(+writing--scale-down-org-latex)
(when (and +writing--line-nums-active-p mixed-pitch-mode-p)
(display-line-numbers-mode +writing--line-nums-active-p)))

(visual-fill-column-mode (if +writing-mode 1 -1))

(when (fboundp 'mixed-pitch-mode)
(mixed-pitch-mode (if (and +writing-mode mixed-pitch-mode-p +writing-mixed-pitch-enable) 1 -1)))

(when (/= +writing-text-scale 0.0)
(text-scale-set (if +writing-mode +writing-text-scale 0.0))
(visual-fill-column-adjust))))


(provide 'me-writing-mode)
87 changes: 7 additions & 80 deletions modules/me-ui.el
Original file line number Diff line number Diff line change
Expand Up @@ -10,88 +10,11 @@
:custom
(svg-lib-icons-dir (concat minemacs-cache-dir "svg-lib/icons/")))

(use-package writeroom-mode
(use-package visual-fill-column
:straight t
:init
(+map! "tw" #'writeroom-mode)
(defcustom +writeroom-text-scale 1.7
"The text-scaling level for `writeroom-mode'."
:group 'minemacs
:type 'float)
(defcustom +writeroom-enable-mixed-pitch t
"Enable `mixed-pitch-mode' with `writeroom-mode' for some modes defined in `+writeroom-mixed-pitch-modes'."
:group 'minemacs
:type 'boolean)
(defcustom +writeroom-mixed-pitch-modes
'(rst-mode markdown-mode org-mode)
"Enable `mixed-pitch-mode' with `writeroom-mode' for these modes."
:group 'minemacs
:type 'boolean)
:hook (writeroom-mode . +writeroom--enable-text-scaling-mode-h)
:hook (writeroom-mode . +writeroom--enable-mixed-pitch-mode-maybe-h)
:hook (writeroom-mode-enable . +writeroom--disable-line-numbers-mode-h)
:hook (writeroom-mode-disable . +writeroom--restore-line-numbers-mode-h)
:custom
(writeroom-width 80)
(writeroom-mode-line t)
(writeroom-global-effects nil)
(writeroom-maximize-window nil)
(writeroom-fullscreen-effect 'maximized)
:config
(defvar-local +writeroom-line-nums-was-active-p nil)
(defvar-local +writeroom-org-format-latex-scale nil)

;; Disable line numbers when in Org mode
(defun +writeroom--disable-line-numbers-mode-h ()
(when (and (or (derived-mode-p 'org-mode)
(derived-mode-p 'markdown-mode))
(bound-and-true-p display-line-numbers-mode))
(setq-local +writeroom-line-nums-was-active-p display-line-numbers-type)
(display-line-numbers-mode -1)))

(defun +writeroom--restore-line-numbers-mode-h ()
(when (and (or (derived-mode-p 'org-mode)
(derived-mode-p 'markdown-mode))
+writeroom-line-nums-was-active-p)
(display-line-numbers-mode +writeroom-line-nums-was-active-p)))

(defun +writeroom--enable-mixed-pitch-mode-maybe-h ()
"Enable `mixed-pitch-mode' when in supported modes."
(when (and +writeroom-enable-mixed-pitch
(apply #'derived-mode-p +writeroom-mixed-pitch-modes))
(require 'mixed-pitch)
(mixed-pitch-mode (if writeroom-mode 1 -1))))

(defun +writeroom--enable-text-scaling-mode-h ()
"Enable text scaling."
(when (/= +writeroom-text-scale 0.0)
(text-scale-set (if writeroom-mode +writeroom-text-scale 0.0))
(visual-fill-column-adjust)))

(with-eval-after-load 'org
;; Increase latex previews scale in Zen mode
(add-hook
'writeroom-mode-enable-hook
(defun +writeroom--scale-up-latex-h ()
(setq-local
+writeroom-org-format-latex-scale
(plist-get org-format-latex-options :scale)
org-format-latex-options
(plist-put
org-format-latex-options
:scale
(* ;; The scale from current font
(/ (float (or (face-attribute 'default :height) 100)) 100.0)
;; Proportional upscaling
(/ +writeroom-text-scale (if (+emacs-features-p 'pgtk) 1.8 1.4)))))))

(add-hook
'writeroom-mode-disable-hook
(defun +writeroom--scale-down-latex-h ()
(setq-local
org-format-latex-options
(plist-put org-format-latex-options
:scale (or +writeroom-org-format-latex-scale 1.0)))))))
(visual-fill-column-width nil)
(visual-fill-column-center-text t))

(use-package mixed-pitch
:straight t
Expand Down Expand Up @@ -137,6 +60,10 @@
font-lock-comment-face
font-lock-comment-delimiter-face)))))

(use-package me-writing-mode
:init
(+map! "tw" #'+writing-mode))

(use-package page-break-lines
:straight t
:hook ((prog-mode text-mode special-mode) . page-break-lines-mode))
Expand Down
92 changes: 92 additions & 0 deletions modules/obsolete/me-writeroom.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
;;; me-flycheck.el --- Programming stuff -*- lexical-binding: t; -*-

;; Copyright (C) 2022-2023 Abdelhak Bougouffa

;; Author: Abdelhak Bougouffa (concat "abougouffa" "@" "fedora" "project" "." "org")


(use-package writeroom-mode
:straight t
:init
(+map! "tw" #'writeroom-mode)
(defcustom +writeroom-text-scale 1.7
"The text-scaling level for `writeroom-mode'."
:group 'minemacs-ui
:type 'float)
(defcustom +writeroom-enable-mixed-pitch t
"Enable `mixed-pitch-mode' with `writeroom-mode' for some modes defined in `+writeroom-mixed-pitch-modes'."
:group 'minemacs-ui
:type 'boolean)
(defcustom +writeroom-mixed-pitch-modes
'(rst-mode markdown-mode org-mode)
"Enable `mixed-pitch-mode' with `writeroom-mode' for these modes."
:group 'minemacs-ui
:type 'boolean)
:hook (writeroom-mode . +writeroom--enable-text-scaling-mode-h)
:hook (writeroom-mode . +writeroom--enable-mixed-pitch-mode-maybe-h)
:hook (writeroom-mode-enable . +writeroom--disable-line-numbers-mode-h)
:hook (writeroom-mode-disable . +writeroom--restore-line-numbers-mode-h)
:custom
(writeroom-width 80)
(writeroom-mode-line t)
(writeroom-global-effects nil)
(writeroom-maximize-window nil)
(writeroom-fullscreen-effect 'maximized)
:config
(defvar-local +writeroom-line-nums-was-active-p nil)
(defvar-local +writeroom-org-format-latex-scale nil)

;; Disable line numbers when in Org mode
(defun +writeroom--disable-line-numbers-mode-h ()
(when (and (or (derived-mode-p 'org-mode)
(derived-mode-p 'markdown-mode))
(bound-and-true-p display-line-numbers-mode))
(setq-local +writeroom-line-nums-was-active-p display-line-numbers-type)
(display-line-numbers-mode -1)))

(defun +writeroom--restore-line-numbers-mode-h ()
(when (and (or (derived-mode-p 'org-mode)
(derived-mode-p 'markdown-mode))
+writeroom-line-nums-was-active-p)
(display-line-numbers-mode +writeroom-line-nums-was-active-p)))

(defun +writeroom--enable-mixed-pitch-mode-maybe-h ()
"Enable `mixed-pitch-mode' when in supported modes."
(when (and +writeroom-enable-mixed-pitch
(apply #'derived-mode-p +writeroom-mixed-pitch-modes))
(require 'mixed-pitch)
(mixed-pitch-mode (if writeroom-mode 1 -1))))

(defun +writeroom--enable-text-scaling-mode-h ()
"Enable text scaling."
(when (/= +writeroom-text-scale 0.0)
(text-scale-set (if writeroom-mode +writeroom-text-scale 0.0))
(visual-fill-column-adjust)))

(with-eval-after-load 'org
;; Increase latex previews scale in Zen mode
(add-hook
'writeroom-mode-enable-hook
(defun +writeroom--scale-up-latex-h ()
(setq-local
+writeroom-org-format-latex-scale
(plist-get org-format-latex-options :scale)
org-format-latex-options
(plist-put
org-format-latex-options
:scale
(* ;; The scale from current font
(/ (float (or (face-attribute 'default :height) 100)) 100.0)
;; Proportional upscaling
(/ +writeroom-text-scale (if (+emacs-features-p 'pgtk) 1.8 1.4)))))))

(add-hook
'writeroom-mode-disable-hook
(defun +writeroom--scale-down-latex-h ()
(setq-local
org-format-latex-options
(plist-put org-format-latex-options
:scale (or +writeroom-org-format-latex-scale 1.0)))))))


(provide 'obsolete/me-writeroom)

0 comments on commit 4c2255d

Please sign in to comment.