Running Ruby script in emacs

Discussion in 'Ruby' started by duke, Apr 14, 2011.

  1. duke

    duke Guest

    Hey ...

    I'm taking my first steps with Ruby. I have ruby-mode loaded and
    working. I also have run-ruby, but we'll forget about that for the
    moment.

    I have a working script that I want to "compile" and run while in ruby-
    mode. I grok how to compile it - no worries there. The script asks for
    input from the user. That's what I don't know how to do! Is there a
    way to input a value while in the 'compilation' process? TIA...
    --
    Duke
     
    duke, Apr 14, 2011
    #1
    1. Advertising

  2. duke

    Ryan Davis Guest

    On Apr 14, 2011, at 10:41 , duke wrote:

    > Hey ...
    >=20
    > I'm taking my first steps with Ruby. I have ruby-mode loaded and
    > working. I also have run-ruby, but we'll forget about that for the
    > moment.
    >=20
    > I have a working script that I want to "compile" and run while in =

    ruby-
    > mode. I grok how to compile it - no worries there. The script asks for
    > input from the user. That's what I don't know how to do! Is there a
    > way to input a value while in the 'compilation' process? TIA...


    M-x compile doesn't allow for interactive use, so you don't want that.

    I use M-x shell for almost all these scenarios (and nearly all other =
    shell use, really). You can also look at my autotest.el if you're =
    wanting to make something shell-like but more tweaked out for your use. =
    You can find that on emacswiki.
     
    Ryan Davis, Apr 14, 2011
    #2
    1. Advertising

  3. duke

    Duke Guest

    On Apr 14, 1:04 pm, Ryan Davis <> wrote:
    > On Apr 14, 2011, at 10:41 , duke wrote:
    >
    > > Hey ...

    >
    > > I'm taking my first steps with Ruby. I have ruby-mode loaded and
    > > working. I also have run-ruby, but we'll forget about that for the
    > > moment.

    >
    > > I have a working script that I want to "compile" and run while in ruby-
    > > mode. I grok how to compile it - no worries there. The script asks for
    > > input from the user. That's what I don't know how to do! Is there a
    > > way to input a value while in the 'compilation' process? TIA...

    >
    > M-x compile doesn't allow for interactive use, so you don't want that.


    OK!

    > I use M-x shell for almost all these scenarios (and nearly all other
    > shell use, really). You can also look at my autotest.el if you're
    > wanting to make something shell-like but more tweaked out for your
    > use. You can find that on emacswiki.


    Much obliged! Thanks ...
     
    Duke, Apr 14, 2011
    #3
  4. duke

    duke Guest

    On Apr 14, 4:42 pm, "mouser" <> wrote:
    > On 14-Apr-2011, duke <> wrote:
    >
    > > Hey ...

    >
    > > I'm taking my first steps with Ruby. I have ruby-mode loaded and
    > > working. I also have run-ruby, but we'll forget about that for the
    > > moment.

    >
    > > I have a working script that I want to "compile" and run while in ruby-
    > > mode. I grok how to compile it - no worries there. The script asks for
    > > input from the user. That's what I don't know how to do! Is there a
    > > way to input a value while in the 'compilation' process? TIA...

    >
    > Have you looked into ruby-compilation.el?  The version on emacswiki.orgis
    > old, but you can either install it via ELPA, or fromhttps://github.com/eschulte/rinari/tree/master/utildirectly.  You can then
    > M-x ruby-compilation-this-buffer and it will execute your script in a
    > compilation buffer.  You can input data in the compilation window, but note
    > that you might find that RET doesn't do the job because it's been shadowed
    > by a different mode.  If this happens to you, you will need to rebind
    > comint-send-input.


    Thank you so much! I'll give it a try, for sure!
     
    duke, Apr 15, 2011
    #4
  5. duke

    duke Guest

    On Apr 15, 12:55 pm, "mouser" <> wrote:
    > On 15-Apr-2011, duke <> wrote:
    >
    > > Thank you so much! I'll give it a try, for sure!

    >
    > There are a number of other good packages for Ruby in ELPA as well.  I think
    > you might have to manually install mode-compile.el, IIRC.  ELPA doesn'tseem
    > to supply that, but I think this package depends on it.  Seehttp://www.emacswiki.org/emacs/ModeCompile


    I installed ruby-compilation.el from ELPA, after installing support
    for the latter. I fired some Ruby code, and it works! but ...

    Your were right ...

    > If this happens to you, you will need to rebind comint-send-input.


    What do you mean by "rebind comint-send-input"?

    The way I'm doing it is:

    after I'm done inputting data into the program, I do a M-x comint-send-
    input, instead of a `cr'. Is that correct?

    It executes OK, and the program output is correct, but I may be taking
    "the long way around". :) Thanks for your input.
     
    duke, Apr 16, 2011
    #5
  6. duke

    Ryan Davis Guest

    On Apr 16, 2011, at 13:45 , mouser wrote:

    > Uninstall ruby-compilation from ELPA (hit 'd' on it's line in
    > package-list-packages, then hit 'x'). Then, install the source for
    > ruby-compilation (from
    > =

    https://github.com/eschulte/rinari/raw/master/util/ruby-compilation.el) =
    in
    > your load path (somewhere in ~/.emacs.d for instance). Next, add =

    "(require
    > 'ruby-compilation)" to ~/.emacs. Finally, open up the =

    ruby-compilation.el
    > file in your load path and add "(define-key map [return]
    > 'comint-send-input)" to defvar ruby-compilation-minor-mode-map (for =

    instance
    > at line 279). The last part is required because for some reason
    > compilation-mode shadows the comint-send-input binding though it's not
    > immediately apparent where that is happening.


    It'd be a lot more maintainable if you didn't modify the file and =
    instead added the define-key to your .emacs:

    (define-key ruby-compilation-minor-mode-map [return] 'comint-send-input)
     
    Ryan Davis, Apr 17, 2011
    #6
  7. duke

    duke Guest

    On Apr 16, 2:43 pm, "mouser" <> wrote:
    > On 16-Apr-2011, duke <> wrote:
    >
    > > It executes OK, and the program output is correct, but I may be taking
    > > "the long way around". :) Thanks for your input.

    >
    > You might find the following will make your life easier.
    >
    > Uninstall ruby-compilation from ELPA (hit 'd' on it's line in
    > package-list-packages, then hit 'x').  Then, install the source for
    > ruby-compilation (fromhttps://github.com/eschulte/rinari/raw/master/util/ruby-compilation.el) in
    > your load path (somewhere in ~/.emacs.d for instance).  Next, add "(require
    > 'ruby-compilation)" to ~/.emacs.  Finally, open up the ruby-compilation..el
    > file in your load path and add "(define-key map [return]
    > 'comint-send-input)" to defvar ruby-compilation-minor-mode-map (for instance
    > at line 279).  The last part is required because for some reason
    > compilation-mode shadows the comint-send-input binding though it's not
    > immediately apparent where that is happening.
    >
    > This gives you a couple advantages over installing it from ELPA.  C-x twill
    > invoke ruby-compilation-this-buffer whenever you are in ruby-mode, and now
    > hitting return/enter will invoke comint-send-input in the compilation
    > buffer.
    >
    > By the way, you might find the following useful for learning and programming
    > Ruby in Emacs.  Seehttp://www.emacswiki.org/emacs/FlymakeRubyfor automated
    > syntax checking.  Also, install the ruby-debug (or ruby-debug19 for Ruby
    > 1.9) gem for Ruby debugging.  Take a look athttp://bashdb.sourceforge.net/ruby-debug/rdebug-emacs.htmlfor Emacs
    > integration of this debugger.


    Much obliged! I'll give it a shot tomorrow!
     
    duke, Apr 17, 2011
    #7
  8. duke

    duke Guest

    On Apr 16, 2:43 pm, "mouser" <> wrote:
    > On 16-Apr-2011, duke <> wrote:
    >
    > > It executes OK, and the program output is correct, but I may be taking
    > > "the long way around". :) Thanks for your input.

    >
    > You might find the following will make your life easier.
    >
    > Uninstall ruby-compilation from ELPA (hit 'd' on it's line in
    > package-list-packages, then hit 'x').  Then, install the source for
    > ruby-compilation (fromhttps://github.com/eschulte/rinari/raw/master/util/ruby-compilation.el) in
    > your load path (somewhere in ~/.emacs.d for instance).  Next, add "(require
    > 'ruby-compilation)" to ~/.emacs.  Finally, open up the ruby-compilation..el
    > file in your load path and add "(define-key map [return]
    > 'comint-send-input)" to defvar ruby-compilation-minor-mode-map (for instance
    > at line 279).  The last part is required because for some reason
    > compilation-mode shadows the comint-send-input binding though it's not
    > immediately apparent where that is happening.
    >
    > This gives you a couple advantages over installing it from ELPA.  C-x twill
    > invoke ruby-compilation-this-buffer whenever you are in ruby-mode, and now
    > hitting return/enter will invoke comint-send-input in the compilation
    > buffer.


    OK! Followed your instructions to the letter ...
    and hacked my .emacs for the key map stuff, as per Ryans advice ...
    NO joy!

    In *Messages* buffer, I get:

    "compilation-next-error: No error here"

    after being asked for the required input.

    The script does work BTW. Any ideas?

    > By the way, you might find the following useful for learning and programming
    > Ruby in Emacs.  Seehttp://www.emacswiki.org/emacs/FlymakeRubyfor automated
    > syntax checking.  Also, install the ruby-debug (or ruby-debug19 for Ruby
    > 1.9) gem for Ruby debugging.  Take a look at http://bashdb.sourceforge.net/ruby-debug/rdebug-emacs.htmlfor Emacs
    > integration of this debugger.


    Thanks a lot for all those links. They surely will be useful to me.
    Much obliged!
    --
    duke
     
    duke, Apr 18, 2011
    #8
  9. duke

    duke Guest

    On Apr 18, 3:15 pm, "mouser" <> wrote:
    > On 18-Apr-2011, duke <> wrote:
    >
    > > OK! Followed your instructions to the letter ...
    > > and hacked my .emacs for the key map stuff, as per Ryans advice ...
    > > NO joy!

    >
    > It sounds like return is still bound to compile-goto-error.  Did you restart
    > Emacs after modifying your .emacs file?  You might want to check your
    > keybindings in the compilation buffer.  Get it in focus and hit C-h b, and a
    > new window will be created with your current keybindings.  Look under
    > ruby-compilation-minor-mode in the keybinding buffer and see if there is an
    > entry for key <return> and binding comint-send-input.


    Everything is now working great! I had simply re-loaded my .emacs file
    thinking that doing so would be enough. Once I re-started "emacs",
    well things couldn't be much better! Thanks a bunch.
    --
    duke
     
    duke, Apr 19, 2011
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rex Eastbourne

    Running Python interpreter in Emacs

    Rex Eastbourne, Jun 23, 2005, in forum: Python
    Replies:
    12
    Views:
    781
    Rex Eastbourne
    Jul 2, 2005
  2. Sells, Fred

    RE: Running Python interpreter in Emacs

    Sells, Fred, Jun 27, 2005, in forum: Python
    Replies:
    0
    Views:
    414
    Sells, Fred
    Jun 27, 2005
  3. Replies:
    2
    Views:
    164
    Forrest Chang
    Aug 19, 2005
  4. HiHeelHottie
    Replies:
    0
    Views:
    100
    HiHeelHottie
    Sep 8, 2007
  5. Adam Funk
    Replies:
    4
    Views:
    258
    Adam Funk
    Jan 29, 2007
Loading...

Share This Page