From 7d12eb735a08d4b389a9f0c4a59061e93b3bca6e Mon Sep 17 00:00:00 2001 From: zk_phi Date: Fri, 13 Jun 2014 00:39:58 +0900 Subject: [PATCH] first commit --- Readme.org | 16 ++++++++++ spray.el | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 Readme.org create mode 100644 spray.el diff --git a/Readme.org b/Readme.org new file mode 100644 index 0000000..abdeff1 --- /dev/null +++ b/Readme.org @@ -0,0 +1,16 @@ +* spray.el + +A speed reading mode for Emacs (an elisp implementation of +[[https://github.com/Miserlou/OpenSpritz][OpenSpritz]]). + +** Installation + +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) diff --git a/spray.el b/spray.el new file mode 100644 index 0000000..a34b58f --- /dev/null +++ b/spray.el @@ -0,0 +1,86 @@ +;; custom +(defvar spray-freq (/ 60.0 300) "60.0 / WPM") +(defvar spray-text-scale 5) +(defvar spray-orp-face 'error) + +;; internal variables for spraying +(defvar spray--padding-overlay nil) +(defvar spray--orp-overlay nil) +(defvar spray--timer nil) +(defvar spray--delay 0) + +;; incompatible minor-modes +(defvar spray--saved-global-hl-line-mode nil) +(defvar spray--saved-font-lock-mode nil) +(defvar spray--saved-hl-line-mode nil) +(defvar spray--saved-cursor-type nil) + +(define-minor-mode spray-mode + "spray mode" + :init nil + :global nil + (cond (spray-mode + (setq spray--orp-overlay (make-overlay 0 0) + spray--padding-overlay (make-overlay 0 0) + spray--timer (run-with-timer 0 spray-freq 'spray-next) + spray--saved-cursor-type cursor-type) + (setq cursor-type nil) + (text-scale-set spray-text-scale) + (overlay-put spray--orp-overlay 'face spray-orp-face) + (add-hook 'pre-command-hook 'turn-off-spray-mode) + ;; disable incompatible minor-modes + (when (boundp 'global-hl-line-mode) + (setq spray--saved-global-hl-line-mode global-hl-line-mode) + (set (make-local-variable 'global-hl-line-mode) nil)) + (when (boundp 'font-lock-mode) + (setq spray--saved-font-lock-mode font-lock-mode) + (font-lock-mode -1)) + (when (boundp 'hl-line-mode) + (setq spray--saved-hl-line-mode hl-line-mode) + (hl-line-mode -1))) + (t + (widen) + (setq cursor-type spray--saved-cursor-type) + (text-scale-set 0) + (delete-overlay spray--orp-overlay) + (delete-overlay spray--padding-overlay) + (cancel-timer spray--timer) + (remove-hook 'pre-command-hook 'turn-off-spray-mode) + ;; restore incompatible minor-modes + (when spray--saved-global-hl-line-mode + (setq global-hl-line-mode spray--saved-global-hl-line-mode)) + (when spray--saved-font-lock-mode + (font-lock-mode 1)) + (when spray--saved-hl-line-mode + (hl-line-mode 1))))) + +(defun turn-on-spray-mode () (interactive) (spray-mode 1)) +(defun turn-off-spray-mode () (interactive) (spray-mode -1)) + +(defun spray-next () + (if (not (zerop spray--delay)) + (setq spray--delay (1- spray--delay)) + (widen) + (if (eobp) + (turn-off-spray-mode) + (skip-chars-forward "\s\t\n") + (let* ((beg (point)) + (len (skip-chars-forward "^\s\t\n")) + (end (point)) + (orp (+ beg (cl-case len + ((1) 1) + ((2 3 4 5) 2) + ((6 7 8 9) 3) + ((10 11 12 13) 4) + (t 5))))) + (setq spray--delay (+ (if (> len 8) 1 0) (cl-case (char-before) + ((?. ?! ?\? ?\;) 3) + ((?, ?:) 1) + (t 0)))) + (overlay-put spray--padding-overlay + 'before-string (make-string (- 5 (- orp beg)) ?\s)) + (move-overlay spray--padding-overlay beg (1+ beg)) + (move-overlay spray--orp-overlay (1- orp) orp) + (narrow-to-region beg end))))) + +(provide 'spray) -- 2.30.2