X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=spray.el;h=977fc6f9abbd8c476d65ce3d91c5d20497f91683;hb=953a89d762763da1c7d408aaa20f2b73b7c512c0;hp=afefae2541f06ae66cc38f2af4e5da1e9967c3f9;hpb=280e554878f25318f94e032f8acde6281905aa2e;p=spray diff --git a/spray.el b/spray.el index afefae2..977fc6f 100644 --- a/spray.el +++ b/spray.el @@ -35,6 +35,12 @@ ;; ;; For more informations, see Readme.org. +;; 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 ;; 0.0.1 add spray-set-margins @@ -49,7 +55,10 @@ (defvar spray-wpm 400 "words/min") (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 0 "character margin at left 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))) @@ -87,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) @@ -118,10 +129,13 @@ buffer-face-mode buffer-face-mode-face) spray--saved-smartparens-enabled (and (boundp 'smartparens-mode) - smartparens-mode)) + smartparens-mode) + spray--saved-highlight-symbol-enabled (and (boundp 'highlight-symbol-mode) + highlight-symbol-mode)) ;; smartparens wrapping of all letter binds can cause problems. ;; for example, it can cause auto-complete to activate (and spray--saved-smartparens-enabled (smartparens-mode -1)) + (and spray--saved-highlight-symbol-enabled (highlight-symbol-mode -1)) (setq cursor-type nil) (let ((buffer-face-mode-face `(:height ,spray-height))) (buffer-face-mode 1)) @@ -132,6 +146,7 @@ (spray-start)) (t (and spray--saved-smartparens-enabled (smartparens-mode 1)) + (and spray--saved-highlight-symbol-enabled (highlight-symbol-mode 1)) (setq cursor-type spray--saved-cursor-type) (if spray--saved-restriction (narrow-to-region (car spray--saved-restriction) @@ -151,9 +166,9 @@ (spray-mode -1)) (defun spray--word-at-point () - (skip-chars-backward "^\s\t\n") + (skip-chars-backward "^\s\t\n—") (let* ((beg (point)) - (len (skip-chars-forward "^\s\t\n")) + (len (+ (skip-chars-forward "^\s\t\n—") (skip-chars-forward "—"))) (end (point)) (accent (+ beg (cl-case len ((1) 1) @@ -161,11 +176,15 @@ ((6 7 8 9) 3) ((10 11 12 13) 4) (t 5))))) + ;; this fairly obfuscated, using magic numbers to store state + ;; it would be nice to sometime patch this so it is more readable. + ;; for greater than 9 length, we display for twice as long + ;; for some punctuation, we display a blank (setq spray--delay (+ (if (> len 9) 1 0) (if (looking-at "\n[\s\t\n]") 3 0) (cl-case (char-before) ((?. ?! ?\? ?\;) 3) - ((?, ?:) 1) + ((?, ?: ?—) 1) (t 0)))) (move-overlay spray--accent-overlay (1- accent) accent) (move-overlay spray--base-overlay beg end) @@ -175,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)))) @@ -184,7 +206,10 @@ (widen) (if (eobp) (spray-mode -1) - (skip-chars-forward "\s\t\n") + (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))))) ;; * interactive commands @@ -206,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))) @@ -214,15 +240,15 @@ Returns t if spray was unpaused." (interactive) (spray-stop) (widen) - (skip-chars-forward "\s\t\n") + (skip-chars-forward "\s\t\n—") (spray--word-at-point)) (defun spray-backward-word () (interactive) (spray-stop) (widen) - (skip-chars-backward "^\s\t\n") - (skip-chars-backward "\s\t\n") + (skip-chars-backward "^\s\t\n—") + (skip-chars-backward "\s\t\n—") (spray--word-at-point)) (defun spray-faster ()