AutoHotkey Community

It is currently May 27th, 2012, 1:22 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: August 24th, 2008, 11:22 pm 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3330
Location: Simi Valley, CA
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
}

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
PostPosted: August 25th, 2008, 10:19 am 
[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...


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Bon and 12 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group