Mrrrr
AdMiN
Inregistrat: acum 17 ani
Postari: 2186
|
|
New code by davebrny -
Original code below, I haven't made a personalized one yet. First of all, comment by davebrny on script usage:
txt.wrap wrap selected text in *symbols* using a two-stage hotkey
USAGE
- highlight some text - press alt + w to activate wrap mode - then press any other key to have that character added to either side of the text - to remove characters from both sides, press delete or d - wrap mode will turn off itself after 5 seconds or can be turned off at any time by pressing the esc key
Characters are only deleted on either side if they match and are not alphanumeric, or else if they are in the wrap list
If no text is selected then the wrap characters will be pasted and the cursor will be moved between them
SETTINGS
select_after set to false if you dont want the text to be re-highlighted after its wrapped
input_limit how many characters you want to add in one go. if its set to 2 or more and you are only adding 1 when in wrap mode then the enter key will need to be used to complete the wrap. if its set to 1 then the enter key isnt needed
alternatively, if select_after is enabled then you can get the same effect by doing two wraps one after another such as alt+w+" then alt+w+% to get "%TXT%"
delete_limit if you know you will only ever want to delete 1 character on each side then set this to 1. the default is set to 2 so things like **TXT** and ~~TXT~~ can be deleted in one go
custom wraps new wraps can be added to the ini section at the top of the file. a single character is used for the ini key and the ini value should have TXT in it with whatever characters you want on either side of it
if you are using ; or [ for the ini key then they need to have a literal ` character before them so they are not ignored by the script
if there is more than 1 of the same character in the list then the one the is lower down will be the one thats used. (upper and lower case letters will be seen as different characters though)
WRAP EXAMPLES
characters that normally require the shift key to be pressed
2 = "TXT" 5 = %TXT% 8 = *TXT* 9 = (TXT) - = _TXT_ `[ = {TXT} # = ~~TXT~~ autohotkey
c = /*TXT*/ h = ^!+{TXT} t = trim(TXT) s = inStr(TXT) markdown
b = **TXT** s = ~~TXT~~ B = ```TXT``` l = [TXT](url) p = ![TXT](url) html
i = <i>TXT</i> b = <b>TXT</b> 1 = <h1>TXT</h1> 2 = <h2>TXT</h2> c = <!-- TXT --> k = <kbd>TXT</kbd> i = <img src="TXT"> l = <a href="TXT">text</a> phpBB forum BBCode
b = TXT i = TXT u = TXT q =
c =
l = [list]TXT[/list] m = [img]TXT[/img] u = TXT g = [gist]TXT[/gist] @ = [mention]TXT[/mention] |
AND NOW HERE'S THE CODE, RAW AND UNCUT:
/* [wrap list] ( = (TXT) `[ = [TXT] { = {TXT} < = <TXT> > = >TXT< a = /`*TXT*`/ h = <!-- TXT --> k = <kbd>TXT</kbd> m = ``` TXT ``` p = '''' TXT '''' [settings] select_after = true input_limit = 1 delete_limit = 2 */
#noEnv #singleInstance, force sendMode input
iniRead, select_after, % a_lineFile, settings, select_after iniRead, input_limit, % a_lineFile, settings, input_limit iniRead, delete_limit, % a_lineFile, settings, delete_limit
iniRead, ini_section, % a_lineFile, wrap list ; save wraps to variables sort, ini_section, F long_lines_first_w stringReplace, ini_section, ini_section, % "/``*", % "/*", all ; remove literals stringReplace, ini_section, ini_section, % "*``/", % "*/", all loop, parse, % ini_section, `n, `r { occurrence := (inStr(a_loopField, "=", , 1) = 1) ? ("L2") : ("") ; (if key name is the equals symbol, then L2) stringGetPos, pos, a_loopField, =, % occurrence stringMid, ini_value, a_loopField, pos + 2 stringMid, ini_key, a_loopField, pos, , L ini_key := trim(ini_key) ini_value := trim(ini_value) if (ini_key = "```;") or (ini_key = "``[") ; remove literals stringTrimLeft, ini_key, ini_key, 1 asc := asc(ini_key) ; convert key character to key number %asc% := ini_value wrap_list .= (wrap_list = "" ? "":"`n") . ini_value } ini_section := ""
return ; end of auto-execute ---------------------------------------------------
!w:: goSub, select_wrap !+w::goSub, repeat_last_wrap
select_wrap: toolTip, text wrap . . . repeat_last_wrap: selected := selected_text_w() if (a_thisLabel = "select_wrap") { input, key, L%input_limit% T5, {delete}{d}{enter}{esc} key := (key = "") ? strReplace(errorLevel, "EndKey:", "") : key key := (key = "Escape") ? strReplace(key, "Escape", "") : key asc := asc(key) this_wrap := %asc% ; get wrap stored in key number }
if (key = "delete") or (key = "d") goSub, remove_wrap else if (errorLevel != "Timeout") and if (key != "") { if (this_wrap) split_wrap(this_wrap, l_wrap, r_wrap) else { l_wrap := key r_wrap := key if (strLen(key) > 1) { reversed_string := "" loop, parse, key reversed_string := a_loopField . reversed_string r_wrap := reversed_string } } paste_text_w(l_wrap . selected . r_wrap) } toolTip, ; close return
remove_wrap: new_string := "" loop, parse, % wrap_list, `n, `r ; figure out which wrap is being used { split_wrap(a_loopField, l_wrap, r_wrap) if inStr(selected, l_wrap) and inStr(selected, r_wrap) { l_len := strLen(l_wrap) ; length of characters r_len := strLen(r_wrap) l_string := subStr(selected, 1, l_len) ; take same length from the string r_string := subStr(selected, 1 - r_len, r_len) if (l_wrap = l_string) and (r_wrap = r_string) ; match found on both sides { new_string := subStr(selected, l_len + 1, strLen(selected) - (l_len + r_len)) break } } } if (new_string = "") ; check for matching character on each side { tmp_string := selected loop, % delete_limit { left_char := subStr(tmp_string, 1, 1) right_char := subStr(tmp_string, 0, 1) if (left_char = right_char) and regExMatch(left_char, "[^a-zA-Z0-9]") ; if match and not alphanumeric tmp_string := subStr(tmp_string, 2, strLen(tmp_string) - 2) ; remove both sides else break } if (tmp_string != selected) ; if something changed new_string := tmp_string } if (new_string) paste_text_w(new_string) return
long_lines_first_w(line_a, line_b, offset) { if strLen(line_b) != strLen(line_a) return strLen(line_b) - strLen(line_a) return -offset }
selected_text_w() { global save_clipboard save_clipboard := clipboardAll clipboard := "" send ^{c} clipWait, 0.1 if clipboard is not space return clipboard }
paste_text_w(string) { global clipboard := string send ^{v} sleep 200 if (selected = "") send % "{left " strLen(r_wrap) "}" ; move caret between characters else if (select_after = "true") { if (a_thisLabel = "remove_wrap") ; select whole string send % "{left " strLen(string) "}+{right " strLen(string) "}" else { stringGetPos, pos, string, % selected ; select original selection send % "{left " (strLen(string) - pos) "}+{right " strLen(selected) "}" } } sleep 300 clipboard := save_clipboard }
split_wrap(wrap_text, byRef l_wrap, byRef r_wrap) { stringGetPos, pos, wrap_text, TXT stringMid, l_wrap, wrap_text, pos, , L stringMid, r_wrap, wrap_text, pos + 4 }
/* [script info] version = 0.4 description = wrap selected text in %symbols% author = davebrny source = */ |
_______________________________________
|
|