Code: Select all
{ ;~---------------------------------------------- TEXT --------------------------------------------------
Some code...
}
If I want the line comment above, I just type TEXT on a new line, highlight it and hit the hotkey (AltGR+C) and then it is centered. Since my preferred width of these lines is 106 characters (even number) odd length strings can't be centered. I decided to put odd strings one character to the left of the center.
Here is the script. Hope that someone finds some use for it.
Code: Select all
#Warn ; Enable warnings to assist with detecting common errors.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance,Force ;Only launch 1 instance of this script
{ ;~ ------------------------------------------ FUNCTIONS ------------------------------------------------
; Takes highlighted text and "centers" it (for naming code blocks). If nothing is highlighted, it centers
; whatever is in the Clipboard.
center_func(x){
temp := ClipboardAll ; Saves clipboard, in case highlighted text is not copied
Sleep 100
Send ^c
desired_width := 106 ; How many characters the entire line should be
line_center := desired_width/2
Sleep 100
Clipboard_length := StrLen(Clipboard)
L_side := line_center-Ceil(StrLen(Clipboard)/2)-5 ; Calculates how many "-" to put on left side
R_side := line_center-Floor(StrLen(Clipboard)/2)-1 ; Calculates how many "-" to put on right side
Send, {{} {;}{~} {- %L_side%} %Clipboard% {- %R_side%} ;}
Clipboard := temp ; Restores clipboard
temp := "" ; Free memory (Don't think this is necessary in Ahk)
return
}
highlight_length(){ ; MsgBox with length of highlighted text or length of Clipboard
temp := ClipboardAll
Send, ^c
Sleep 80
high_length := StrLen(Clipboard)
MsgBox, Length of highlighted string = %high_length%.
Clipboard := temp
temp := ""
return
}
}
{ ;~------------------------------------------- HOTKEYS -------------------------------------------------
<^>!c::center_func(Clipboard) ; AltGr + C - Calls function center_func() with inputvariable = Clipboard
<^>!l::highlight_length() ; AltGr + L - Returns a MsgBox with length of highlighted string.
<^>!x::Clipboard:="" ; AltGr + X - Empties Clipboard
}
Code: Select all
{ ;~---------------------------------------------- HELP --------------------------------------------------
{ ;~------------------------------------------- COMMENT 1 ------------------------------------------------
{ ;~----------------------------------------- COMMENT 10000 ----------------------------------------------
{ ;~---------------------------------------- SOME DESCRIPTION --------------------------------------------