命令行Matlab中的vi输入模式?

Ben*_*kes 19 ruby vim matlab

我有这些线~/.inputrc:

set editing-mode vi 
set keymap vi
Run Code Online (Sandbox Code Playgroud)

这允许我vi在每个使用GNU读取行进行文本输入的程序中使用键绑定.例如:python,irb,sftp,bash,sqlite3,等.它使得使用命令行变得轻而易举.Matlab 使用readlines,但是在调试或交互式工作时,vi键绑定会很棒.有现成的解决方案吗?

我倾向于使用matlab -nosplash -nodesktop命令行,并且让我思考:有可能写出一个包装使用readlines方法和输入传递给matlab?(如果我必须实现这一点,我可能更愿意在Ruby中这样做.)

更新:

谢谢您的帮助.这几乎有效:

# See also: http://bogojoker.com/readline/
require 'readline'

puts 'Starting Matlab...'
io = IO.popen('matlab -nosplash -nodesktop 2>&1', 'w+')

while input_line = Readline.readline('>> ', true)
  io.puts input_line
  puts io.gets
end
Run Code Online (Sandbox Code Playgroud)

但它一次只从Matlab读取一行(因为我正在使用gets).关于如何在下次等待输入之前获取所有内容的任何想法?这是发生了什么(我在>>提示符处输入内容):

Starting Matlab...
>> 1

>> 2
                            < M A T L A B (R) >
>> 3
                  Copyright 1984-2009 The MathWorks, Inc.
>> 4
                 Version 7.8.0.347 (R2009a) 32-bit (glnx86)
>> 5
                             February 12, 2009
>> 6

>> 7

>> 8
  To get started, type one of these: helpwin, helpdesk, or demo.
>> 9
  For product information, visit www.mathworks.com.
>> 0

>> 1
>> 
>> 2
ans =
>> 3

>> 4
     1
>> 5

>> 6
>> 
>> 7
ans =
>> 8

>> 9
     2
>> 0

>> 1
>> 
>> 2
ans =
>> 3

>> 4
     3
Run Code Online (Sandbox Code Playgroud)

Bro*_*ses 5

是的,这应该很容易.这只是一般情况下"打开一个进程并绑定其stdin和stdout"问题的一个特例,这并不困难.

一些谷歌搜索发现这IO.popen()是Ruby的正确部分,这里的回复还有一些细节:http://groups.google.com/group/ruby-talk-google/browse_thread/thread/0bbf0a3f1668184c.希望,这足以让你开始!

更新:看起来你的包装几乎就在那里.你需要完成的是识别Matlab何时要求输入,然后只询问用户输入.我建议尝试这个伪代码:

while input_line = Readline.readline('>> ', true)
  io.puts input_line
  while ((output_line = io.gets) != '>> ')  // Loop until we get a prompt.
    puts io.gets
  end
end
Run Code Online (Sandbox Code Playgroud)

这不太对,因为在你要求第一个输入行之前你需要做一次内循环,但它应该给你一个想法.您可能还需要调整它正在查找的提示文本.

更新2:好的,所以我们还需要考虑提示后没有EOL的事实,因此io.gets将挂起.这是一个修订版本,它使用了一个事实,你可以给Matlab提示一个空行,它只会给你另一个提示而不做任何事情.我重新安排了循环以使事情变得更清晰,但这意味着你现在必须添加逻辑来弄清楚你什么时候完成.

while [not done]   // figure this out somehow
  io.puts blank_line                        // This will answer the first
                                            // prompt we get.
  while ((output_line = io.gets) != '>> ')  // Loop until we get a prompt.
    puts io.gets                            // This won't hang, since the
  end                                       // prompt will get the blank
                                            // line we just sent.

  input_line = Readline.readline('>> ', true)  // Get something, feed it
  io.puts input_line                           // to the next prompt.

  output_line = io.gets   // This will eat the prompt that corresponds to
                          // the line we just fed in.
end
Run Code Online (Sandbox Code Playgroud)