Trying to code a "back tab"

Help with writing and playing macros

Trying to code a "back tab"

Postby BillStewart » Tue May 30, 2006 2:20 pm

Here's some macro pseudo-code I'm trying to assign to the Shift-Tab key:

Code: Select all
IfSel
[do what Shift-Tab normally does if text is selected]
Else
[backspace twice]
EndIf


My goal is to prevent Shift-Tab from tabbing forward (which I find bizarre) but backspace twice, but only if text is not selected (i.e., I don't want to lose Shift-Tab's normal behavior of un-tabbing selected text, if any text is selected).

As far as I can tell, this is not possible with the very limited macro language. Any tips are appreciated.

Thanks

Bill
User avatar
BillStewart
Basic User
Basic User
 
Posts: 25
Joined: Thu Sep 01, 2005 11:00 pm

Re: Trying to code a "back tab"

Postby BillStewart » Fri Jul 07, 2006 4:25 pm

It's been over 30 days and there are no replies, so I guess it's just not possible with UE's macro feature. (Does anyone else think that it's bizarre that Shift-Tab tabs forward?)

I've written to IDM to request this seemingly simple feature. I guess we'll have to wait and see.

Bill
User avatar
BillStewart
Basic User
Basic User
 
Posts: 25
Joined: Thu Sep 01, 2005 11:00 pm

Re: Trying to code a "back tab"

Postby mrainey56 » Fri Jul 07, 2006 6:18 pm

I'm sure this isn't exactly what you want - maybe it's a starting point for discussion.


InsertMode
ColumnModeOff
HexOff
UnixReOn
IfSel
Find RegExp "^\t*"
Replace All SelectText ""
Else
Key BACKSPACE
Key BACKSPACE
EndIf
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: Trying to code a "back tab"

Postby BillStewart » Fri Jul 07, 2006 6:32 pm

Hi mrainey56,

It looks like your macro will only work with "hard" tabs and will delete all leading tabs in the selected text. Nice try, though. I'd like to keep the editor's native Shift-Tab command if text is selected; otherwise, do a "back tab". It looks like UE's macro language isn't sophisticated enough to allow a macro to "chain" to a keystroke's native capability.

Bill
User avatar
BillStewart
Basic User
Basic User
 
Posts: 25
Joined: Thu Sep 01, 2005 11:00 pm

Re: Trying to code a "back tab"

Postby mrainey56 » Fri Jul 07, 2006 11:17 pm

This would work with hard tabs or spaces - it's set for four spaces, you could make it whatever number you like.

Only deletes the first hard tab or first four spaces.


Code: Select all
InsertMode
ColumnModeOff
HexOff
UnixReOn
IfSel
Find RegExp "^\t"
Replace All SelectText ""
Find RegExp "^    "
Replace All SelectText ""
Else
Key BACKSPACE
Key BACKSPACE
EndIf
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: Trying to code a "back tab"

Postby BillStewart » Mon Jul 10, 2006 2:43 pm

Hi mrainey56,

Well done. This is closer to my desired behavior, but it has at least one undesirable side-effect: The most recent "find string" is the string specified in the macro. Is there any way to perform a find/replace in a macro without causing the find/replace MRU list to be updated?

Also, it seems that this technique breaks down if the I change my tab width. (I still think it's bizarre that Shift-Tab does a forward tab.)

Bill
User avatar
BillStewart
Basic User
Basic User
 
Posts: 25
Joined: Thu Sep 01, 2005 11:00 pm

Re: Trying to code a "back tab"

Postby mrainey56 » Mon Jul 10, 2006 4:11 pm

I can't answer the MRU question. I seldom change the tab width.

If I did change the tab width frequently, and wanted to use the macro, I might try sticking one of these lines at the top of my file:

~#1
~#2
~#4


Basically, a couple of unique characters followed by the tab width. Use whatever unique strings are appropriate for you. Have as many possible tab widths as you like.

The macro would first search for ~#1. If ~#1 was found, code to remove one tab or space would be executed, then the macro would end.

If not found, the macro would do a search for ~#2. If ~#2 was found, code to remove one tab or two spaces would be executed, then the macro would end.

Find ~#1
IfFound
do stuff for tab width of one
ExitMacro
EndIf

Find ~#2
IfFound
do stuff for tab width of two
ExitMacro
EndIf

And so on. It sounds klutzy, probably is, but might help with your problem.

I'll leave it to you to play with the code, if you want to. If you can't get it to work, ask for help. If you find the concept revolting, sorry, it's my best shot right now.
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: Trying to code a "back tab"

Postby mrainey56 » Mon Jul 10, 2006 6:07 pm

I studied the idea a little more - probably too many gotchas to work out. Sorry.
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: Trying to code a

Postby Mofi » Tue Jul 11, 2006 3:37 pm

I have not posted anything to this thread till now because I simply can't understand what is the benefit pressing the 2 keys Shift+Tab instead of Backspace twice. I personally think that pressing the Backspace key twice is faster because easier to press than Shift+Tab.

However, the indent spaces can be also removed without a find/replace. But the solution would be extremly slow, because you have to copy the selected text into a new file, use a loop which removes the fixed number of indent spaces at very line of the text, selects the modified text, copies it, closes the new file and pastes it over the still selected text.

The macro code for unindenting a single line is available at Is there any shortcut to unindent a single line.

Also this solution has 2 problems. It works only for a fixed number of indent spaces and not tabs, if you do not write a better macro as the one mentioned above. And since UE v12.10+3 it will not really work because of the new focus handling when closing a file described at Problem with Previous Window/Tab Command, if you have more than 1 file open and your file is not the most right one in the open tab sequence.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Trying to code a "back tab"

Postby BillStewart » Fri Jul 14, 2006 1:12 pm

Hi Mofi,

I appreciate your input, but there are just too many limitations in the UE macro "language" to be very useful. IMHO, the macro system needs to be based on a programming language that supports programming features such as variables, conditionals, loops, etc.

In any case, maybe you don't understand the big deal because you've gotten used to UE's limitations. Believe me, some of UE's behavioral characteristics (character-by-character undo, lack of undo for certain features, and lack of back tab are just a few) feel really bizarre when you've worked with other, more capable, editors.

Bill
User avatar
BillStewart
Basic User
Basic User
 
Posts: 25
Joined: Thu Sep 01, 2005 11:00 pm

Re: Trying to code a "back tab"

Postby mrainey56 » Fri Jul 14, 2006 1:23 pm

feel really bizarre when you've worked with other, more capable, editors.


I hope you found all this out during the free trial period. Which editor is your favorite?
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: Trying to code a "back tab"

Postby BillStewart » Mon Jul 17, 2006 1:54 pm

My long-time favorite editor is The SemWare Editor, aka TSE (http://www.semware.com/). It looks a bit odd (the GUI version looks like a text-based program), but it has a built-in programming language called SAL and a macro compiler. It supports multi-keystroke chords, sensible and consistent grouped undo, etc.

Bill
User avatar
BillStewart
Basic User
Basic User
 
Posts: 25
Joined: Thu Sep 01, 2005 11:00 pm


Return to Macros