X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=spray.el;h=e54de5487354d45eb405c0f57ebfdb2303f9d3f4;hb=5f807d1cf0b25dc2169bdba49c1f58efd6e5109d;hp=95951ca2d05ab9c4b8dca6e624e0c4143c1643ab;hpb=6715a1934b2e3df9509efab150eb5b5eb5101a42;p=spray diff --git a/spray.el b/spray.el index 95951ca..e54de54 100644 --- a/spray.el +++ b/spray.el @@ -1,47 +1,89 @@ ;;; spray.el --- a speed reading mode -;; Copyright (C) 2014 zk_phi +;; Copyright (C) 2014 Ian Kelling ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 2 of the License, or +;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. -;; + ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. -;; + ;; You should have received a copy of the GNU General Public License -;; along with this program; if not, write to the Free Software -;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +;; along with this program. If not, see . -;; Author: zk_phi -;; URL: http://hins11.yu-yake.com/ +;; Maintainer: Ian Kelling ;; Author: Ian Kelling +;; Author: zk_phi +;; Created: 18 Jun 2014 ;; Version: 0.0.2 +;; URL: https://github.com/ian-kelling/spray +;; Mailing list: https://lists.iankelling.org/listinfo/spray +;; Keywords: convenience ;;; Commentary: -;; Put this script into a "load-path"ed directory, and load it in your -;; init file. -;; +;; For speed reading, or just more enjoyable reading. Narrows the buffer to show +;; one word at a time. Adjust speed / pause as needed. +;; +;; Download from Melpa or put this script into a "load-path"ed directory, and +;; load it in your init file: + ;; (require 'spray) -;; + ;; Then you may run spray with "M-x spray-mode". Binding some keys may ;; also be useful. -;; + ;; (global-set-key (kbd "") 'spray-mode) -;; -;; For more informations, see Readme.org. -;; Known bugs. +;; In spray-mode buffers, following commands are available. + +;; - =spray-start/stop= (SPC) :: +;; pause or resume spraying + +;; - =spray-backward-word= (h, ) :: +;; pause and back to the last word + +;; - =spray-forward-word= (l, ) :: +;; inverse of =spray-backward-word= + +;; - =spray-faster= (f) :: +;; increases speed + +;; - =spray-slower= (s) :: +;; decreases speed + +;; - =spray-quit= (q, ) :: +;; quit =spray-mode= + +;; You may customize spray by modifying following items: + +;; - [Variable] spray-wpm +;; - [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 + +;; Readme.org from the package repository has some additional information: +;; A gif screencast. +;; Algorithm specification. +;; Comparison with similar projects. + +;;; 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 ;; 0.0.2 margin options, speed control, better quit @@ -52,23 +94,63 @@ ;; * customizable vars -(defvar spray-wpm 400 - "words/min") +(defcustom spray-wpm 400 + "Words per minute" + :group 'spray + :type 'integer) + +(defcustom spray-save-point nil + "Set to true and then exiting spray mode will restore the point" + :group 'spray + :type 'boolean) + + +(defcustom spray-height 400 + "Height of characters" + :group 'spray + :type 'integer) + +(defcustom spray-margin-top 1 + "Character margin at top of buffer. Characters are as big as + spray text characters." + :group 'spray + :type 'integer) + +(defcustom spray-margin-left 1 + "Character margin at left of buffer. Characters are as big as + spray text characters." + :group 'spray + :type 'integer) + +(defcustom spray-ramp 2 + "Initial words before ramping up to full speed. Pauses for +this multiple of wpm on the first word, +decreasing by one for each subsequent word." + :group 'spray + :type 'integer) + +(defcustom spray-unsupported-minor-modes + '(buffer-face-mode smartparens-mode highlight-symbol-mode + column-number-mode) + "Minor modes to toggle off when in spray mode." + :group 'spray + :type '(list symbol)) + + +;; * faces -(defvar spray-height 400 - "height of characters") +(defface spray-base-face + '((t (:inherit default))) + "Face for non-accent characters." + :group 'spray) -(defvar spray-margin-top 1 - "character margin at top of buffer. Characters are as big as - spray text characters.") +(defface spray-accent-face + '((t (:foreground "red" :inherit spray-base-face))) + "Face for accent character." + :group 'spray) -(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.") +;; keymap (defvar spray-mode-map (let ((km (make-sparse-keymap))) @@ -79,6 +161,7 @@ decreasing by one for each subsequent word.") (define-key km (kbd "") 'spray-forward-word) (define-key km (kbd "f") 'spray-faster) (define-key km (kbd "s") 'spray-slower) + (define-key km (kbd "t") 'spray-time) (define-key km (kbd "q") 'spray-quit) (define-key km (kbd "") 'spray-quit) (define-key km [remap forward-char] 'spray-forward-word) @@ -89,19 +172,6 @@ decreasing by one for each subsequent word.") km) "keymap for spray-mode buffers") -(defvar spray-unsupported-minor-modes - '(buffer-face-mode smartparens-mode highlight-symbol-mode)) - -;; * faces - -(make-face 'spray-base-face) -(set-face-attribute 'spray-base-face nil - :inherit 'default) - -(make-face 'spray-accent-face) -(set-face-attribute 'spray-accent-face nil - :inherit 'spray-base-face - :foreground "red") ;; * internal vars @@ -115,6 +185,7 @@ decreasing by one for each subsequent word.") (defvar spray--saved-cursor-type nil) (defvar spray--saved-restriction nil) (defvar spray--saved-minor-modes nil) +(defvar spray--saved-point nil) ;; * utility functions @@ -135,6 +206,7 @@ decreasing by one for each subsequent word.") (setq spray--base-overlay (make-overlay (point-min) (point-max)) spray--accent-overlay (make-overlay 0 0) spray--saved-cursor-type cursor-type + spray--saved-point (point) spray--saved-restriction (and (buffer-narrowed-p) (cons (point-min) (point-max)))) (dolist (mode spray-unsupported-minor-modes) @@ -159,6 +231,8 @@ decreasing by one for each subsequent word.") (cdr spray--saved-restriction)) (widen)) (setq cursor-type spray--saved-cursor-type) + (when (and spray-save-point spray--saved-point) + (goto-char spray--saved-point)) (dolist (mode spray--saved-minor-modes) (funcall mode 1)) (setq spray--saved-minor-modes nil)))) @@ -174,11 +248,11 @@ decreasing by one for each subsequent word.") (len (+ (skip-chars-forward "^\s\t\n—") (skip-chars-forward "—"))) (end (point)) (accent (+ beg (cl-case len - ((1) 1) - ((2 3 4 5) 2) - ((6 7 8 9) 3) - ((10 11 12 13) 4) - (t 5))))) + ((1) 1) + ((2 3 4 5) 2) + ((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 @@ -201,13 +275,11 @@ decreasing by one for each subsequent word.") (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)))) + (setq spray--delay (1- spray--delay))) (t (widen) (if (eobp) - (spray-mode -1) + (spray-quit) (when (not (zerop spray--first-words)) (setq spray--initial-delay spray--first-words) (setq spray--first-words (1- spray--first-words))) @@ -278,6 +350,16 @@ Decreases the wpm (words per minute) parameter. See the variable (when was-running (spray-start)))) +(defun spray-time () + (interactive) + (widen) + (let ((position (progn (skip-chars-backward "^\s\t\n—") (point)))) + (message + "%d per cent done; ~%d minute(s) remaining" + (* 100 (/ position (+ 0.0 (point-max)))) + (fround (/ (count-words-region position (point-max)) (+ 0.0 spray-wpm))))) + (spray--word-at-point)) + ;; * provide (provide 'spray)