update doc, no idea what orp means so rename it
[spray] / spray.el
index 7e38b4eee3dbd13a0cad1a37dc6760cf1e7ddf5b..8e3b9225cf37568d1037e02b3391f4a325daba09 100644 (file)
--- a/spray.el
+++ b/spray.el
@@ -47,6 +47,8 @@
 
 (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-mode-map
   (let ((km (make-sparse-keymap)))
@@ -69,8 +71,8 @@
                     :foreground (face-foreground 'default)
                     :slant 'normal)
 
-(make-face 'spray-orp-face)
-(set-face-attribute 'spray-orp-face nil
+(make-face 'spray-accent-face)
+(set-face-attribute 'spray-accent-face nil
                     :foreground "red"
                     :overline (face-foreground 'default)
                     :underline (face-foreground 'default)
 
 ;; * 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."
+(defun spray-set-margins ()
+  "Setup spray--margin-string"
   (setq spray--margin-string
-        (propertize " " 'display `((space-width ,left) (height ,(+ 1 above))))))
+        (concat (make-string spray-margin-top 10) ;; 10 = ascii newline
+                (make-string spray-margin-left 32)))) ;; 32 = ascii space
 
 ;; * the mode
 
@@ -119,8 +120,7 @@ an integer or a float value."
          (overlay-put spray--base-overlay 'priority 100)
          (overlay-put spray--base-overlay 'face 'spray-base-face)
          (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)
+         (overlay-put spray--orp-overlay 'face 'spray-accent-face)
          (spray-start))
         (t
          (setq cursor-type spray--saved-cursor-type)
@@ -134,7 +134,6 @@ an integer or a float value."
                (buffer-face-mode 1)))
          (delete-overlay spray--base-overlay)
          (delete-overlay spray--orp-overlay)
-         (remove-hook 'pre-command-hook 'spray--pre-command-handler)
          (spray-stop))))
 
 (defun spray-quit ()
@@ -142,10 +141,6 @@ an integer or a float value."
   (interactive)
   (spray-mode -1))
 
-(defun spray--pre-command-handler ()
-  (unless (string-match "^spray-" (symbol-name this-command))
-    (spray-mode -1)))
-
 (defun spray--word-at-point ()
   (skip-chars-backward "^\s\t\n")
   (let* ((beg (point))
@@ -165,6 +160,7 @@ an integer or a float value."
                             (t 0))))
     (move-overlay spray--orp-overlay (1- orp) orp)
     (move-overlay spray--base-overlay beg end)
+    (spray-set-margins)
     (overlay-put spray--base-overlay 'before-string
                  (concat spray--margin-string
                          (make-string (- 5 (- orp beg)) ?\s)))