代码之家  ›  专栏  ›  技术社区  ›  Benjamin Oakes

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

  •  19
  • Benjamin Oakes  · 技术社区  · 14 年前

    我的字典里有这些行 ~/.inputrc :

    set editing-mode vi 
    set keymap vi
    

    这允许我使用 vi 每个使用GNU readlines进行文本输入的程序中的键绑定。示例: python irb , sftp , bash sqlite3 等等它使使用命令行变得轻而易举。Matlab软件 使用readline,但是 键绑定将是 太神了 在调试或交互工作时具有。是否存在现有的解决方案?

    我倾向于使用 matlab -nosplash -nodesktop 从命令行开始,这让我思考:是否有可能编写一个这样的包装器 matlab

    更新:

    谢谢你的帮助。这几乎奏效了:

    # 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
    

    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
    
    3 回复  |  直到 11 年前
        1
  •  5
  •   Brooks Moses    14 年前

    谷歌搜索一下就发现了这一点 IO.popen() 这是一块合适的红宝石,在这里的回复中有更多的细节: 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
    

    这并不完全正确,因为在请求第一个输入行之前,您需要做一次内部循环,但它应该会给您一个想法。您可能还需要调整它要查找的提示文本。

    更新2:

    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
    
        2
  •  4
  •   towolf    14 年前

    你可以用 rlwrap 以直截了当的方式。

    rlwrap is a wrapper that uses the GNU readline library to allow the editing
    of keyboard input for any other command. 
    

    http://utopia.knoware.nl/~hlub/rlwrap/#rlwrap

    不幸的是,它会在MATLAB中阻止上下文相关的tab完成,这本身就很有用。

        3
  •  3
  •   AVB    14 年前

    实际上,你最好用C写这个-然后你可以打电话给 matlab engine 直接的。这基本上允许您使用GNU Readline库将自己的前端编写到matlab,如果您愿意的话。