-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revert: replace
writeroom-mode
with simpler config
- Loading branch information
1 parent
6d2550c
commit 4c2255d
Showing
4 changed files
with
219 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |