Page 1 of 1

Diff. Syntax Definition for files of no extension

Posted: Wed Mar 13, 2002 5:51 pm
by Kevin Otto
Is there a way to have Textpad choose different syntax highlighting for files based on the first line in the file? I write UNIX shell scripts, perl scripts, and python scripts, and I don't give an extension to any of them to make it easy for non-technical people on my team to run them without knowing what language the scripts were written in. But... this means that Textpad uses the same syntax highlighting for all of them. If it could parse the first line, that would be sweet. For example, the first line of a Korn shell script would be:

#!/bin/ksh

The first line of a Perl script would be:

#!/usr/bin/perl

So if I could tell Textpad to use Korn shell syntax highlighting for "#!/bin/ksh" and Perl syntax highlighting for "#!/usr/bin/perl", that would be wonderful. Any ideas how to do this? I could write a program that would rename the file to have an appropriate extension then kick off Textpad, but I don't like to use Explorer to open files. Thanks for your help!

Re: Diff. Syntax Definition for files of no extension

Posted: Thu Mar 14, 2002 9:06 am
by Carlyle Sutphen
Short answer, no. It shouldn't be a hard thing to implement but since there are other much more needed additions to TextPad's functionality, I'm afraid you'll have to accept that that mod will be a while in coming. TextPad users have been wanting a macro editor, for example, a lo-lo-lo-lo-lo a lo-lo-lo-lo-lo a lo-lo lo-longly time.

You could do a number of things to get the effects you want.

First, give the files the endings common for the interpreter it is written for. That will have the advantage of letting a tech person know what type of file it is without looking inside first. Or make it easier to search for all files of a given type with the file command.

Next, for the non-techies, your options are:
1. create a set of aliases in /etc/profile
-> this works in all shells and acheives your purpose
2. write a set of functions and set FPATH in /etc/profile
-> this precludes the use of ksh or bash
-> it gives you the ability to set the environment on a per user basis
3. use logical links
-> messy, uses up inodes and requires that the files don't move

Re: Diff. Syntax Definition for files of no extension

Posted: Thu Mar 14, 2002 9:59 pm
by Roy Beatty
You could also set a a TextPad workspace, open all of the files, manually Alt+Enter each one to set the syntax, and save the workspace.

Hmm, thinking out loud here -- could you set up a macro to interogate the first line and apply a different syntax file based on what it found? (I don't .SYN, so I don't know.)

8-)

Re: Diff. Syntax Definition for files of no extension - WORK

Posted: Fri Mar 15, 2002 9:49 am
by Carlyle Sutphen
You know what? I just might start using workspaces. I just created my first one to test the abillity to save the syntax and just realized that all the files I am working with whenever I close up shop can be reopened in the same state I left them, including the views, cursor position, syntax, split ...

I am impressed.

But I still think I would go for the function variant I suggested so new files added to the workspace (or old ones readded) wouldn't have to be manually set to a syntax but be automatically based on the file ending as defined by configuring new document classes.

I like your loud thought there. But without a macro language it is difficult to conditionally do one of two things. What you suggested would actually be possible if the preferences could be chosen in macro recording mode. I just tested it and it is possible. But that should be brought up in a seperate topic.