From 953a89d762763da1c7d408aaa20f2b73b7c512c0 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Thu, 3 Jul 2014 16:03:37 -0700 Subject: [PATCH] add spray-ramp to slow down words initially --- Readme.org | 3 +++ spray.el | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Readme.org b/Readme.org index 09b323a..de7876a 100644 --- a/Readme.org +++ b/Readme.org @@ -92,6 +92,7 @@ You may customize spray by modifying following items: - [Variable] spray-height - [Variable] spray-margin-top - [Variable] spray-margin-left +- [Variable] spray-ramp - [Keymap] spray-mode-map - [Face] spray-base-face - [Face] spray-accent-face @@ -107,6 +108,8 @@ Words are split at space, tab, newline, and emdash characters. If any of the cha Each word is displayed for (60 / the choosen wpm) seconds, except if the word ends with ,:— or is greater than 9 characters long, in which case it is displayed for twice as long. +When started, an added delay is optionally added, based on the spray-ramp variable. See it's documentation for details. + The accent location is chosen as the nth character in a word, depending on its length, based on the following table | length | accent position | | 1 | 1 | diff --git a/spray.el b/spray.el index 1ebdab2..977fc6f 100644 --- a/spray.el +++ b/spray.el @@ -38,6 +38,8 @@ ;; Known bugs. ;; repeated words are indistinguishable, for example ;; "going, going, gone" reads like going, gone, with a slight delay. +;; +;; sentences (like this) should trigger a pause for ( and ) ;;; Change Log: ;; 0.0.0 test release @@ -54,6 +56,9 @@ (defvar spray-height 400 "height of characters") (defvar spray-margin-top 1 "character margin at top of buffer. Characters are as big as spray text characters.") (defvar spray-margin-left 1 "character margin at left of buffer. Characters are as big as spray text characters.") +(defvar spray-ramp 2 + "Ramp up to full speed. Pause for this multiple of wpm on the first word, +decreasing by one for each subsequent word.") (defvar spray-mode-map (let ((km (make-sparse-keymap))) @@ -91,6 +96,8 @@ (defvar spray--base-overlay nil) (defvar spray--accent-overlay nil) (defvar spray--running nil) +(defvar spray--first-words 0) +(defvar spray--initial-delay 0) (defvar spray--delay 0) (defvar spray--saved-cursor-type nil) (defvar spray--saved-buffer-face nil) @@ -187,8 +194,11 @@ (make-string (- 5 (- accent beg)) ?\s))) (narrow-to-region beg end))) + (defun spray--update () - (cond ((not (zerop spray--delay)) + (cond ((not (zerop spray--initial-delay)) + (setq spray--initial-delay (1- spray--initial-delay))) + ((not (zerop spray--delay)) (setq spray--delay (1- spray--delay)) (when (= spray--delay 2) (narrow-to-region (point) (point)))) @@ -196,6 +206,9 @@ (widen) (if (eobp) (spray-mode -1) + (when (not (zerop spray--first-words)) + (setq spray--initial-delay spray--first-words) + (setq spray--first-words (1- spray--first-words))) (skip-chars-forward "\s\t\n—") (spray--word-at-point))))) @@ -218,6 +231,7 @@ Returns t if spray was unpaused." (defun spray-start () "Start / resume spray." (interactive) + (setq spray--first-words spray-ramp) (setq spray--running (run-with-timer 0 (/ 60.0 spray-wpm) 'spray--update))) -- 2.30.2