diff --git a/scheme/nuit-engine.scm b/scheme/nuit-engine.scm index e86509d..eccc194 100644 --- a/scheme/nuit-engine.scm +++ b/scheme/nuit-engine.scm @@ -161,6 +161,19 @@ (move-cursor (command-buffer) (result-buffer)) (refresh-command-window)))) +(define (current-command-line) + (let ((entered (last (buffer-text (command-buffer))))) + (if (string=? entered "") + #f + entered))) + +(define (replace-current-command-line! text) + (set-buffer-text! + (command-buffer) + (reverse + (cons text + (cdr (reverse (buffer-text (command-buffer)))))))) + (define (toggle-command/scheme-mode) (cond ((command-buffer-in-command-mode?) @@ -172,6 +185,28 @@ (move-cursor (command-buffer) (result-buffer)) (refresh-command-window)) +;; assumes we are in command mode +(define (toggle-command/scheme-mode-with-conversion) + (cond + ((current-command-line) + => (lambda (cmdln) + (cond + ((lex/parse-partial-command-line cmdln #f) + => (lambda (parsed) + (let ((scheme-str + (write-to-string + (compile-command-line parsed)))) + (replace-current-command-line! scheme-str) + (enter-scheme-mode!) + (set-buffer-pos-col! (command-buffer) + (+ 2 (string-length scheme-str))) + (paint-command-frame-window) + (paint-command-window-contents) + (move-cursor (command-buffer) (result-buffer)) + (refresh-command-window)))) + (else (values))))) + (else (values)))) + (define (handle-return-key) (let ((command-line (cadr (reverse (buffer-text (command-buffer)))))) (debug-message "command-line " command-line) @@ -401,7 +436,13 @@ (offer-completions (last (buffer-text (command-buffer)))))) (loop (wait-for-input) #f maybe-selector))) - ;; F7 toggle scheme-mode / command-mode (FIXME: find a better key) + ((and (focus-on-command-buffer?) + (command-buffer-in-command-mode?) + c-x-pressed? + (= ch (config 'main 'switch-command-buffer-mode-key))) + (toggle-command/scheme-mode-with-conversion) + (loop (wait-for-input) #f #f)) + ((= ch (config 'main 'switch-command-buffer-mode-key)) (toggle-command/scheme-mode) (loop (wait-for-input) #f #f)) diff --git a/scheme/nuit-packages.scm b/scheme/nuit-packages.scm index d54a797..bca2e3d 100644 --- a/scheme/nuit-packages.scm +++ b/scheme/nuit-packages.scm @@ -896,6 +896,8 @@ configuration command-line-parser + command-line-compiler + utils focus-table result-buffer-changes nuit-eval/focus-table