Syntax Management

You know that TKE has syntax highlighting and editing support for lots of programming languages and file formats which helps make TKE useful for a wide spectrum of users. However, because any one individual probably only uses a dozen or so in their normal workflow, displaying all of those unused languages is unnecessary. Fortunately, TKE has a solution that helps eliminate the language clutter in the UI.

Go to the Preferences window (Edit / Preferences / Edit Global – User), select the General pane and then the Languages tab as shown in the image below.

Language Preference Table

The languages table displays a listing of all supported languages within the application. To hide a language from view in the View / Set Syntax submenu and the syntax menu in the lower right-hand corner of the main application window, simply deselect the checkbox next to the syntax to hide. Likewise, you can unhide a language from view by selecting the checkbox.

Though hiding a syntax helps keep language clutter from occurring in the menus, it does not disable TKE from identifying and highlighting files of hidden languages if they those files are opened.

Since we are in the language management table, we’ll also point out that this table displays the syntax extensions for each language. If a file of a particular extension is opened, TKE will use the information from this table to automatically identify which syntax highlighting to apply to the file. The default extensions come from the TKE syntax description files. If you need to add, delete or change file extensions, simply click on the table cell to edit and make the appropriate changes.

To see more information and download your copy of the TKE code editor, visit http://tke.sourceforge.net.

Advertisements
Syntax Management

Managing Themes

Themes in TKE control the look of the editor. Themes can alter the look of the window elements such as color, size, thickness, etc. They can set the colors used in syntax highlighting. They can also set the various icons used throughout the application.

TKE has several different themes that you can choose from via the View / Set Theme submenu. Just select a theme from the available list to cause the UI to immediately update. However, using the menu will only cause the theme to be changed while the application is running. If you close TKE and restart it, TKE will use the theme that was set in the preferences area.

To change the theme via the preferences window, launch the preferences (via Edit / Preferences / Edit User – Global menu option) and select the Appearance panel in the sidebar. The first option in the panel will allow you to set the default theme to use when launching TKE.

image-12
Setting Default Theme in Preferences

But what if you want to try out more themes can come built into TKE? Well, TKE has a way to import new themes using the Manage Themes tab in the Appearances Panel. Selecting that tab will display the list of all themes that are currently available within the application.

image-86
Theme Manager

The theme table displays all of the available themes within TKE. You can change the visibility of themes by clicking on the checkbox in the Visible column of the table. If a theme’s visibility is turned off, the associated theme will not be displayed in any of the theme selection menus. This can be useful for hiding built-in themes that you are not interested in using.

To get new themes, click on the Get More Themes… button in the lower right corner of the panel. This will launch your web browser to the new TKE themes page where you can browse, filter and download other available pre-built free themes. When you download a theme from the website, to install the theme you can click on the Add button which will launch a file selection dialog window. Find the downloaded theme and click on the Open button to install the theme.

In addition to installing new themes, you can also delete previously imported themes by selecting the theme and clicking on the Delete button. You can also edit any theme by selecting the theme and clicking on the Edit button. This will launch the theme editor (which will be a topic of future conversation).

Themes are not just eye candy within TKE. Each saved session can set its own theme, making themes useful for session identification.

To see more information and download your copy of the TKE code editor, visit tke.sourceforge.net.

Managing Themes

Vim Modelines

Everyone seems to have their own favorite editing preferences regarding things like:

  1. Should tabs be converted to spaces?
  2. How many spaces should be used if I hit the tab key?
  3. How many spaces should be for an indentation?

And so on and so forth.

Most editors, including TKE, allow you to specify these various editing preferences to your individual liking, but how should these settings be handled if you are sharing a file with a wider audience? If everyone uses different values and makes edits to the file, the structure of the file is going to look really bad, making the code harder to read and understand.

In smaller circles, you could make a “rule” that everyone must never use tab characters, but this rule is hard to enforce, especially in a larger audience.

Fortunately, for most editors that support Vim, which includes TKE, there is the concept of the Vim modeline. This is a line towards the top or bottom of a file which tells the editor how to handle formatting for the given file. These formatting options are specific to the file and will not mess up your preference values.

To create a Vim modeline to your file, it is best to put it inside a comment block in either the first or second line of the file or at the very bottom of the file. TKE allows you to specify how many lines at the top or bottom of the file to look for a modeline.

The following graphic shows an example of what a modeline might look like:

img-alternative-text

This example modeline sets the file format (endline character) to use the unix format, sets the shiftwidth value to 4 spaces and forces the editing buffer to treat the file as Tcl syntax.

You can learn more about modelines in the official Vim documentation at vimdoc.sourceforge.net.

To see more information and download your copy of the TKE code editor, visit tke.sourceforge.net.

Vim Modelines

Find/Replace Transmogrification

Do you ever find yourself with the editing situation where you need to transform a text pattern to a string that contains information in that pattern? For example, suppose you want to convert all Tcl style assignments to C-style assignments.

Tcl:
set foo “some value”

C:
foo = “some value”;

This may seem like a time-consuming task until you know that TKE supports this type editing with the “Find / Find and Replace” capability. Because “Find and Replace” supports regular expression syntax, you can place any text that you would like to use in the “Replace” field by surrounding them with parenthesis in the “Find” field. You can then reference these matched text values in the “Replace” field by specifying a backslash () character followed by a number with corresponds to the left parenthesis order (starting at a value of 1).

So to implement a solution to the problem above, we could search the text for the pattern:

(s+)sets+(w+)s+(.*)$

This will place the preceding whitespace into variable “1”, the variable name of the Tcl “set” command into variable “2” and the value being assigned to the variable in variable “3”. We can then perform the text transformation in the replace entry field with the value:

12 = 3;

Once the text has been input, all Tcl set commands found in the editing buffer will be transformed into the C equivalents.

Pretty slick right? Use this powerful editing feature to make quick work of complex, repetitive editing tasks.

To see more information and download your copy of the TKE code editor, visit tke.sourceforge.net

Find/Replace Transmogrification