[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 13717fb 17/26: Attempt a clearer design of modes
From: |
João Távora |
Subject: |
[elpa] master 13717fb 17/26: Attempt a clearer design of modes |
Date: |
Fri, 19 Dec 2014 19:07:29 +0000 |
branch: master
commit 13717fbec7ca18c30bf3f3f37354768467ee7758
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Attempt a clearer design of modes
* darkroom.el (darkroom--turn-on): New function.
(darkroom--tentative-mode-driving): Removed this.
(darkroom-mode): Use new `darkroom--turn-on' and
`darkroom--turn-off'.
(darkroom-tentative-mode): Assert that no `darkroom-mode' and
`darkroom-tentative-mode' are mixed.
(darkroom--turn-off): New function.
---
darkroom.el | 72 ++++++++++++++++++++++++++++++++--------------------------
1 files changed, 40 insertions(+), 32 deletions(-)
diff --git a/darkroom.el b/darkroom.el
index 1a6ff43..33e6801 100644
--- a/darkroom.el
+++ b/darkroom.el
@@ -230,9 +230,28 @@ Set by `darkroom--set-margins'")
;; (defvar darkroom--saved-text-scale-mode-amount nil
;; "Text scale before `darkroom-mode' is turned on.")
-(defvar darkroom--tentative-mode-driving nil
- "Non-nil if `darkroom-tentative-mode' toggles
- `darkroom-mode'.")
+(defun darkroom--turn-on ()
+ (set (make-local-variable 'darkroom--saved-margins) (window-margins))
+ (set (make-local-variable 'darkroom--saved-mode-line-format)
+ mode-line-format)
+ (set (make-local-variable 'darkroom--saved-header-line-format)
+ header-line-format)
+ (setq mode-line-format nil)
+ (setq header-line-format nil)
+ (text-scale-increase darkroom-text-scale-increase)
+ (darkroom--set-margins (darkroom--compute-margins))
+ (add-hook 'window-configuration-change-hook 'darkroom--set-margins
+ t t))
+
+(defun darkroom--turn-off ()
+ (setq mode-line-format darkroom--saved-mode-line-format
+ header-line-format darkroom--saved-header-line-format)
+ (text-scale-decrease darkroom-text-scale-increase)
+ (let (darkroom--buffer-margins)
+ (darkroom--set-margins darkroom--saved-margins))
+ (set (make-local-variable 'darkroom--buffer-margins) nil)
+ (remove-hook 'window-configuration-change-hook 'darkroom--set-margins
+ t))
(define-minor-mode darkroom-mode
"Remove visual distractions and focus on writing. When this
@@ -240,52 +259,41 @@ mode is active, everything but the buffer's text is
elided from
view. The buffer margins are set so that text is centered on
screen. Text size is increased (display engine allowing) by
`darkroom-text-scale-increase'." nil nil nil
- (when (and darkroom-tentative-mode
- (not darkroom--tentative-mode-driving))
+ (when darkroom-tentative-mode
(error
- "Don't try to toggle `darkroom-mode' when in `darkroom-tentative-mode'"))
+ "Don't mix `darkroom-mode' and `darkroom-tentative-mode'"))
+ ;; FIXME: unfortunately, signalling an error doesn't prevent the
+ ;; mode from turning itself off. How do I do that?
(cond (darkroom-mode
- (set (make-local-variable 'darkroom--saved-margins) (window-margins))
- (set (make-local-variable 'darkroom--saved-mode-line-format)
- mode-line-format)
- (set (make-local-variable 'darkroom--saved-header-line-format)
- header-line-format)
- (setq mode-line-format nil)
- (setq header-line-format nil)
- (text-scale-increase darkroom-text-scale-increase)
- (darkroom--set-margins (darkroom--compute-margins))
- (add-hook 'window-configuration-change-hook 'darkroom--set-margins
- t t))
+ (darkroom--turn-on))
(t
- (setq mode-line-format darkroom--saved-mode-line-format
- header-line-format darkroom--saved-header-line-format)
- (text-scale-decrease darkroom-text-scale-increase)
- (let (darkroom--buffer-margins)
- (darkroom--set-margins darkroom--saved-margins))
- (remove-hook 'window-configuration-change-hook 'darkroom--set-margins
- t))))
+ (darkroom--turn-off))))
(defun darkroom--maybe-enable ()
(let ((darkroom--tentative-mode-driving t))
- (cond ((and (not darkroom-mode) (= (count-windows) 1))
- (darkroom-mode 1))
- ((and darkroom-mode (> (count-windows) 1))
- (darkroom-mode -1))
+ (cond ((and (not darkroom--buffer-margins) (= (count-windows) 1))
+ (darkroom--turn-on))
+ ((and darkroom--buffer-margins (> (count-windows) 1))
+ (darkroom--turn-off))
(t
- ;; (message "debug: buffer: %s windows: %s darkroom-mode: %s"
- ;; (current-buffer) (count-windows) darkroom-mode)
+ ;; (message "debug: buffer: %s windows: %s
+ ;; darkroom-buffer--margins: %s"
+ ;; (current-buffer) (count-windows)
+ ;; darkroom-buffer--margins)
))))
-
(define-minor-mode darkroom-tentative-mode
"Enters `darkroom-mode' when all other windows are deleted."
nil " Room" nil
+ (when darkroom-mode
+ (error
+ "Don't mix `darkroom-mode' and `darkroom-tentative-mode'"))
(cond (darkroom-tentative-mode
(add-hook 'window-configuration-change-hook
'darkroom--maybe-enable nil t)
(darkroom--maybe-enable))
(t
- (if darkroom-mode (darkroom-mode -1))
+ (darkroom--turn-off)
(remove-hook 'window-configuration-change-hook
'darkroom--maybe-enable t))))
- [elpa] master 744d72a 08/26: Add .gitignore, (continued)
- [elpa] master 744d72a 08/26: Add .gitignore, João Távora, 2014/12/19
- [elpa] master 9cd8dfd 06/26: Now works with multiple windows for same darkroom buffer, João Távora, 2014/12/19
- [elpa] master 786b5a3 10/26: Integrate another comment from Rasmus, João Távora, 2014/12/19
- [elpa] master 6cbfebe 09/26: Integrate some comments from Rasmus, João Távora, 2014/12/19
- [elpa] master b36123e 11/26: Tidy up margin calculation, João Távora, 2014/12/19
- [elpa] master a16a665 01/26: Initial commit, João Távora, 2014/12/19
- [elpa] master 3a1db96 13/26: Add some docstrings, João Távora, 2014/12/19
- [elpa] master a39ab2e 15/26: Minor tweaks, João Távora, 2014/12/19
- [elpa] master 90f5299 14/26: Prefix internal symbols with "darkroom--", João Távora, 2014/12/19
- [elpa] master 8b0daf6 12/26: Add (still non-functioning) `darkroom-compute-margins', João Távora, 2014/12/19
- [elpa] master 13717fb 17/26: Attempt a clearer design of modes,
João Távora <=
- [elpa] master 20d5539 21/26: load cl-lib, João Távora, 2014/12/19
- [elpa] master 4bf9c10 19/26: Fix `darkroom-tentative-mode', João Távora, 2014/12/19
- [elpa] master 1e68955 16/26: Corrections after another review iteration with Rasmus, João Távora, 2014/12/19
- [elpa] master 15e976b 22/26: Merge pull request #1 from syohex/require-cl-lib, João Távora, 2014/12/19
- [elpa] master 9674d79 20/26: Fix automatic margin calculation, João Távora, 2014/12/19
- [elpa] master 2887b5e 18/26: Redesign setting of margins, which now works per-window, João Távora, 2014/12/19
- [elpa] master 96e61a9 26/26: Add packages/darkroom by merging its upstream subtree, João Távora, 2014/12/19
- [elpa] master 5de9a5d 24/26: Fix darkroom-tentative-mode when switching window's buffer, João Távora, 2014/12/19
- [elpa] master 654e5fd 23/26: Fix margin calculation yet again., João Távora, 2014/12/19
- [elpa] master 7a8b5b6 25/26: Prepare for inclusion in GNU ELPA, João Távora, 2014/12/19