AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Manual block tabbing / detabbing

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
[VxE]



Joined: 07 Oct 2006
Posts: 1496

PostPosted: Sun Aug 24, 2008 10:22 pm    Post subject: Manual block tabbing / detabbing Reply with quote

This is a little something whipped up because I don't use a fancy editor that has built-in auto indenting and whatnot. Basically, what this script does is while the [`] button is held down, the [tab] and [esc] keys become hotkeys that add / remove indentation from the selected block of text. Doing so does not deselect the text, so you can spam it pretty easily. Releasing the [`] key will spit out a normal backtick otherwise.

It also converts alternate indentations (like the triple space from these forums) into tabs (configurable).

Tested in notepad. Comments welcome.

Code:
;<><><><><><><><><><><><><><><><><><><><><><><><>
;<><><><><><><><><><><><><><><><><><><><><><><><>
;<><>
;<><>  Block Tabber/Detabber, by [VxE]
;<><>
;<><>  Simply select a block of text
;<><>  and use [`][tab] to tab it in
;<><>  or [`][esc] to tab it back out
;<><>
;<><><><><><><><><><><><><><><><><><><><><><><><>
;<><><><><><><><><><><><><><><><><><><><><><><><>

#SingleInstance, Force
Indent := A_Tab ; your primary indentation character
Compatible := "   " ; triple space (as per forum code blocks) or whatever
; other kind of indentation you want to integrate.

$`::
bktik = 0
Hotkey, $Tab, iTab, on
Hotkey, $Esc, iEsc, on
return

$` up::
Hotkey, $Tab, iTab, off
Hotkey, $Esc, iEsc, off
If !bktik
   Send {blind}{``}
return

iTab:
bktik := BlockIndentChange( "`n", "`n" Indent, "`n" ,"`n" Compatible )
return

iEsc:
bktik := BlockIndentChange( "`n" Indent , "`n", "`n" Compatible, "`n")
return

BlockIndentChange( in1, out1, in2 = "", out2 = "")
{
   clip := clipboardall
   clipboard := ""
   SendPlay, ^x
   Clipwait, 9, 1
   StringReplace, clipboard, clipboard, %in2%, %in1%, all
   StringReplace, clipboard, clipboard, %out2%, %out1%, all
   StringReplace, clipboard, clipboard, %in1%, %out1%, all
   StringReplace, clipboard, clipboard, `r, `r, UseErrorLevel
   total := Strlen(clipboard) - ErrorLevel
   SendPlay, ^v+{Left %total%}
   Clipboard := clip
   return total
}

_________________
My Home Thread
More Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Back to top
View user's profile Send private message
Guest






PostPosted: Mon Aug 25, 2008 9:19 am    Post subject: Re: Manual block tabbing / detabbing Reply with quote

[VxE] wrote:
...I don't use a fancy editor that has built-in auto indenting and whatnot.

...doesn't need to be fancy...Notepad2 does that, select, press Tab to indent block, press Shift+Tab to unindent block...also the way I've configured my Notepad2, it looks exactly like Notepad...I plan on releasing my custom Notepad too as soon as I can...but until then the vanilla Notepad2 is fine...
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group