X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=spray.el;h=e54de5487354d45eb405c0f57ebfdb2303f9d3f4;hb=refs%2Fheads%2Fmaster;hp=a15274f0adb71f2688c785b5967656196ef58521;hpb=eafbada8dae4337ff9b3fe8e3ea21b4abf0f207f;p=spray diff --git a/spray.el b/spray.el index a15274f..e54de54 100644 --- a/spray.el +++ b/spray.el @@ -21,6 +21,7 @@ ;; 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: @@ -98,6 +99,12 @@ :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 @@ -154,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) @@ -177,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 @@ -197,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) @@ -221,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)))) @@ -236,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 @@ -263,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))) @@ -340,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)