Author Topic: forcing syntax highlighting regardless of file extension?  (Read 5888 times)

heedless

  • Community Member
  • Posts: 24
  • Hero Points: 1
forcing syntax highlighting regardless of file extension?
« on: March 07, 2007, 02:04:06 pm »
Hi,

I would like to have vsdiff use the proper syntax highlighting for a language i specify regardless of file extension.

I usually vsdiff between source code versions using rational's Clearcase. this can often lead to situations when the actual parameters passed to vsdiff are for instance:

vsdiff file1.cpp file2.cpp@@1


thus, the left pane window uses c++ syntax coloring and the right pane window uses no syntax highlighting at all.

Is there a way to force vsdiff to use a specific syntax highlighting method while disregarding the file extension?
(preferably, as an extra command line option..)

ScottW, VP of Dev

  • Senior Community Member
  • Posts: 1471
  • Hero Points: 64
Re: forcing syntax highlighting regardless of file extension?
« Reply #1 on: March 15, 2007, 03:01:25 pm »
Open the file in the editor window, then select Document > Set Mode and select the appropriate mode. Diffzilla will use that when it displays the file. Diffzilla does not have a means to set the document mode, so it uses whatever is already set for that file.

--Scott

heedless

  • Community Member
  • Posts: 24
  • Hero Points: 1
Re: forcing syntax highlighting regardless of file extension?
« Reply #2 on: March 15, 2007, 03:15:25 pm »
Thanks for you answer.

However the file suffixes are created dynamically and signify the version of the file, so I can't set the file mode in advance.

I thought there might be a command line switch to force file mode. That could've helped.

hs2

  • Senior Community Member
  • Posts: 2725
  • Hero Points: 281
Re: forcing syntax highlighting regardless of file extension?
« Reply #3 on: March 15, 2007, 03:44:41 pm »
I think providing a _switchbuf_* callback parsing the CC generated extension would help.
E.g. cut '@@*' and extract 'real' ext. from p_buf_name and select_edit_mode().

HS2

PS: Please post your solution - I'll also need it soon ...

heedless

  • Community Member
  • Posts: 24
  • Hero Points: 1
Re: forcing syntax highlighting regardless of file extension?
« Reply #4 on: March 15, 2007, 03:52:15 pm »
Sure, i'm on it :P

hs2

  • Senior Community Member
  • Posts: 2725
  • Hero Points: 281
Re: forcing syntax highlighting regardless of file extension?
« Reply #5 on: March 15, 2007, 03:55:49 pm »
Great  8)

Tim Kemp

  • Senior Community Member
  • Posts: 513
  • Hero Points: 83
Re: forcing syntax highlighting regardless of file extension?
« Reply #6 on: March 15, 2007, 06:02:28 pm »
How about this?  It's my first attempt at SlickC.

I discovered that strip_filename() won't strip everything but the extension (i.e. 'PDN'.)  The file name in the tab is still messed up because I don't know how to fix it without making changes to buftabs.e

- Tim

Code: [Select]
#include 'slick.sh'

void _buffer_add_fixCcType( int newbuffid, _str name, int flags = 0 )
{
  int atat = pos( '@@', name );

  if ( 0 != atat )
  {
    _str realName = substr( name, 1, atat - 1 );
    int lastDot = lastpos( '.', realName );
    _str ext = substr( realName, lastDot + 1 );
    select_edit_mode( ext );
  }
}

hs2

  • Senior Community Member
  • Posts: 2725
  • Hero Points: 281
Re: forcing syntax highlighting regardless of file extension?
« Reply #7 on: March 15, 2007, 06:24:14 pm »
Yep - _buffer_add_* is also fine. Great solution Tim - HP++ !
IMO the bufftab name is ok b/c it tells the version.

Thanks a lot,

HS2

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2107
  • Hero Points: 263
Re: forcing syntax highlighting regardless of file extension?
« Reply #8 on: March 15, 2007, 06:32:14 pm »
Here is an experimental solution for you.  This changes our behavior at a pretty low level with respect to getting the extension from a file name.  It should fix the problem you have with ClearCase's special file names.

The fix is to replace "get_extension()" in stdprocs.e with the following then reload stdprocs.e:

Code: [Select]
/**
 * Returns extension of buffer name without dot unless returnDot is true.
 *
 * @param buf_name  Filename to get extension from.
 * @param returnDot Specify true if you want '.' included in return value.
 * @return Returns extension of buffer name.
 *
 * @categories File_Functions
 */
_str get_extension(_str buf_name,boolean returnDot=false)
{
  if (def_vc_system == "ClearCase") {
     j := pos('@', buf_name);
     k := lastpos('.',buf_name);
     if ( j && k && j > k ) buf_name = substr(buf_name, 1, j-1);
  }
  _str extension='';
  int i=lastpos('.',buf_name);
  if ( i  ) {
    extension=substr(buf_name,(returnDot)?i:i+1);
    if ( verify(extension,'\/','M') ) {
      /* this is the extension of a directory name and not a filename */
      extension='';
    }
  } else {
    extension='';
  }
  return(strip(extension,'T','"'));
  /* messageNwait('extension='extension) */

}

Please let us know if this fixes the problem for you.  I have made the change specific to the case where you have configured SlickEdit to use ClearCase as your default version control system, so be sure to configure that before testing this change.

This is a pretty low level change, and it could cause other problems.  If so, please pull it out before reporting any bugs that may be due to this change.

hs2

  • Senior Community Member
  • Posts: 2725
  • Hero Points: 281
Re: forcing syntax highlighting regardless of file extension?
« Reply #9 on: March 15, 2007, 07:07:27 pm »
Not bad Dennis - but not perfect ;) (I assume you're still a bit exhausted after the release nightmare...)
You missed the 'SCC' cases when checking for ClearCase.
Using
if ( pos ( "ClearCase", def_vc_system ) ) {
instead of
if (def_vc_system == "ClearCase") {

should work for commandline and SCC setup.

Thanks a lot (and of course HP++ for this and the v12) !

HS2

Tim Kemp

  • Senior Community Member
  • Posts: 513
  • Hero Points: 83
Re: forcing syntax highlighting regardless of file extension?
« Reply #10 on: March 16, 2007, 07:26:02 pm »
Here's a minor improvement to the macro I included.  It also fixes the name of the file in the tab.  The way I did it is questionable, but at least it didn't require changes to a system file.

- Tim

Code: [Select]
#include 'slick.sh'

void _buffer_add_fixCcType( int newbuffid, _str name )
{
  int atat = pos( '@@', name );


  if ( 0 != atat )
  {
    _str realName = substr( name, 1, atat - 1 );
    int lastDot = lastpos( '.', realName );
    _str ext = substr( realName, lastDot + 1 );
    select_edit_mode( ext );
    _buffer_renamed_tabs( newbuffid, name, realName, 0 );
  }
}