]> gitweb.factorcode.org Git - factor.git/commitdiff
FUEL: Word completion in listener, bound to TAB by default.
authorJose A. Ortega Ruiz <jao@gnu.org>
Tue, 16 Dec 2008 01:09:18 +0000 (02:09 +0100)
committerJose A. Ortega Ruiz <jao@gnu.org>
Tue, 16 Dec 2008 01:09:18 +0000 (02:09 +0100)
extra/fuel/fuel.factor
misc/fuel/README
misc/fuel/fuel-completion.el
misc/fuel/fuel-listener.el
misc/fuel/fuel-syntax.el

index 5a39fe9f2b6b1f7f443160813a2686180ce2a97e..bf36969219123597e8cd936cd652fb14dc713929 100644 (file)
@@ -163,32 +163,35 @@ M: source-file fuel-pprint path>> fuel-pprint ;
 : fuel-get-edit-location ( defspec -- )
     where [
        first2 [ (normalize-path) ] dip 2array fuel-eval-set-result
-    ] when* ;
+    ] when* ; inline
 
 : fuel-get-vocab-location ( vocab -- )
-    >vocab-link fuel-get-edit-location ;
+    >vocab-link fuel-get-edit-location ; inline
 
 : (fuel-get-vocabs) ( -- seq )
     all-vocabs-seq [ vocab-name ] map ; inline
 
 : fuel-get-vocabs ( -- )
-    (fuel-get-vocabs) fuel-eval-set-result ;
+    (fuel-get-vocabs) fuel-eval-set-result ; inline
 
 MEMO: (fuel-vocab-words) ( name -- seq )
     >vocab-link words [ name>> ] map ;
 
-: fuel-vocabs-words ( names/f -- seq )
-    [ (fuel-get-vocabs) ] unless* prune
-    [ (fuel-vocab-words) ] map concat natural-sort ;
+: fuel-current-words ( -- seq )
+    use get [ keys ] map concat ; inline
+
+: fuel-vocabs-words ( names -- seq )
+    prune [ (fuel-vocab-words) ] map concat ; inline
 
 : (fuel-get-words) ( prefix names/f -- seq )
-    fuel-vocabs-words swap [ drop-prefix nip length 0 = ] curry filter ;
+    [ fuel-vocabs-words ] [ fuel-current-words ] if* natural-sort
+    swap [ drop-prefix nip length 0 = ] curry filter ;
 
 : fuel-get-words ( prefix names -- )
     (fuel-get-words) fuel-eval-set-result ; inline
 
 : fuel-run-file ( path -- ) run-file ; inline
 
-: fuel-startup ( -- ) "listener" run ; inline
+: fuel-startup ( -- ) "listener" run-file ; inline
 
 MAIN: fuel-startup
index 3754e816a94cd638983790bdff643b40f728e86b..2bf58cbdc7901b13b4da88a70a3dedf324aa1d24 100644 (file)
@@ -55,19 +55,27 @@ the same as C-cz)).
  - C-cz : switch to listener
  - C-co : cycle between code, tests and docs factor files
 
- - M-. : edit word at point in Emacs (also in listener)
+ - M-. : edit word at point in Emacs
  - M-TAB : complete word at point
  - C-cC-ev : edit vocabulary
 
  - C-cr, C-cC-er : eval region
  - C-M-r, C-cC-ee : eval region, extending it to definition boundaries
  - C-M-x, C-cC-ex : eval definition around point
- - C-ck, C-cC-ek : compile file
+ - C-ck, C-cC-ek : run file
 
  - C-cC-da : toggle autodoc mode
  - C-cC-dd : help for word at point
  - C-cC-ds : short help word at point
 
+* In the listener:
+
+ - TAB : complete word at point
+ - M-. : edit word at point in Emacs
+ - C-cv : edit vocabulary
+ - C-ch : help for word at point
+ - C-ck : run file
+
 * In the debugger (it pops up upon eval/compilation errors):
 
  - g : go to error
index bffa2aa0fc2c56b95ad5dc3b77d5fc9536d08299..66657cbfcfb33cad963b44a16c0983bba2540f1e 100644 (file)
              (fuel-eval--send/wait '(:fuel* (fuel-get-vocabs) "fuel" (:array)))))))
   fuel-completion--vocabs)
 
-(defsubst fuel-completion--words (prefix vocabs)
-  (fuel-eval--retort-result
-   (fuel-eval--send/wait `(:fuel* (,prefix V{ ,@vocabs } fuel-get-words) t ,vocabs))))
+(defun fuel-completion--words (prefix vocabs)
+  (let ((vs (if vocabs (cons :array vocabs) 'f))
+        (us (or vocabs 't)))
+    (fuel-eval--retort-result
+     (fuel-eval--send/wait `(:fuel* (,prefix ,vs fuel-get-words) t ,us)))))
 
 \f
 ;;; Completions window handling, heavily inspired in slime's:
@@ -135,10 +137,11 @@ terminates a current completion."
 \f
 ;;; Completion functionality:
 
-(defsubst fuel-completion--word-list (prefix)
-  (let ((fuel-log--inhibit-p t))
-    (fuel-completion--words
-     prefix `("syntax" ,(fuel-syntax--current-vocab) ,@(fuel-syntax--usings)))))
+(defun fuel-completion--word-list (prefix)
+  (let* ((fuel-log--inhibit-p t)
+         (cv (fuel-syntax--current-vocab))
+         (vs (and cv `("syntax" ,cv ,@(fuel-syntax--usings)))))
+    (fuel-completion--words prefix vs)))
 
 (defun fuel-completion--complete (prefix)
   (let* ((words (fuel-completion--word-list prefix))
index 7c71cbf03c2e21841d81c64dde7cd9db25410840..d2f8cff9db054e6152bd7b8b961f93ccf8df919b 100644 (file)
@@ -15,6 +15,8 @@
 
 (require 'fuel-eval)
 (require 'fuel-base)
+(require 'fuel-completion)
+(require 'fuel-syntax)
 (require 'comint)
 
 \f
@@ -68,10 +70,10 @@ buffer."
       (error "Could not run factor: image file %s not readable" image))
     (message "Starting FUEL listener ...")
     (comint-exec (fuel-listener--buffer) "factor"
-                 factor nil `("-run=fuel" ,(format "-i=%s" image)))
+                 factor nil `("-run=listener" ,(format "-i=%s" image)))
     (pop-to-buffer (fuel-listener--buffer))
     (goto-char (point-max))
-    (comint-send-string nil "USE: fuel \"\\nFUEL loaded\\n\" write\n")
+    (comint-send-string nil "USE: fuel \"FUEL loaded\\n\" write\n")
     (fuel-listener--wait-for-prompt 30)
     (message "FUEL listener up and running!")))
 
@@ -101,6 +103,17 @@ buffer."
       (goto-char (point-max))
       (unless seen (error "No prompt found!")))))
 
+\f
+;;; Completion support
+
+(defsubst fuel-listener--current-vocab () nil)
+(defsubst fuel-listener--usings () nil)
+
+(defun fuel-listener--setup-completion ()
+  (setq fuel-syntax--current-vocab-function 'fuel-listener--current-vocab)
+  (setq fuel-syntax--usings-function 'fuel-listener--usings)
+  (set-syntax-table fuel-syntax--syntax-table))
+
 \f
 ;;; Interface: starting fuel listener
 
@@ -126,13 +139,16 @@ buffer."
 \\{fuel-listener-mode-map}"
   (set (make-local-variable 'comint-prompt-regexp) fuel-listener--prompt-regex)
   (set (make-local-variable 'comint-prompt-read-only) t)
-  (setq fuel-listener--compilation-begin nil))
+  (fuel-listener--setup-completion))
 
 (define-key fuel-listener-mode-map "\C-cz" 'run-factor)
 (define-key fuel-listener-mode-map "\C-c\C-z" 'run-factor)
 (define-key fuel-listener-mode-map "\C-ch" 'fuel-help)
 (define-key fuel-listener-mode-map "\M-." 'fuel-edit-word-at-point)
+(define-key fuel-listener-mode-map "\C-cv" 'fuel-edit-vocabulary)
+(define-key fuel-listener-mode-map "\C-c\C-v" 'fuel-edit-vocabulary)
 (define-key fuel-listener-mode-map "\C-ck" 'fuel-run-file)
+(define-key fuel-listener-mode-map (kbd "TAB") 'fuel-completion--complete-symbol)
 
 \f
 (provide 'fuel-listener)
index a492a7b647f919ceec9ddbd96effd20744a97f94..936bded3a5299e874280a055ee3badfb85405f59 100644 (file)
 \f
 ;;; USING/IN:
 
-(defun fuel-syntax--current-vocab ()
+(make-variable-buffer-local
+ (defvar fuel-syntax--current-vocab-function 'fuel-syntax--find-in))
+
+(defsubst fuel-syntax--current-vocab ()
+  (funcall fuel-syntax--current-vocab-function))
+
+(defun fuel-syntax--find-in ()
   (let* ((vocab)
          (ip
           (save-excursion
               (setq vocab (format "%s.%s" vocab (downcase sub))))))))
     vocab))
 
-(defun fuel-syntax--usings ()
+(make-variable-buffer-local
+ (defvar fuel-syntax--usings-function 'fuel-syntax--find-usings))
+
+(defsubst fuel-syntax--usings ()
+  (funcall fuel-syntax--usings-function))
+
+(defun fuel-syntax--find-usings ()
   (save-excursion
     (let ((usings)
           (in (fuel-syntax--current-vocab)))