yi-editor / yi

The Haskell-Scriptable Editor
GNU General Public License v2.0
1.51k stars 201 forks source link

Cannot provide input to shell commands #997

Closed quickdudley closed 7 years ago

quickdudley commented 7 years ago

To replicate (assuming vim keymap because I don't know how to use emacs):

  1. Use #995 or the ":!" command won't work
  2. In normal mode type ":!ghci" (or another command as long as it reads from stdin)
  3. Try to provide input to the running program

What happens

The yi screen splits horizontally and the program output appears on the right hand pane. You can switch to that pane by pressing ctrl-w then the right arrow and insert text into the buffer, but there seems to be no way to send character data to the running command.

What should happen

I'm not sure. In the case of the original vim: the vim screen itself vanishes until the child command is finished, but having the program output go to a yi buffer is actually a nice feature so we probably don't want to directly imitate them here.

mpwp commented 7 years ago

edit: Oops, I just saw your push request. I may not answer to your issue..

You need to tell it explicitly in your $YI_CONFIG.hs, as far as I know it's not automaticaly implemented.

For example, check this config in the yi-contrib package: https://hackage.haskell.org/package/yi-contrib-0.10.1/docs/src/Yi-Config-Users-Gwern.html#config

mpwp commented 7 years ago

Bonus, if you need it: In my config I've just added hdevtools and stylish-haskell basic support, like that:

import qualified Data.Text as T
import Yi.Command (buildRun)
import Yi.Monad (gets)

withFile :: MonadEditor m => (FilePath -> m ()) -> m ()
withFile f = do
  filename <- withEditor . withCurrentBuffer $ gets file
  case filename of
    Just name -> f name
    Nothing -> return ()

hdevtools :: YiM ()
hdevtools = withFile $ \name -> buildRun "hdevtools" ["check", T.pack name] (const $ return ())

stylish :: YiM ()
stylish = withFile $ \name -> buildRun "stylish-haskell" ["-i", T.pack name] (const $ return ())

-- add in your `ConfigM ()`:
publishAction "hdevtools" hdevtools
publishAction "stylish haskell" stylish

Finally add your shortcuts in the modeKeyMap, for example:

ctrlCh 'h' ?>>! hdevtools
ctrlCh 's' ? >>! stylish

You might need more imports and some refactoring (like that stylish-haskell opens an unecessary window). You can also add hlint, ghc-mod and what you want!

quickdudley commented 7 years ago

I should check what exactly the Yi.Mode.Haskell.ghciLoadBuffer function does and possibly modify my pull request accordingly. The commits in my pull request already let me do what I was wanting to (although the way the :bd command is handled in the vim keymap is still annoying)