FUEL: Word completion in listener, bound to TAB by default.
parent
5d20b0e202
commit
472a8edcc8
|
@ -163,32 +163,35 @@ M: source-file fuel-pprint path>> fuel-pprint ;
|
||||||
: fuel-get-edit-location ( defspec -- )
|
: fuel-get-edit-location ( defspec -- )
|
||||||
where [
|
where [
|
||||||
first2 [ (normalize-path) ] dip 2array fuel-eval-set-result
|
first2 [ (normalize-path) ] dip 2array fuel-eval-set-result
|
||||||
] when* ;
|
] when* ; inline
|
||||||
|
|
||||||
: fuel-get-vocab-location ( vocab -- )
|
: fuel-get-vocab-location ( vocab -- )
|
||||||
>vocab-link fuel-get-edit-location ;
|
>vocab-link fuel-get-edit-location ; inline
|
||||||
|
|
||||||
: (fuel-get-vocabs) ( -- seq )
|
: (fuel-get-vocabs) ( -- seq )
|
||||||
all-vocabs-seq [ vocab-name ] map ; inline
|
all-vocabs-seq [ vocab-name ] map ; inline
|
||||||
|
|
||||||
: fuel-get-vocabs ( -- )
|
: fuel-get-vocabs ( -- )
|
||||||
(fuel-get-vocabs) fuel-eval-set-result ;
|
(fuel-get-vocabs) fuel-eval-set-result ; inline
|
||||||
|
|
||||||
MEMO: (fuel-vocab-words) ( name -- seq )
|
MEMO: (fuel-vocab-words) ( name -- seq )
|
||||||
>vocab-link words [ name>> ] map ;
|
>vocab-link words [ name>> ] map ;
|
||||||
|
|
||||||
: fuel-vocabs-words ( names/f -- seq )
|
: fuel-current-words ( -- seq )
|
||||||
[ (fuel-get-vocabs) ] unless* prune
|
use get [ keys ] map concat ; inline
|
||||||
[ (fuel-vocab-words) ] map concat natural-sort ;
|
|
||||||
|
: fuel-vocabs-words ( names -- seq )
|
||||||
|
prune [ (fuel-vocab-words) ] map concat ; inline
|
||||||
|
|
||||||
: (fuel-get-words) ( prefix names/f -- seq )
|
: (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 ( prefix names -- )
|
||||||
(fuel-get-words) fuel-eval-set-result ; inline
|
(fuel-get-words) fuel-eval-set-result ; inline
|
||||||
|
|
||||||
: fuel-run-file ( path -- ) run-file ; inline
|
: fuel-run-file ( path -- ) run-file ; inline
|
||||||
|
|
||||||
: fuel-startup ( -- ) "listener" run ; inline
|
: fuel-startup ( -- ) "listener" run-file ; inline
|
||||||
|
|
||||||
MAIN: fuel-startup
|
MAIN: fuel-startup
|
||||||
|
|
|
@ -55,19 +55,27 @@ the same as C-cz)).
|
||||||
- C-cz : switch to listener
|
- C-cz : switch to listener
|
||||||
- C-co : cycle between code, tests and docs factor files
|
- 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
|
- M-TAB : complete word at point
|
||||||
- C-cC-ev : edit vocabulary
|
- C-cC-ev : edit vocabulary
|
||||||
|
|
||||||
- C-cr, C-cC-er : eval region
|
- C-cr, C-cC-er : eval region
|
||||||
- C-M-r, C-cC-ee : eval region, extending it to definition boundaries
|
- C-M-r, C-cC-ee : eval region, extending it to definition boundaries
|
||||||
- C-M-x, C-cC-ex : eval definition around point
|
- 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-da : toggle autodoc mode
|
||||||
- C-cC-dd : help for word at point
|
- C-cC-dd : help for word at point
|
||||||
- C-cC-ds : short help 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):
|
* In the debugger (it pops up upon eval/compilation errors):
|
||||||
|
|
||||||
- g : go to error
|
- g : go to error
|
||||||
|
|
|
@ -32,9 +32,11 @@
|
||||||
(fuel-eval--send/wait '(:fuel* (fuel-get-vocabs) "fuel" (:array)))))))
|
(fuel-eval--send/wait '(:fuel* (fuel-get-vocabs) "fuel" (:array)))))))
|
||||||
fuel-completion--vocabs)
|
fuel-completion--vocabs)
|
||||||
|
|
||||||
(defsubst fuel-completion--words (prefix vocabs)
|
(defun fuel-completion--words (prefix vocabs)
|
||||||
(fuel-eval--retort-result
|
(let ((vs (if vocabs (cons :array vocabs) 'f))
|
||||||
(fuel-eval--send/wait `(:fuel* (,prefix V{ ,@vocabs } fuel-get-words) t ,vocabs))))
|
(us (or vocabs 't)))
|
||||||
|
(fuel-eval--retort-result
|
||||||
|
(fuel-eval--send/wait `(:fuel* (,prefix ,vs fuel-get-words) t ,us)))))
|
||||||
|
|
||||||
|
|
||||||
;;; Completions window handling, heavily inspired in slime's:
|
;;; Completions window handling, heavily inspired in slime's:
|
||||||
|
@ -135,10 +137,11 @@ terminates a current completion."
|
||||||
|
|
||||||
;;; Completion functionality:
|
;;; Completion functionality:
|
||||||
|
|
||||||
(defsubst fuel-completion--word-list (prefix)
|
(defun fuel-completion--word-list (prefix)
|
||||||
(let ((fuel-log--inhibit-p t))
|
(let* ((fuel-log--inhibit-p t)
|
||||||
(fuel-completion--words
|
(cv (fuel-syntax--current-vocab))
|
||||||
prefix `("syntax" ,(fuel-syntax--current-vocab) ,@(fuel-syntax--usings)))))
|
(vs (and cv `("syntax" ,cv ,@(fuel-syntax--usings)))))
|
||||||
|
(fuel-completion--words prefix vs)))
|
||||||
|
|
||||||
(defun fuel-completion--complete (prefix)
|
(defun fuel-completion--complete (prefix)
|
||||||
(let* ((words (fuel-completion--word-list prefix))
|
(let* ((words (fuel-completion--word-list prefix))
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
(require 'fuel-eval)
|
(require 'fuel-eval)
|
||||||
(require 'fuel-base)
|
(require 'fuel-base)
|
||||||
|
(require 'fuel-completion)
|
||||||
|
(require 'fuel-syntax)
|
||||||
(require 'comint)
|
(require 'comint)
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,10 +70,10 @@ buffer."
|
||||||
(error "Could not run factor: image file %s not readable" image))
|
(error "Could not run factor: image file %s not readable" image))
|
||||||
(message "Starting FUEL listener ...")
|
(message "Starting FUEL listener ...")
|
||||||
(comint-exec (fuel-listener--buffer) "factor"
|
(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))
|
(pop-to-buffer (fuel-listener--buffer))
|
||||||
(goto-char (point-max))
|
(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)
|
(fuel-listener--wait-for-prompt 30)
|
||||||
(message "FUEL listener up and running!")))
|
(message "FUEL listener up and running!")))
|
||||||
|
|
||||||
|
@ -101,6 +103,17 @@ buffer."
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
(unless seen (error "No prompt found!")))))
|
(unless seen (error "No prompt found!")))))
|
||||||
|
|
||||||
|
|
||||||
|
;;; 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))
|
||||||
|
|
||||||
|
|
||||||
;;; Interface: starting fuel listener
|
;;; Interface: starting fuel listener
|
||||||
|
|
||||||
|
@ -126,13 +139,16 @@ buffer."
|
||||||
\\{fuel-listener-mode-map}"
|
\\{fuel-listener-mode-map}"
|
||||||
(set (make-local-variable 'comint-prompt-regexp) fuel-listener--prompt-regex)
|
(set (make-local-variable 'comint-prompt-regexp) fuel-listener--prompt-regex)
|
||||||
(set (make-local-variable 'comint-prompt-read-only) t)
|
(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-cz" 'run-factor)
|
||||||
(define-key fuel-listener-mode-map "\C-c\C-z" '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 "\C-ch" 'fuel-help)
|
||||||
(define-key fuel-listener-mode-map "\M-." 'fuel-edit-word-at-point)
|
(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 "\C-ck" 'fuel-run-file)
|
||||||
|
(define-key fuel-listener-mode-map (kbd "TAB") 'fuel-completion--complete-symbol)
|
||||||
|
|
||||||
|
|
||||||
(provide 'fuel-listener)
|
(provide 'fuel-listener)
|
||||||
|
|
|
@ -241,7 +241,13 @@
|
||||||
|
|
||||||
;;; USING/IN:
|
;;; 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)
|
(let* ((vocab)
|
||||||
(ip
|
(ip
|
||||||
(save-excursion
|
(save-excursion
|
||||||
|
@ -258,7 +264,13 @@
|
||||||
(setq vocab (format "%s.%s" vocab (downcase sub))))))))
|
(setq vocab (format "%s.%s" vocab (downcase sub))))))))
|
||||||
vocab))
|
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
|
(save-excursion
|
||||||
(let ((usings)
|
(let ((usings)
|
||||||
(in (fuel-syntax--current-vocab)))
|
(in (fuel-syntax--current-vocab)))
|
||||||
|
|
Loading…
Reference in New Issue