Author Topic: filetype not in filename  (Read 9537 times)

Paul Gilmartin

  • Junior Community Member
  • Posts: 8
  • Hero Points: 0
filetype not in filename
« on: December 18, 2014, 07:30:21 AM »
We're using Slickedit with a competitor's CM system (IBM Rational CM Synergy).
This keeps archival versions under generated names ("/CM/Archive/12345678")
The Synergy DB tells us that that's "foo.c" but we must edit it as "12345678".
How can we tell Slickedit to use filetype ".c" for syntax highlighting?
I'd imagine something on the command line such as

    vs -type ".c" /CM/Archive/12345678

Thanks,
gil

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: filetype not in filename
« Reply #1 on: December 18, 2014, 11:00:42 AM »
This should work:
Code: [Select]
vs /CM/Archive/12345678 "-#select-mode C/C++"'select-mode' is the underlying command of 'Document>Select Mode'
See also 'Help>Index:Invocation Options'.
HS2

Graeme

  • Senior Community Member
  • Posts: 2793
  • Hero Points: 347
Re: filetype not in filename
« Reply #2 on: December 18, 2014, 12:00:05 PM »
See also "Extensionless file manager" in the help.
You could set up a pattern that treats any file whose name starts with a "1" as mapping to c/c++.
You could also write a macro that scanned a file when it's first opened and selected the mode based on the content of the file.

Dennis

  • Senior Community Member
  • Posts: 3954
  • Hero Points: 515
Re: filetype not in filename
« Reply #3 on: December 18, 2014, 06:19:38 PM »
If you have other languages mixed in there, and if you can retrieve the real file name from the database based on the mangled name, you could write a macro that gets the real file name and then selects the mode:

Code: [Select]
   _str synergy_cm_get_real_filename(_str f) {
      // call out to shell to get result
      return _PipeShellResult("whatever_command_it_takes " :+ _maybe_quote_filename(f));
   }
   _command void synergy_cm_select_mode()
                           name_info(MODENAME_ARG','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
   {
       f := synergy_cm_get_real_filename(p_buf_name);
       lang := _Filename2LangId(f);
       if (lang != "") _SetEditorLanguage(lang);
       p_DocumentName = f;  // optional
   }

Then you can use -#synergy_cm_select_mode on the command line.

Paul Gilmartin

  • Junior Community Member
  • Posts: 8
  • Hero Points: 0
Re: filetype not in filename
« Reply #4 on: December 18, 2014, 09:09:42 PM »
This should work:
Code: [Select]
vs /CM/Archive/12345678 "-#select-mode C/C++"'select-mode' is the underlying command of 'Document>Select Mode'
See also 'Help>Index:Invocation Options'.
HS2

The best suggestion I've received.  Thanks!  I issue the command:
    vs "-#select_mode Makefile" 221314
... and sure enough, it opens it as a Makefile.  *But*, I get
a dialog:
o Just map this file to Makefile
o Map all files named "221314" to Makefile
o Map all extensionless files in /foo/bar to Makefile
|_| Do not ask me to map file names or directories to languages again.

Clearly the last is what I want.  I exit and try again.  Same
dialog.  Did I neglect to save my profile?

(The better option would be, "Ask me only when I haven't told you".)

Also, I note that one of the languages I want to use has a space in
its name.  Do I need to quote that (how?) in the select_mode?

Thanks again,
gil

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6823
  • Hero Points: 526
Re: filetype not in filename
« Reply #5 on: December 18, 2014, 10:08:40 PM »
The select_mode command argument does not need to be quoted (i.e. "-#select bourne shell" will work fine).

As for that check box, it appears that there's a bug. The work around is to check that box at start up and change some other option so that the configuration gets saved. The option is getting set but not saved. That's the bug.

Clark

Paul Gilmartin

  • Junior Community Member
  • Posts: 8
  • Hero Points: 0
Re: filetype not in filename
« Reply #6 on: December 18, 2014, 10:56:32 PM »
The select_mode command argument does not need to be quoted (i.e. "-#select bourne shell" will work fine).

As for that check box, it appears that there's a bug. The work around is to check that box at start up and change some other option so that the configuration gets saved. The option is getting set but not saved. That's the bug.

Clark
Now, this is weird.  I got the "do not ask" button checked and saved;
I don't know what I did.  Now, for the command:
    vs +#select_mode Makefile 314745
the file opens as "Plain Text".  I exit Slick and issue
the same command again, and the file comes up as
"Makefile".  Another bug?  Does it only remember the
type when I Exit, not when I Open?

Thanks,
gil

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: filetype not in filename
« Reply #7 on: December 18, 2014, 11:20:44 PM »
Not sure, but the correct syntax and acc. to the docs is:
Code: [Select]
vs 314745 "-#select-mode Makefile"It worked for me with SEv19.0.1 RC.
I think the language mode of files in the MRU list (File menu) is also saved and restored for convenience reasons.
HS2

Dennis

  • Senior Community Member
  • Posts: 3954
  • Hero Points: 515
Re: filetype not in filename
« Reply #8 on: December 19, 2014, 04:33:04 PM »
Just to clarify on the quoting.  The -#<command args> argument does need to be quoted, but the mode name itself does not need to be quoted, even if it includes spaces.

Example:
Code: [Select]
  vs +new /CM/Archive/12345678 "-#select-mode Bourne Shell"

Paul Gilmartin

  • Junior Community Member
  • Posts: 8
  • Hero Points: 0
Re: filetype not in filename
« Reply #9 on: December 19, 2014, 05:48:28 PM »
Just to clarify on the quoting.  The -#<command args> argument does need to be quoted, but the mode name itself does not need to be quoted, even if it includes spaces.

Example:
Code: [Select]
  vs +new /CM/Archive/12345678 "-#select-mode Bourne Shell"

Aren't you describing POSIX Shell syntax, rather than vs
argument syntax?

But I'm so POSIX-oriented that I automatically put the option
before the command argument.  Must the order be reversed, in fact?

Hmmm.  The "select" links in each ply of this display give
"Javascript void(0)" on both Safari 5.1.10 and Firefox 34.0.5
on OS X 10.6.8.

Thanks,
gil

Dennis

  • Senior Community Member
  • Posts: 3954
  • Hero Points: 515
Re: filetype not in filename
« Reply #10 on: December 20, 2014, 12:06:04 AM »
Things happen in the order they are specified on the command line, so yes, the -#select-mode needs to be after the filename.  Otherwise, you are running select-mode before opening the file.  It has to be this way so that you can specify multiple -# commands on the command line.

Even POSIX shell syntax has notable exceptions where necessary, such as the arguments to 'find' and 'xargs'

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: filetype not in filename
« Reply #11 on: December 20, 2014, 01:12:57 AM »
Quote
Things happen in the order they are specified on the command line
Exactly. Just like editing a file in SE as usual and invoking a sequence of commands.
HS2
« Last Edit: December 20, 2014, 01:14:45 AM by hs2 »

jporkkahtc

  • Senior Community Member
  • Posts: 2620
  • Hero Points: 210
  • Text
Re: filetype not in filename
« Reply #12 on: December 20, 2014, 03:28:25 PM »
It would be great if Slick could have an "automatic" type that used the equivalent of the linux "file" command.
"file" has a bunch of hueristics to determine the type of the file, be it binary or C or whatever.




I'd really like slick to at least have some "binary" autodetect - so that I can more easily recursively search without having to enumerate all good/bad file extensions to try to get slick to not search thru the many binary files (*.o;*.ilk;*.a;*.lib;*.pdb;*.etc....)


Having it use this to automatically determine the type of extensionless files would be icing on the cake.

Paul Gilmartin

  • Junior Community Member
  • Posts: 8
  • Hero Points: 0
Re: filetype not in filename
« Reply #13 on: December 20, 2014, 07:51:24 PM »
It would be great if Slick could have an "automatic" type that used the equivalent of the linux "file" command.
"file" has a bunch of hueristics to determine the type of the file, be it binary or C or whatever.
<snip!>

I'm already working on a shell script to bridge from CM Synergy
to Slick (Works much better now that I understand about command
sequence -- thanks!)

Such a script might invoke "file" in command substitution; parse
it's output; edit with the "-#select-mode [whatever]" command.
You'd still need a massive "case/switch" statement to convert
"file"'s returned values to Slick modes.

Now, the hard one:  CM Synergy may pass my wrapper strings such as:

    "306440" "View asm370 - source (SWSRDMG.s,I16926760)"

I know that "306440" means a filename in the current directory,
and "SWSRDMG.s,I16926760" are the name the programmer knows
and our issue tracking number and I can convert "asm370" to
"-#select_mode IBM HLASM"  But the title bar and file tabs show
"306440"; not very useful to the programmer.  Can these values
be overridden so the file tabs show "SWSRDMG.s,I16926760"?
(I'm not very hopeful.)

I like this forum's user interface.  Much better than others I deal with.

Thanks,
gil

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6823
  • Hero Points: 526
Re: filetype not in filename
« Reply #14 on: December 20, 2014, 09:34:48 PM »
Try the docname command on the SlickEdit command line. It allows you to set the display name without effecting the filename on disk. You can append another "-#docname the name" argument to the invocation.