]> gitweb.factorcode.org Git - factor.git/blobdiff - misc/fuel/fuel-stack.el
FUEL: refactoring to eliminate the eval-result variable
[factor.git] / misc / fuel / fuel-stack.el
index 3a19a59026c36ed8fa3a38459e37f672882ff021..bccda8302451429fbc8d72ad58ae0663f3d10465 100644 (file)
 ;;; Code:
 
 (require 'fuel-autodoc)
-(require 'fuel-syntax)
 (require 'fuel-eval)
 (require 'fuel-base)
+(require 'factor-mode)
 
 \f
 ;;; Customization
 
+;;;###autoload
 (defgroup fuel-stack nil
-  "Customization for FUEL's stack inference engine"
+  "Customization for FUEL's stack inference engine."
   :group 'fuel)
 
-(defface fuel-font-lock-stack-region (face-user-default-spec 'highlight)
-  "Face used to highlight the region whose stack effect is shown"
+(defface fuel-stack-region-face '((t (:inherit highlight)))
+  "Highlights the region being stack inferenced."
   :group 'fuel-stack
-  :group 'faces)
+  :group 'fuel-faces
+  :group 'fuel)
 
-(defcustom fuel-stack-highlight-period 2
+(defcustom fuel-stack-highlight-period 1.0
   "Time, in seconds, the region is highlighted when showing its
 stack effect.
 
@@ -50,7 +52,7 @@ Set it to 0 to disable highlighting."
 (defun fuel-stack--infer-effect (str)
   (let ((cmd `(:fuel*
                ((:using stack-checker effects)
-                ([ (:factor ,str) ] infer effect>string :get)))))
+                ([ (:factor ,str) ] infer effect>string)))))
     (fuel-eval--retort-result (fuel-eval--send/wait cmd 500))))
 
 (defsubst fuel-stack--infer-effect/prop (str)
@@ -61,7 +63,7 @@ Set it to 0 to disable highlighting."
 
 (defvar fuel-stack--overlay
   (let ((overlay (make-overlay 0 0)))
-    (overlay-put overlay 'face 'fuel-font-lock-stack-region)
+    (overlay-put overlay 'face 'fuel-stack-region-face)
     (delete-overlay overlay)
     overlay))
 
@@ -71,11 +73,11 @@ Set it to 0 to disable highlighting."
   (when (> fuel-stack-highlight-period 0)
     (move-overlay fuel-stack--overlay begin end))
   (condition-case nil
-      (let* ((str (fuel--region-to-string begin end))
+      (let* ((str (fuel-region-to-string begin end))
              (effect (fuel-stack--infer-effect/prop str)))
         (if effect (message "%s" effect)
           (message "Couldn't infer effect for '%s'"
-                   (fuel--shorten-region begin end 60)))
+                   (fuel-shorten-region begin end 60)))
         (sit-for fuel-stack-highlight-period))
     (error))
   (delete-overlay fuel-stack--overlay))
@@ -86,26 +88,34 @@ With prefix argument, use current region instead"
   (interactive "P")
   (if arg
       (call-interactively 'fuel-stack-effect-region)
-    (fuel-stack-effect-region (1+ (fuel-syntax--beginning-of-sexp-pos))
-                              (if (looking-at-p ";") (point)
-                                (fuel-syntax--end-of-symbol-pos)))))
+    (fuel-stack-effect-region (1+ (factor-beginning-of-sexp-pos))
+                              (if (looking-at-p ";")
+                                  (point)
+                                (save-excursion
+                                  (factor-end-of-symbol) (point))))))
 
 \f
 ;;; Stack mode:
 
-(make-variable-buffer-local
- (defvar fuel-stack-mode-string " S"
-   "Modeline indicator for fuel-stack-mode"))
+(defvar-local fuel-stack-mode-string " S"
+  "Modeline indicator for fuel-stack-mode")
+
+(defvar-local fuel-stack--region-function
+  '(lambda ()
+     (fuel-region-to-string (1+ (factor-beginning-of-sexp-pos)))))
 
 (defun fuel-stack--eldoc ()
   (when (looking-at-p " \\|$")
-    (let* ((r (fuel--region-to-string (1+ (fuel-syntax--beginning-of-sexp-pos))))
-           (e (fuel-stack--infer-effect/prop r)))
+    (let* ((r (funcall fuel-stack--region-function))
+           (e (and r
+                   (not (string-match "^ *$" r))
+                   (fuel-stack--infer-effect/prop r))))
       (when e
         (if fuel-stack-mode-show-sexp-p
-            (concat (fuel--shorten-str r 30) ": " e)
+            (concat (fuel-shorten-str r 30) " -> " e)
           e)))))
 
+;;;###autoload
 (define-minor-mode fuel-stack-mode
   "Toggle Fuel's Stack mode.
 With no argument, this command toggles the mode.
@@ -120,10 +130,10 @@ sexp are automatically displayed in the echo area."
 
   (setq fuel-autodoc--fallback-function
         (when fuel-stack-mode 'fuel-stack--eldoc))
-  (set (make-local-variable 'eldoc-minor-mode-string) nil)
+  (setq-local eldoc-minor-mode-string nil)
   (unless fuel-autodoc-mode
-    (set (make-local-variable 'eldoc-documentation-function)
-         (when fuel-stack-mode 'fuel-stack--eldoc))
+    (setq-local eldoc-documentation-function
+                (when fuel-stack-mode 'fuel-stack--eldoc))
     (eldoc-mode fuel-stack-mode)
     (message "Fuel Stack Autodoc %s" (if fuel-stack-mode "enabled" "disabled"))))