willghatch / racket-rash

The Reckless Racket Shell
http://rash-lang.org
Other
549 stars 31 forks source link

«cd -» and tab completion for external programs? #45

Open formbi-kupiec opened 5 years ago

willghatch commented 5 years ago

I'm not sure what you mean by “tab completion for external programs”. Do you mean completion for the name of a program, or custom completion for flags and such dependent on the program?

I haven't made the completer function visible to users, and I probably should, in which case you could easily have the former. But completion is currently very limited to the point where you might not want to add it. Right now the completion function only receives the current word under the cursor -- it gets no context to know if it's completing a command name, a file name, etc. So any different completions you run would have to run together. I want to fix this in general by using a new line editor, such as making a line-editor mode for remacs or rmacs, perhaps.

Better completion and line editing is definitely on my radar, though I can't say how soon I'll actually get there.

As for «cd -», FYI you could make your own -- here's a simple sketch:

(require (for-syntax racket/base syntax/parse))
(define last-dir-box (box #f))
(define-line-macro cd/tracking
  (syntax-parser
    #:datum-literals (-)
    [(_ -)
     #'(let ([last-dir (unbox last-dir-box)])
         (set-box! last-dir-box (current-directory))
         (current-directory last-dir))]
    [(_ dir)
     #'(begin
         (set-box! last-dir-box (current-directory))
         (current-directory (format "~a" 'dir)))]))

Then cd/tracking would have the behavior you want (though this basic version probably lacks other features you also want). Perhaps I'll roll that functionality into the default cd.

formbi-kupiec commented 5 years ago

I mean, for example, that typing «em» and TAB should give «emacs». Your example doesn't work :/

zlee-personal commented 5 years ago

Are you using racket -l rash/repl? Tab completion works for me.

willghatch commented 5 years ago

Ok, I've just pushed a commit that adds optional command completion, and I'm going to explain how to turn it on here.

The default completion from now until I replace readline will be path completion. But you can use optional command or racket function completion by doing the following (in your rashrc file):

(require readline/readline)
;; NOTE - this is not stable, and WILL completely go away eventually!
(require rash/private/rashrc-lib)
(set-completion-function! (make-composite-completer complete-paths complete-commands complete-namespaced))

But really just paths is probably what you want until a completer can get some context for what sort of thing it should be completing, or at least an ability to add multiple completion keybindings.

I don't think I'm going to put this in the real docs, because I want to replace it ASAP, and I don't think it's really very useful. Maybe early next year I'll have some time to make a line-editor interface for remacs. Maybe. Sorry it's not better until then.

rcorrear commented 5 years ago

Hi @willghatch, have you had time to improve this since the last message? Rash looks awesome but (to me) it's not really usable without at least some basic completion. Is there any way I can help? (mind you, I'm not a Scheme dev, just find it very appealing).

willghatch commented 5 years ago

On Thu, Jun 27, 2019 at 02:58:16AM -0700, Ricardo Correa wrote:

Hi @willghatch, have you had time to improve this since the last message? Rash looks awesome but (to me) it's not really usable without at least some basic completion. Is there any way I can help? (mind you, I'm not a Scheme dev, just find it very appealing).

Sorry, I'm afraid I haven't. My PhD advisor advises me that making a line editor for Rash should be “my first side-project after graduating”. And I'm inclined to to agree with him. So I'll definitely do this eventually, but probably not this year.

If you want to make a line editor or a better FFI module for libreadline, feel free! But I don't think there will be any serious progress on completion until Rash has a better line editor.

So for the time being Rash will probably remain mostly usable for scripting, unfortunately.