: 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
- 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
(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:
\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))
(require 'fuel-eval)
(require 'fuel-base)
+(require 'fuel-completion)
+(require 'fuel-syntax)
(require 'comint)
\f
(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!")))
(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
\\{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)
\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)))