Author Topic: Adding my own beautifier for ruby  (Read 3578 times)

flethuseo

  • Senior Community Member
  • Posts: 177
  • Hero Points: 2
Adding my own beautifier for ruby
« on: May 14, 2014, 06:02:31 PM »
I have added the following macro that will allow beautifying ruby files (using the ruby-beautify gem), but I would like to take this one step further.

_command void beautify_ruby() {

   if (_select_type() == "") {
      select_all()
   } else if (_select_type() != "LINE" && _select_type() != "BLOCK") {
      // Convert it into a LINE selection
      _select_type('', 'T', 'LINE');
   }
   _str out = filter_command("rbeautify");
}

Can I tell Slickedit to use this as my beautifying command for ruby files. That is, if I go to Tools > Beautify > Beautify, it should run the command beautify_ruby().

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: Adding my own beautifier for ruby
« Reply #1 on: May 14, 2014, 06:36:31 PM »
Yes, but not without modifying one of our shipped .e files, which usually isn't recommended.  (mainly because applying a hotfix that updates the file you changed will revert your changes).

Two things.  In cformat.e, look for DEFAULT_BEAUTIFIER_EXT, and add " ruby=ruby" to the end of that string.  Save it and run "load" at the command line to load your changes. And, then rename your command to ruby_beautify(), and then reload it as well.

Once that's done the 'beautify' command will delegate to your ruby_beautify() command, and the option will be enabled in the Tools -> Beautify menu.

flethuseo

  • Senior Community Member
  • Posts: 177
  • Hero Points: 2
Re: Adding my own beautifier for ruby
« Reply #2 on: May 14, 2014, 07:50:15 PM »
Cool, it works. I have been doing that with a bunch of macros that come with Slickedit. Am I supposed to modify them in the

C:\Program Files\SlickEditV18.0.1 x64\macros\ directory, or in some other directory that "extends" them or overrides them.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: Adding my own beautifier for ruby
« Reply #3 on: May 14, 2014, 08:03:23 PM »
You can modify them in place, or make copies and modify the copy.  Hotfixes do not overwrite the .e files we ship with, so you're not in danger of losing source code that way.  (the hotfix.e files end up in your configuration directory, under the 'hotfixes' directory).

The real issue with modifications is that the hotfix process does not merge the fix in with whatever changes you made - it just loads up the new .e files that were packaged with the hotfix.  So if a fix replaces a file you modified, it's then up to you to remerge the changes you made into the newer .e file, and reload it.  Which can be tedious for extensive modifications.

jimlangrunner

  • Senior Community Member
  • Posts: 360
  • Hero Points: 31
  • Jim Lang - always a student.
Re: Adding my own beautifier for ruby
« Reply #4 on: May 15, 2014, 11:37:19 AM »
to that end - would it be reasonable to detect a file, say "mods.e" that contains modified macros derived from shipped-with macros that have been modified?  Then notify the user on loading the hotfix that macro "foo" has been updated in "ship_foo.e" and the user might want to update foo?  This assumes you have a process that loads all of the standard macros, then checks "mods.e" for updates to those macros and uses them if they exist? 

Or is that beyond the reasonable and into the "gee - where do they come up with these things" realm?