[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/logos 187081f922 1/4: Add Olivetti; more options; abstr
From: |
ELPA Syncer |
Subject: |
[elpa] externals/logos 187081f922 1/4: Add Olivetti; more options; abstract state change |
Date: |
Sun, 13 Mar 2022 03:57:39 -0400 (EDT) |
branch: externals/logos
commit 187081f922bddeed7f0f62e9891999b161831fe4
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Add Olivetti; more options; abstract state change
---
README.org | 54 +++++++++++++++++------------
logos.el | 114 ++++++++++++++++++++++++++++++++++++++++++++++---------------
2 files changed, 119 insertions(+), 49 deletions(-)
diff --git a/README.org b/README.org
index 9eed35ae7d..45b740ae2f 100644
--- a/README.org
+++ b/README.org
@@ -99,12 +99,18 @@ to narrow effectively. Such users may still want to bind
it to a key.
#+vindex: logos-hide-mode-line
#+vindex: logos-scroll-lock
#+vindex: logos-variable-pitch
+#+vindex: logos-indicate-buffer-boundaries
+#+vindex: logos-buffer-read-only
+#+vindex: logos-olivetti
Logos provides some optional aesthetic tweaks which come into effect
when the buffer-local ~logos-focus-mode~ is enabled. These will hide
-the mode line (~logos-hide-mode-line~), enable ~scroll-lock-mode~
-(~logos-scroll-lock~), and use ~variable-pitch-mode~ in non-programming
-buffers (~logos-variable-pitch~). All these variables are
-buffer-local.
+the mode line (~logos-hide-mode-line~), disable the buffer boundary
+indicators (~indicate-buffer-boundaries~), enable ~scroll-lock-mode~
+(~logos-scroll-lock~), use ~variable-pitch-mode~ in non-programming
+buffers (~logos-variable-pitch~), make the buffer read-only
+(~logos-buffer-read-only~), and center the buffer in its window if the
+=olivetti= package is installed (~logos-olivetti~). All these variables
+are buffer-local.
Logos is the familiar word derived from Greek (watch my presentation on
philosophy about Cosmos, Logos, and the living universe:
@@ -181,9 +187,11 @@ changes out-of-the-box
([[#h:2bb57369-352a-43bf-afe3-0bed2fcc7359][Extra tweaks]
+ To have quick access to ~logos-focus-mode~, bind it to a key. This
mode checks the variables ~logos-hide-mode-line~, ~logos-scroll-lock~,
- ~logos-variable-pitch~ and applies their effects if they are non-nil.
- Note that everything is buffer-local, so it is possible to use file
- variables as described in the Emacs manual.
+ ~logos-variable-pitch~, ~logos-indicate-buffer-boundaries~,
+ ~logos-buffer-read-only~, ~logos-olivetti~ (requires =olivetti=
+ package) and applies their effects if they are non-nil. Note that
+ everything is buffer-local, so it is possible to use file variables as
+ described in the Emacs manual.
#+begin_src emacs-lisp
(require 'logos)
@@ -197,9 +205,12 @@ changes out-of-the-box
([[#h:2bb57369-352a-43bf-afe3-0bed2fcc7359][Extra tweaks]
;; These apply when `logos-focus-mode' is enabled. Their value is
;; buffer-local.
-(setq-default logos-hide-mode-line nil)
-(setq-default logos-scroll-lock nil)
-(setq-default logos-variable-pitch nil)
+(setq-default logos-hide-mode-line nil
+ logos-scroll-lock nil
+ logos-variable-pitch nil
+ logos-indicate-buffer-boundaries nil
+ logos-buffer-read-only nil
+ logos-olivetti nil)
(let ((map global-map))
(define-key map [remap narrow-to-region] #'logos-narrow-dwim)
@@ -224,22 +235,21 @@ motions through the ~logos-page-motion-hook~.
:END:
#+cindex: Automatically toggle olivetti-mode
-Use the excellent =olivetti= package by Paul W. Rankin. Here we
-configure Olivetti to take effect when we enter ~logos-focus-mode~ and
-be disabled when we exit.
+Install the excellent =olivetti= package by Paul W. Rankin. Then set
+~logos-olivetti~ to non-nil.
+
+The present author's favourite settings given that a ~fill-column~ of
+=72=:
#+begin_src emacs-lisp
-;; glue code for `logos-focus-mode' and `olivetti-mode'
-(defun my-logos--olivetti-mode ()
- "Toggle `olivetti-mode'."
- (if (or (bound-and-true-p olivetti-mode)
- (null (logos--focus-p)))
- (olivetti-mode -1)
- (olivetti-mode 1)))
-
-(add-hook 'logos-focus-mode-hook #'my-logos--olivetti-mode)
+(setq olivetti-body-width 0.7
+ olivetti-minimum-body-width 80
+ olivetti-recall-visual-line-mode-entry-state t)
#+end_src
+Though note that Olivetti works well even without a ~fill-column~ and
+~auto-fill-mode~ disabled.
+
** Automatically reveal Org or Outline subtree
:PROPERTIES:
:CUSTOM_ID: h:e18f828f-f9a8-4821-b73b-46793be57abb
diff --git a/logos.el b/logos.el
index d027126d8e..435b1fd207 100644
--- a/logos.el
+++ b/logos.el
@@ -118,6 +118,27 @@ This is only relevant when `logos-focus-mode' is enabled."
:group 'logos
:local t)
+(defcustom logos-indicate-buffer-boundaries nil
+ "If non-nil locally disable `indicate-buffer-boundaries'.
+This is only relevant when `logos-focus-mode' is enabled."
+ :type 'boolean
+ :group 'logos
+ :local t)
+
+(defcustom logos-buffer-read-only nil
+ "If non-nil make buffer read-only.
+This applies when `logos-focus-mode' is enabled."
+ :type 'boolean
+ :group 'logos
+ :local t)
+
+(defcustom logos-olivetti nil
+ "If non-nil center buffer in its window with Olivetti package.
+This is only relevant when `logos-focus-mode' is enabled."
+ :type 'boolean
+ :group 'logos
+ :local t)
+
;;;; General utilities
(defun logos--focus-p ()
@@ -256,6 +277,29 @@ If narrowing is in effect, widen the view."
;;;; Optional "focus mode" and utilities
+;; I learnt about the method of using `logos--mode' and `logos--set'
+;; from Daniel Mendler: <https://github.com/minad>.
+(defvar-local logos--restore nil)
+
+(defun logos--mode (mode arg)
+ "Set MODE to ARG.
+ARG is either 1 or -1. The current value changes to its
+alternate, thus toggling MODE."
+ (let ((old (if (and (boundp mode) (symbol-value mode)) 1 -1)))
+ (unless (eq old arg)
+ (push (lambda () (funcall mode old)) logos--restore)
+ (funcall mode arg))))
+
+(defun logos--set (var val)
+ "Set VAR to buffer-local VAL."
+ (let ((old (and (boundp var) (symbol-value var))))
+ (unless (equal old val)
+ (set var val)
+ (if (local-variable-p var)
+ (push (lambda () (set var old)) logos--restore)
+ (make-local-variable var)
+ (push (lambda () (kill-local-variable var)) logos--restore)))))
+
(define-minor-mode logos-focus-mode
"Buffer-local mode for focused editing.
When enabled it sets the buffer-local value of these user
@@ -264,42 +308,58 @@ options: `logos-scroll-lock', `logos-variable-pitch',
:init-value nil
:global nil
:lighter " Λ" ; lambda majuscule
- (logos--setup))
+ (mapc #'funcall logos--restore)
+ (setq logos--restore nil)
+ (when logos-focus-mode
+ (logos--setup)))
(defun logos--setup ()
- "Setup aesthetics for presentation."
- (logos--variable-pitch-toggle)
+ "Set up aesthetics for presentation."
+ ;; modes
+ (logos--variable-pitch)
(logos--scroll-lock)
- (logos--hide-mode-line))
+ (logos--olivetti)
+ ;; variables
+ (logos--hide-mode-line)
+ (logos--indicate-buffer-boundaries)
+ (logos--buffer-read-only))
-(defun logos--variable-pitch-toggle ()
- "Make text use `variable-pitch' face, except for programming."
- (when (and logos-variable-pitch
- (derived-mode-p 'text-mode))
- (if (or (bound-and-true-p buffer-face-mode)
- (null (logos--focus-p)))
- (variable-pitch-mode -1)
- (variable-pitch-mode 1))))
+(defun logos--variable-pitch ()
+ "Set `logos-variable-pitch'."
+ (when (and logos-variable-pitch (derived-mode-p 'text-mode))
+ (logos--mode 'variable-pitch-mode 1)))
(defun logos--scroll-lock ()
- "Keep the point at the centre."
+ "Set `logos-scroll-lock'."
(when logos-scroll-lock
- (if (or (bound-and-true-p scroll-lock-mode)
- (null (logos--focus-p)))
- (scroll-lock-mode -1)
- (recenter nil)
- (scroll-lock-mode 1))))
-
-;; Based on Paul W. Rankin's code:
-;; <https://gist.github.com/rnkn/a522429ed7e784ae091b8760f416ecf8>.
+ (logos--mode 'scroll-lock-mode 1)))
+
+(defun logos--indicate-buffer-boundaries ()
+ "Set `logos-indicate-buffer-boundaries'."
+ (when logos-indicate-buffer-boundaries
+ (logos--set 'indicate-buffer-boundaries nil)))
+
+;; FIXME 2022-03-13: The mode line is not redrawn properly. Not even
+;; with `force-mode-line-update', unless something happens like
+;; switching to the other window. Using `redisplay' does not fix the
+;; issue. I can reproduce the problem on both Emacs 29 and 27.
+;;
+;; When using `logos-olivetti' the problem no longer occurs, presumably
+;; because Olivetti triggers some kind of redraw. Which one?
(defun logos--hide-mode-line ()
- "Toggle mode line visibility."
+ "Set `logos-hide-mode-line'."
(when logos-hide-mode-line
- (if (or (null mode-line-format)
- (null (logos--focus-p)))
- (kill-local-variable 'mode-line-format)
- (setq-local mode-line-format nil)
- (force-mode-line-update))))
+ (logos--set 'mode-line-format nil)))
+
+(defun logos--buffer-read-only ()
+ "Set `logos-buffer-read-only'."
+ (when logos-buffer-read-only
+ (logos--set 'buffer-read-only t)))
+
+(defun logos--olivetti ()
+ "Set `logos-olivetti'."
+ (when (and logos-olivetti (require 'olivetti nil t))
+ (logos--mode 'olivetti-mode 1)))
(provide 'logos)
;;; logos.el ends here