Notepad++ and Ruby

Notepad++ is an excellent code editor for Ruby as it is, out of box. The remaining thing is to properly configure it, so it will be able not just run the code, but sometimes display the output of such.

There is an elegant way to make it work involves a bit more than simply typing ruby "$(FULL_CURRENT_PATH)" in the run command window. This, of course, will 100% work; however it runs and dismisses the output window unless the whole system is configured not to dismiss the command window automatically. Do not ask me how to configure this – I forgot such nonsense as I could not imagine why one would ever need even to consider this option.

Well, the solution looks quite simple, the command that is needed to put to the run command window is:

cmd /K ruby "$(FULL_CURRENT_PATH)"

And here it works. By the way, the run command window can be invoked via F5 key. Now, since it works, there is interesting button on that window, named Save. Click that. Well, it offers to name it (name Ruby fits very well) and select shortcut for it (Ctrl+R looks very appropriate). After this not so sophisticated procedure we have got a new menu item under the Run menu and a new shortcut. Both should work to execute the currently opened in Notepad++ Ruby code and keep the output window open. Cool.

By the way, the way it works that the file must be saved first. Otherwise the file does not exist and Notepad++ does not know what to run, and it just merely provides new 1 to the command interpreter, and the command shell will sadly declare that the file does not exist. Plus, it is good practice to save the code, giving you all the benefits of an advanced code editor: code highlighting, collapsing-expanding features and so on. And a saved code is always better than unsaved. Jesus saves.

So what if you like me have grown to dislike the command prompt and want to use something less reminding of MS-DOS 6.22? OK, of course there is a way to configure the command to call Powershell:

powershell -noexit ruby '$(FULL_CURRENT_PATH)'

Please note the single quotes used in the command. This is not a fancy replacement for double quotes – the double quotes will not work at all. Well, not at all, they will work if the path does not contain blanks, what rarely happens in age of Windows better that 3.11. Some day I will write about of “single vs double”, but right now just beleive me, like people believe to Jimmy Swaggart.

By the way, it is easy to mess up the command text, and it is not so obvious how to correct those mistakes. After monkeying not for a long time with right click everywhere in menu, i found the configuration file that saves this extra command. The file is %AppData%\Notepad++\shortcuts.xml Just by editing the xml one can quicky correct his mess. Of course you can not use Notepad++ to edit settings for Notepad++, you would need to remember your skills with vim.

Little later I found a civilized way to edit customizations like that there is Shortcut Mapper... menu item under Settings menu. Why one puts ... in the menu item? This is to be mystery forever. But the Run commands tab allows to edit name and shortcut (but not command) to the menu items under Run menu and even delete them. Surely, the ultimate edit is delete-create way. Zen of windows.


5 responses to “Notepad++ and Ruby

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s