Is there a way to set auto-indentation a per file type setting? It seems there is no such a feature. I've tried to implement it through scripting but with a partial success only.
You can control with the syntax highlighting wordfile(s) where indent/unindent should be done. But enabling/disabling auto indent on a per file type base is not possible, unfortunately. I would need this also because I like auto indent, but not for editing normal text files or some type of files like batch files.
My idea was to control state of auto indent for syntax highlighted files with the indent/unindent strings settings in the wordfile(s). Examples:
/Indent Strings = "{"
/Unindent Strings = "}"
in the syntax highlighting definition for C/C++ and JavaScript should be interpreted as use auto indent (if enabled in the configuration dialog) and indent/unindent on { and } plus indent a new line to start of the line above. That works already.
/Indent Strings = "no_unindent"
/Unindent Strings = "no_unindent"
in my syntax highlighting definition for HTML files means indent a new line to start of the line above, but never increase the number of indent spaces automatically and never unindent automatically. This works also already. The trick here is to specify indent and unindent strings which never occur in the files of this type.
/Indent Strings = ""
/Unindent Strings = ""
should be interpreted as no auto indent for files highlighted with this syntax highlighting definition. So specifying explicitely an empty indent AND an empty unindent string should be interpreted by UltraEdit to turn off auto indent for files highlighted with this syntax highlighting when the configuration setting is enabled.
For syntax highlighting definitions not containing
/Indent Strings =
/Unindent Strings =
and for files without syntax highlighting the behavior should be unchanged which would mean auto indent is based only on the configuration setting and works like my second example which I use for HTML files (and some others). It would be possible to create a syntax highlighting wordfile which highlights nothing (no keywords, all colors set to standard text color), contains the empty indent/unindent strings definitions and is applied to all type of files not highlighted by any other syntax highlighting definition. Such a "turn off auto indent for all not highlighted files wordfile" would be already possible.
A completely different approach would be to move the 2 auto indent settings from Editor Display - Formatting to Editor - Word Wrap/Tab Settings to control auto indent like the auto-complete, tab and word wrap settings per file type. But this approach could cause a compatibility problem when not applying on update/upgrade the current global setting to all already defined file types (drop down list entries) in this dialog.
If you support my feature request or have a better idea how to control auto indent per file type taking downward compatibility into account please send an email to IDM support with a link to this post or with your suggestion. Please post also your suggestion here.
My workaround is that I use UEStudio (or UltraEdit with a project specific INI for older projects defined on command line of the shortcut to start UE with that INI file which also loads the project) for editing files where I want auto indent and UltraEdit for all other files. In UEStudio the auto indent setting is enabled and in UltraEdit for general text editing (using uedit32.ini) it is disabled.
My idea was to control state of auto indent for syntax highlighted files with the indent/unindent strings settings in the wordfile(s). Examples:
/Indent Strings = "{"
/Unindent Strings = "}"
in the syntax highlighting definition for C/C++ and JavaScript should be interpreted as use auto indent (if enabled in the configuration dialog) and indent/unindent on { and } plus indent a new line to start of the line above. That works already.
/Indent Strings = "no_unindent"
/Unindent Strings = "no_unindent"
in my syntax highlighting definition for HTML files means indent a new line to start of the line above, but never increase the number of indent spaces automatically and never unindent automatically. This works also already. The trick here is to specify indent and unindent strings which never occur in the files of this type.
/Indent Strings = ""
/Unindent Strings = ""
should be interpreted as no auto indent for files highlighted with this syntax highlighting definition. So specifying explicitely an empty indent AND an empty unindent string should be interpreted by UltraEdit to turn off auto indent for files highlighted with this syntax highlighting when the configuration setting is enabled.
For syntax highlighting definitions not containing
/Indent Strings =
/Unindent Strings =
and for files without syntax highlighting the behavior should be unchanged which would mean auto indent is based only on the configuration setting and works like my second example which I use for HTML files (and some others). It would be possible to create a syntax highlighting wordfile which highlights nothing (no keywords, all colors set to standard text color), contains the empty indent/unindent strings definitions and is applied to all type of files not highlighted by any other syntax highlighting definition. Such a "turn off auto indent for all not highlighted files wordfile" would be already possible.
A completely different approach would be to move the 2 auto indent settings from Editor Display - Formatting to Editor - Word Wrap/Tab Settings to control auto indent like the auto-complete, tab and word wrap settings per file type. But this approach could cause a compatibility problem when not applying on update/upgrade the current global setting to all already defined file types (drop down list entries) in this dialog.
If you support my feature request or have a better idea how to control auto indent per file type taking downward compatibility into account please send an email to IDM support with a link to this post or with your suggestion. Please post also your suggestion here.
My workaround is that I use UEStudio (or UltraEdit with a project specific INI for older projects defined on command line of the shortcut to start UE with that INI file which also loads the project) for editing files where I want auto indent and UltraEdit for all other files. In UEStudio the auto indent setting is enabled and in UltraEdit for general text editing (using uedit32.ini) it is disabled.
Best regards from an UC/UE/UES for Windows user from Austria
- 2
Making auto indentation a per file-type setting
I've written a small script that makes indentation a per file type setting (at last) which was published here the first time on 2009-10-12.
This is a(n improved version of) script which makes auto indentation a per file setting.
Just set auto indentation to on and follow the instructions on how to associate it with <Enter> key below, if you have any problems associating script with Return key. All is done as usual at Scripting dialog.
Please report what you think about it!
This is a(n improved version of) script which makes auto indentation a per file setting.
Code: Select all
//============================================================================
//
// Filename: Kill_Indentation_Exceptionally.js
//
// Description: Indentation switching on/off on per file type basis
// 1) Switch Auto Indentation on
// ( Configuration -> Editor Display -> Formatting )
// 2) Add file extensions you want to have auto
// indentation for in untouchable list
// 3) Associate this script with Return key
//
//---------------- UltraEdit scripting API version indicator -----------------
//
// Version = 1.00
//
//============================================================================
var untouchable =
[
"c", "cc", "cpp", "cxx",
"h", "hh", "hpp", "hxx",
"js", "java",
"php",
"html",
"pas", "pp",
"py"
];
//----------------------------------------------------------------------------
function imitate_return()
{
UltraEdit.activeDocument.startSelect();
UltraEdit.activeDocument.key( "END" );
UltraEdit.activeDocument.endSelect();
var clipboard;
var was_selected = UltraEdit.activeDocument.isSel();
if ( was_selected )
{
clipboard = UltraEdit.clipboardContent;
UltraEdit.activeDocument.cut();
}
UltraEdit.activeDocument.insertLine();
if ( was_selected )
{
var column = UltraEdit.activeDocument.currentColumnNum;
if (typeof(UltraEdit.activeDocumentIdx) == "undefined") column++;
UltraEdit.activeDocument.paste();
UltraEdit.clipboardContent = clipboard;
UltraEdit.activeDocument.gotoLine( 0, column );
}
}
//============================================================================
imitate_return();
var indentation_killing = true;
for ( var i = untouchable.length; --i >= 0; )
{
//UltraEdit.messageBox( untouchable[i] );
if ( UltraEdit.activeDocument.isExt( untouchable[i] ) )
{
indentation_killing = false;
break;
}
}
if ( indentation_killing )
{
UltraEdit.activeDocument.deleteToStartOfLine();
}
//============================================================================
- Press Ctrl + Enter
- You'll see Ctrl + RETURN
- Select "Ctrl + " with your mouse
- Press Delete
- Seems to be done, click OK.
Please report what you think about it!