Smart Tabs

This forum is user-to-user based and not regularly monitored by IDM.
Please see the note at the top of this page on how to contact IDM.

Smart Tabs

Postby pliebrand » Wed Jul 14, 2004 1:56 pm

Is there a smart tabbing option for UltraEdit? For example, if I have the following text:

Code: Select all
    move                 to $_test
    move

and I press TAB after the second move, that will align under the next text above it (to), for example:

Code: Select all
    move                 to $_test
    move                 _ <- cursor gets placed here on 1 tab

Thanks!
User avatar
pliebrand
Newbie
 
Posts: 3
Joined: Tue Jul 13, 2004 11:00 pm

Re: Smart Tabs

Postby DanKirkd » Thu Jul 15, 2004 11:21 pm

This can be done by setting Tab stops in the UltraEdit Configuration settings on the Edit tab.

To set multiple Tab Stop Values separate them by commas. Quoting the Help on this, "The user may define multiple TAB stop values (up to 12) in comma-delimited format, i.e. "4,4,8". The last value defined will be used for subsequent TABS. In the example above, the first two TABS would be equal to four spaces and all subsequent TABS would be equivalent to 8 spaces."

However, it appears this only works if you don't have the "Use spaces in place of Tabs" option selected. If it is selected, the Tab Stop Values seem to be ignored and the Indent Spaces setting is used for all tabs.

Dan
User avatar
DanKirkd
Basic User
Basic User
 
Posts: 39
Joined: Wed Jul 14, 2004 11:00 pm

Re: Smart Tabs

Postby Andreas » Fri Jul 16, 2004 2:43 am

I guess what pliebrand meant was to automatically have the cursor move (i.e. insert spaces) with a single press of the Tab key to wherever the next character is in the line above (preferably the last non-empty line above), independently of fixed tab settings... and, well, AFAIK that's not implemented, but I'd like to see that feature too...
User avatar
Andreas
Basic User
Basic User
 
Posts: 10
Joined: Thu Jul 15, 2004 11:00 pm
Location: PAF, Germany

Re: Smart Tabs

Postby pliebrand » Fri Jul 16, 2004 9:03 am

Andreas, bingo!
User avatar
pliebrand
Newbie
 
Posts: 3
Joined: Tue Jul 13, 2004 11:00 pm

Re: Smart Tabs

Postby DanKirkd » Fri Jul 16, 2004 9:55 am

Ah! That would indeed be some pretty smart tabbing feature.

Dan
User avatar
DanKirkd
Basic User
Basic User
 
Posts: 39
Joined: Wed Jul 14, 2004 11:00 pm

Re: Smart Tabs

Postby elenzil » Tue Aug 17, 2004 6:16 pm

Yes, indeed.

If anyone ever gets around to implementing this, I find that it's better to use Spaces rather than Tabs for Non-Leading Indents.
This is because if you use actual tabs, when somebody with a different tab-stop setup than you views the file, your nicely aligned columns will be messed up.

It's still good to use an actual tab for the Leading Indents, tho.

Orion
User avatar
elenzil
Newbie
 
Posts: 3
Joined: Mon Aug 16, 2004 11:00 pm

Re: Smart Tabs

Postby bozo » Fri Jan 11, 2013 6:54 am

Nothing since 2004?! I just requested this enhancement...

Anyone know any more?
bozo
Newbie
 
Posts: 1
Joined: Fri Jan 11, 2013 6:39 am

Re: Smart Tabs

Postby Mofi » Sat Mar 16, 2013 6:53 am

Those wanting such a feature do not need to wait until IDM implements it. With an UltraEdit script it can be already done.

Code: Select all
// This script inserts at current line spaces to align the next
// word on the next non whitespace character in the line above.

function SmartSpaces()
{
   // Get current line number at caret position.
   var nActLineNum = UltraEdit.activeDocument.currentLineNum;

   // Do nothing if there is no line above.
   if (nActLineNum < 2) return false;

   // Get column number (with correction for UE < 16.00 and UES < 10.00).
   var nActColNum = UltraEdit.activeDocument.currentColumnNum;
   if (typeof(UltraEdit.activeDocumentIdx) == "undefined") nActColNum++;

   // Move caret to the line above.
   UltraEdit.activeDocument.key("UP ARROW");

   // If the configuration setting "Allow positioning beyond line end" is
   // enabled, the caret could be beyond line end. So move the caret to
   // end of line and verify that the caret is now not left to initial
   // column at script start which means the line above is shorter.
   UltraEdit.activeDocument.key("END");
   nNewColNum = UltraEdit.activeDocument.currentColumnNum;
   if (typeof(UltraEdit.activeDocumentIdx) == "undefined") nNewColNum++;
   if (nNewColNum < nActColNum)
   {
      // Restore caret position and do nothing if line above is shorter.
      UltraEdit.activeDocument.gotoLine(nActLineNum,nActColNum);
      return false;
   }

   // Move caret back to the right column in the line above.
   UltraEdit.activeDocument.gotoLine(0,nActColNum);

   // Find next space or tab character in this line.
   while (!UltraEdit.activeDocument.isChar(' ') && !UltraEdit.activeDocument.isChar('\t'))
   {
      // Restore caret position and do nothing if end of line is reached.
      if (UltraEdit.activeDocument.isChar('\r') || UltraEdit.activeDocument.isChar('\n'))
      {
         UltraEdit.activeDocument.gotoLine(nActLineNum,nActColNum);
         return false;
      }
      UltraEdit.activeDocument.key("RIGHT ARROW");
   }

   // Find character which is not a space or tab in this line.
   UltraEdit.activeDocument.key("CTRL+RIGHT ARROW");
   // Restore caret position and do nothing if end of line is reached.
   if (UltraEdit.activeDocument.isChar('\r') || UltraEdit.activeDocument.isChar('\n'))
   {
      UltraEdit.activeDocument.gotoLine(nActLineNum,nActColNum);
      return false;
   }

   // Calculate the number of spaces to insert in the line below.
   nNewColNum = UltraEdit.activeDocument.currentColumnNum;
   if (typeof(UltraEdit.activeDocumentIdx) == "undefined") nNewColNum++;
   var nSpaceCount = nNewColNum - nActColNum;

   // Move caret back to initial position on script start.
   UltraEdit.activeDocument.gotoLine(nActLineNum,nActColNum);

   // Build the string to insert consisting only of spaces.
   var sSpaces = "";
   while (nSpaceCount--) sSpaces += ' ';

   // It would be also possible insert tabs instead of spaces. But that
   // is much more complicated as the script has to know the tab stop
   // value for the current file and therefore how many spaces must be
   // replaced by a tab character. And additionally it is necessary to
   // determine how many spaces the first inserted tab represents in
   // dependence of the column number at caret position.

   // Determine if overstrike mode is active and if this
   // is the case switch temporarily to the insert mode.
   var bInsertMode = UltraEdit.insOvrMode;
   if (!bInsertMode) UltraEdit.insertMode();

   // Write the spaces into the file.
   UltraEdit.activeDocument.write(sSpaces);

   // Switch back to overstrike mode if active before insert.
   if (!bInsertMode) UltraEdit.overStrikeMode();
   return true;
}

if (UltraEdit.document.length > 0)  // Is any file opened?
{
   // If the active file is not opened in hex editing mode.
   if (UltraEdit.activeDocument.hexMode == false)
   {
      if (!SmartSpaces())
      {
         // The function does nothing if it was not possible to determine
         // how many spaces to insert. You can insert here whatever wanted
         // to define the default behavior like inserting 3 spaces or 1 tab.
      }
   }
}

Please note that the script as posted here inserts always spaces and not tabs as I use only spaces in my source code files. However, the big advantage of a script instead of a built-in function is that everybody can customize the script to personal requirements. So if somebody wants to insert tabs instead of spaces, feel free to modify the script to your needs. I have added some hints how to insert tabs instead of spaces.

The script should be added to the script list and of course assigning a hotkey or chord should be done for fast execution by key. I do not recommend assigning Tab, Ctrl+Tab, Ctrl+Shift+Tab, Shift+Tab, Alt+Tab or Alt+Shift+Tab to the script as those keys are predefined by Windows and UltraEdit GUI for different features depending on context.

Well, assigning key TAB to the script could be done, if additional code is added to the script to emulate other functions of TAB key like increasing indentation of all selected lines by one indent level if 1 or more lines are selected on script start.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to UltraEdit General Discussion