Author Topic: set filetype?  (Read 5558 times)

Stu

  • Community Member
  • Posts: 59
  • Hero Points: 0
set filetype?
« on: January 12, 2010, 02:42:15 AM »
After lots of hunting I figured out how to manually set the mode on a file.
What I want is for it to be automatic.

Right, so my build system is in ruby, I wanted to add rantfiles + rakefiles as ruby files.

1 - under tools -> options -> file options -> file type filters; My ruby filter is "*.rb;*.rby;rantfile;rakefile"

That works great. I verified it in the open file dialogue.

2 - Under language options -> Ruby, all I have is file extensions... no glob pattern, just a raw extension so if I add "rakefile" slickedit looks for "*.rakefile" which is not what I want.

Filters dont translate to filetypes :(

I tested it with makefiles, which have only file extenions "*.mk, *.mak" but it detects "Makefile" as a makefile so clearly I can do it somehow..

Only I cant figure that out.. I see some info in macros/defaults.e

anyone know how I can add my filetypes??

ScottW, VP of Dev

  • Senior Community Member
  • Posts: 1471
  • Hero Points: 64
Re: set filetype?
« Reply #1 on: January 12, 2010, 03:29:08 PM »
Currently, document mode is determined by the extension. We have implemented special handling for makefiles, though.

We have a change request in the system to address this. I'll see if I can get that implemented in v15.

Sandra

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 754
  • Hero Points: 36
Re: set filetype?
« Reply #2 on: January 12, 2010, 04:00:43 PM »
As it happens, we have a way for you to add your own handling to set the mode for files when we open them.

Enter the following code into a new Slick-C macro file (rantfile.e or whatever you want):

Code: [Select]
/**
 * User-defined file mode callback.  Whenever _SetEditorLanguage() is called,
 * this function is called.
 * 
 * @return int             0 if language mode was set in this callback
 *                         1 if no mode was set and the default actions in
 *                         _SetEditorLanguage should be used
 */
int userSelectEditorLanguage(_str lang, boolean bypass_buffer_setup=false)
{
   // strip out the file name only
   filename := strip_filename(p_buf_name, 'p');

   // determine if this is a ruby build system file (extensionless)
   if (file_eq(filename, 'rakefile') || file_eq(filename, 'rantfile')) {
     _SetEditorLanguage('ruby', bypass_buffer_setup);
     return 0;
   }

   return 1;
}

Then load the file (Macro > Load Module).  Now, whenever you open a file named "rantfile" or "rakefile", it should come up as a Ruby file.  You can extend this function as you need.  As Scott said, we'd like to eventually have a more formal way of doing this that doesn't require macro code, but this should work for you for now.

Stu

  • Community Member
  • Posts: 59
  • Hero Points: 0
Re: set filetype?
« Reply #3 on: January 13, 2010, 02:15:27 AM »
worked like a charm! :) thanks so much.

Hopefully 15 will match file selector globs to doc types or allow globs rather than fixed extensions.
eitherway, I'm happy with this solution provided above.

great stuff