X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=spray.el;h=7e38b4eee3dbd13a0cad1a37dc6760cf1e7ddf5b;hb=dce5a35abd9e640d6d6123ac2b2bfd42c86ee7f8;hp=361e0490cb0d0af45f85e9cdf4088d175b564d0f;hpb=19017e3d79de794de7654d66033fa8cf5b276599;p=spray diff --git a/spray.el b/spray.el index 361e049..7e38b4e 100644 --- a/spray.el +++ b/spray.el @@ -18,7 +18,8 @@ ;; Author: zk_phi ;; URL: http://hins11.yu-yake.com/ -;; Version: 0.0.0 +;; Author: Ian Kelling +;; Version: 0.0.1 ;;; Commentary: @@ -36,6 +37,7 @@ ;;; Change Log: ;; 0.0.0 test release +;; 0.0.1 add spray-set-margins ;;; Code: @@ -53,6 +55,9 @@ (define-key km (kbd "l") 'spray-forward-word) (define-key km (kbd "") 'spray-backward-word) (define-key km (kbd "") 'spray-forward-word) + (define-key km (kbd "f") 'spray-faster) + (define-key km (kbd "q") 'spray-quit) + (define-key km (kbd "") 'spray-quit) km) "keymap for spray-mode buffers") @@ -61,16 +66,20 @@ (make-face 'spray-base-face) (set-face-attribute 'spray-base-face nil :background (face-background 'default) - :foreground (face-foreground 'default)) + :foreground (face-foreground 'default) + :slant 'normal) (make-face 'spray-orp-face) (set-face-attribute 'spray-orp-face nil :foreground "red" :overline (face-foreground 'default) - :underline (face-foreground 'default)) + :underline (face-foreground 'default) + :slant 'normal) ;; * internal vars +(defvar spray--margin-string "" + "Currently not used.") (defvar spray--base-overlay nil) (defvar spray--orp-overlay nil) (defvar spray--running nil) @@ -79,6 +88,15 @@ (defvar spray--saved-buffer-face nil) (defvar spray--saved-restriction nil) +;; * utility functions + +(defun spray-set-margins (left above) + "Currently broken & not used: +add margins before/above the spray text. each arguments can be +an integer or a float value." + (setq spray--margin-string + (propertize " " 'display `((space-width ,left) (height ,(+ 1 above)))))) + ;; * the mode ;;;###autoload @@ -103,7 +121,7 @@ (overlay-put spray--orp-overlay 'priority 101) (overlay-put spray--orp-overlay 'face 'spray-orp-face) (add-hook 'pre-command-hook 'spray--pre-command-handler) - (spray-start/stop 1)) + (spray-start)) (t (setq cursor-type spray--saved-cursor-type) (if spray--saved-restriction @@ -117,11 +135,15 @@ (delete-overlay spray--base-overlay) (delete-overlay spray--orp-overlay) (remove-hook 'pre-command-hook 'spray--pre-command-handler) - (spray-start/stop -1)))) + (spray-stop)))) + +(defun spray-quit () + "Exit spray mode." + (interactive) + (spray-mode -1)) (defun spray--pre-command-handler () - (unless (memq this-command - '(spray-forward-word spray-backward-word spray-start/stop)) + (unless (string-match "^spray-" (symbol-name this-command)) (spray-mode -1))) (defun spray--word-at-point () @@ -143,8 +165,9 @@ (t 0)))) (move-overlay spray--orp-overlay (1- orp) orp) (move-overlay spray--base-overlay beg end) - (overlay-put spray--base-overlay - 'before-string (make-string (- 5 (- orp beg)) ?\s)) + (overlay-put spray--base-overlay 'before-string + (concat spray--margin-string + (make-string (- 5 (- orp beg)) ?\s))) (narrow-to-region beg end))) (defun spray--update () @@ -161,33 +184,68 @@ ;; * interactive commands -(defun spray-start/stop (&optional switch) +(defun spray-start/stop () + "Toggle pause/unpause spray." (interactive) - (cond ((and (memql switch '(nil 1)) - (not spray--running)) - (setq spray--running - (run-with-timer 0 (/ 60.0 spray-wpm) 'spray--update))) - ((memql switch '(nil -1)) - (cancel-timer spray--running) - (setq spray--running nil)) - (t - nil))) + (or (spray-stop) (spray-start))) + +(defun spray-stop () + "Pause spray. +Returns t if spray was unpaused." + (interactive) + (prog1 spray--running + (when spray--running + (cancel-timer spray--running) + (setq spray--running nil)))) + +(defun spray-start () + "Start / resume spray." + (interactive) + (setq spray--running + (run-with-timer 0 (/ 60.0 spray-wpm) 'spray--update))) + (defun spray-forward-word () (interactive) - (when spray--running (spray-start/stop -1)) + (spray-stop) (widen) (skip-chars-forward "\s\t\n") (spray--word-at-point)) (defun spray-backward-word () (interactive) - (when spray--running (spray-start/stop -1)) + (spray-stop) (widen) (skip-chars-backward "^\s\t\n") (skip-chars-backward "\s\t\n") (spray--word-at-point)) +(defun spray-faster () + "Increases speed. + +Increases the wpm (words per minute) parameter. See the variable +`spray-wmp'." + (interactive) + (spray-inc-wpm 20)) + +(defun spray-slower () + "Decreases speed. + +Decreases the wpm (words per minute) parameter. See the variable +`spray-wmp'." + (interactive) + (spray-inc-wpm -20)) + +(defun spray-inc-wpm (delta) + (let ((was-running spray--running)) + (spray-stop) + (when (< 10 (+ spray-wpm delta)) + (setq spray-wpm (+ spray-wpm delta))) + (and was-running (spray-backward-word)) + (message "spray wpm: %d" spray-wpm) + (when was-running + (spray-start)))) + ;; * provide (provide 'spray)