Skip to content

Commit

Permalink
tweak(writeroom): minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Mar 23, 2023
1 parent e8025e9 commit a1bc1a8
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions modules/me-ui.el
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
:group 'minemacs
:type 'float)
(defcustom +writeroom-enable-mixed-pitch t
"Enable `mixed-pitch-mode' with `writeroom-mode' for some modes (Org, Markdown, etc.)."
"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)
Expand All @@ -33,27 +38,27 @@
(writeroom-maximize-window nil)
(writeroom-fullscreen-effect 'maximized)
:config
(defvar-local +writeroom-line-num-was-activate-p nil)
(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-num-was-activate-p display-line-numbers-type)
(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-num-was-activate-p)
(display-line-numbers-mode +writeroom-line-num-was-activate-p)))
+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 '(rst-mode markdown-mode org-mode)))
(apply #'derived-mode-p +writeroom-mixed-pitch-modes))
(require 'mixed-pitch)
(mixed-pitch-mode (if writeroom-mode 1 -1))))

Expand All @@ -68,18 +73,25 @@
(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))
(setq org-format-latex-options
(plist-put org-format-latex-options
:scale (if (+emacs-features-p 'pgtk) 1.4 2.1)))))
(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 org-format-latex-options
(plist-put org-format-latex-options
:scale (or +writeroom-org-format-latex-scale 1.0)))))))
(setq-local
org-format-latex-options
(plist-put org-format-latex-options
:scale (or +writeroom-org-format-latex-scale 1.0)))))))

(use-package mixed-pitch
:straight t
Expand Down

0 comments on commit a1bc1a8

Please sign in to comment.