Skip to content

Instantly share code, notes, and snippets.

@davebrny
Last active March 3, 2024 11:50
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save davebrny/088c48d6678617876b34f53571e92ee6 to your computer and use it in GitHub Desktop.
Save davebrny/088c48d6678617876b34f53571e92ee6 to your computer and use it in GitHub Desktop.
πŸ“‡ (autohotkey) - wrap selected text in *symbols*
/*
[script info]
version = 2.5
description = wrap selected text in %symbols%
author = davebrny
source = https://gist.github.com/davebrny/088c48d6678617876b34f53571e92ee6
*/
sendMode input
return ; end of auto-execute
;---------------------------
!2::
::w2::
goTo, wrap_quote ; "text"
!'::
::w'::
goTo, wrap_apostrophe ; 'text'
!`::
::w``::
goTo, wrap_grave ; `text`
!9::
::w9::
goTo, wrap_parenthesis ; (text)
![::
::w[::
goTo, wrap_bracket ; [text]
!]::
::w]::
goTo, wrap_brace ; {text}
!,::
::w,::
goTo, wrap_angle ; <text>
!5::
::w5::
goTo, wrap_percent ; %text%
!.::
::w.::
goTo, wrap_2_angle ; >>text<<
!8::
::w8::
goTo, wrap_asterisk ; *text*
+!8::
::w*::
goTo, wrap_2_asterisk ; **text**
+!#::
::w~::
goTo, wrap_tilde ; ~~text~~
!-::
::w-::
goTo, wrap_hyphen ; -text-
+!-::
::w_::
goTo, wrap_underscore ; _text_
!k::
::wkbd::
goTo, wrap_kbd ; <kbd>text</kbd>
!del::
::wdel::
goTo, wrap_delete ; _text_ ---> text
;-----------------------
wrap_quote:
wrap_apostrophe:
wrap_grave:
wrap_parenthesis:
wrap_bracket:
wrap_brace:
wrap_angle:
wrap_percent:
wrap_2_angle:
wrap_asterisk:
wrap_2_asterisk:
wrap_tilde:
wrap_hyphen:
wrap_underscore:
wrap_kbd:
this_label := a_thisLabel
clipboard_text := get_clipboard()
for what, with in { "wrap_quote" : """" clipboard_text """"
, "wrap_apostrophe" : "'" clipboard_text "'"
, "wrap_grave" : "``" clipboard_text "``"
, "wrap_parenthesis" : "(" clipboard_text ")"
, "wrap_bracket" : "[" clipboard_text "]"
, "wrap_brace" : "{" clipboard_text "}"
, "wrap_angle" : "<" clipboard_text ">"
, "wrap_percent" : "%" clipboard_text "%"
, "wrap_2_angle" : ">>" clipboard_text "<<"
, "wrap_asterisk" : "*" clipboard_text "*"
, "wrap_2_asterisk" : "**" clipboard_text "**"
, "wrap_tilde" : "~~" clipboard_text "~~"
, "wrap_hyphen" : "-" clipboard_text "-"
, "wrap_underscore" : "_" clipboard_text "_"
, "wrap_kbd" : "<kbd>" clipboard_text "</kbd>" }
stringReplace, this_label, this_label, % what, % with, all
new_text := this_label
goSub, send_wrap
return
wrap_delete:
clipboard_text := get_clipboard()
loop, 2
{
stringLeft, left_character, clipboard_text, 1
stringRight, right_character, clipboard_text, 1
if regExMatch(left_character, "[\Q'%*-_""~``([{><\E]")
and if regExMatch(right_character, "[\Q'%*-_""~)``]}><\E]") ; if '%*-_"~`([{
{
stringTrimLeft, clipboard_text, clipboard_text, 1
stringTrimRight, clipboard_text, clipboard_text, 1
}
else break
}
new_text := clipboard_text
goSub, send_wrap
return
get_clipboard(){
global
if !inStr(a_thisHotkey, ":") ; if hotkey was used
{
revert_clipboard := clipboardAll
clipboard =
send ^{c}
clipWait, 0.3
if clipboard is space
clipboard =
}
return clipboard
}
send_wrap:
if !inStr(a_thisHotkey, ":") and if (clipboard = "") ; if hotkey was used
position := "{Left " round( strLen(new_text) / 2) "}" ; move cursor between symbols
else position := ""
clipboard := new_text
send % "^{v}" . position
sleep 150
clipboard := revert_clipboard
return
@davebrny
Copy link
Author

@jaydeepkarena @adrianff
ive rewritten this script from scratch to make it easier to add and manage different types of wraps. the new script also uses a two stage hotkey so you dont have to worry about conflicts with other hotkeys as much:
https://gist.github.com/davebrny/cd98cb10d4c944b065fda67b707cfd0b

(i didnt add support for hotstrings into the new script though which is why im leaving this script here in case anyone still wants that feature)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment