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 

RegEx Powered Dynamic Hotstrings
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Lexikos



Joined: 17 Oct 2006
Posts: 4471
Location: Qld, Australia

PostPosted: Sun Jan 04, 2009 2:29 am    Post subject: Reply with quote

rjwilmsi wrote:
Regarding your post, I don't understand the bug you mention?
I already said, it prevents hotstrings(k) from removing k from the list of expressions. For example,
Code:
hotstrings("\bann(a|e)" , "Ann%$1%")
; This is supposed to "remove hotstring definition from triggering an action":
hotstrings("\bann(a|e)")

Quote:
Your second change breaks entries like ...
I forgot to replace "$" with "$$" in k and a. For example,
Code:
t := RegExReplace(t, "\n\Q" . k . "\E\r.*?\n|$", "`n" RegExReplace(k,"\$","$$$$") "`r" RegExReplace(a,"\$","$$$$") "`n", _, 1)
Notice that the replacement string is actually "$$", with each doubled up to specify a single literal character.
Quote:
If possible please post back on the problem there and what difference changing that line should make.
Again, I already said what it does: replaces any identical expressions already existing in the list. For instance, without the change, code like the following
Code:
hotstrings("omg" , "oh my god")
Sleep, 5000
hotstrings("omg" , "oh my god{!}")
will result in "omg" being expanded to "oh my god oh my god!" if the script has been running for at least 5 seconds. This is because there are two "omg" entries in the list (but also because of the first issue in the list below.)

Both of these changes are specifically useful for loading hotstring definitions from an external file, and later reloading them or modifying them via a GUI. (Someone Asked for Help with such a script recently.)

While debugging this, I've noticed some other issues:
  • Sometimes the "recognizer" seems to act on what was there, not what it was replaced with. (One could argue that neither should be recognized, but that's not the point.) For instance, if I use hotstrings("\bann(a|e)", "Ann%$1%") and type "anna", it replaces it with "Anna". If I then backspace the "a" and type another "a", or type some other letter then backspace it, "Anna" is replaced with "Anna".
    • I had originally noticed it with "oh my g" being replaced with "oh moh my god" or something similar. After modifying the script, it no longer happens this way for "omg"->"oh my god". Confused
  • This is especially problematic if I click into another window (like Firefox) and start typing then backspace what I typed, as it then deletes part of my text and types "Anna". This is partly a separate issue:
  • Unlike AutoHotkey's hotstring recognizer, hotstrings() does not reset when you click, press arrow keys, home, end, etc. (Clicking and +home,delete are the main problems for me.)
Back to top
View user's profile Send private message Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5043
Location: /b/

PostPosted: Sun Jan 04, 2009 2:59 pm    Post subject: Reply with quote

I committed an update which should have hopefully resolved the issues mentioned. Thanks for the bug reports.
_________________
Chat (IRC) • PlusNet • Scripts • IronAHK • Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
rjwilmsi



Joined: 18 May 2005
Posts: 17

PostPosted: Sun Jan 04, 2009 11:37 pm    Post subject: Reply with quote

Titan wrote:
I committed an update which should have hopefully resolved the issues mentioned. Thanks for the bug reports.

Thanks for the update - it is certainly an improvement. The "isn't" bug I had has now gone too. Also, the main bug I was suffering from was over extra firing of hotkeys, which I believe is the issue Lexikos mentioned.

However, one bug introduced by this update (I'm pretty sure) is that now backspacing of a hotstring doesn't work: e.g. type anna, get it converted to Anna by hotstrings("\bann(a|e)" , "Ann%$1%") rule, but then if backspace is pressed immediately, the character before Anna is deleted rather than the last 'a' in Anna. If the e = line is changed to remove BS this doesn't happen, but does that break other things? Thanks.
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5043
Location: /b/

PostPosted: Mon Jan 05, 2009 1:57 am    Post subject: Reply with quote

Both bugs fixed in v2.53.
_________________
Chat (IRC) • PlusNet • Scripts • IronAHK • Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Krogdor



Joined: 18 Apr 2008
Posts: 1381
Location: The Interwebs

PostPosted: Mon Jan 05, 2009 8:25 am    Post subject: Reply with quote

Thanks, this is great until we get fully implemented dynamic hotstrings!


Just a little modification I made in my own version of the function;
Code:
         StringSplit, x, A_LoopField, `r
         If (RegExMatch(s, x1 . "$", $)) ; match
         {
            StringLen, l, $
            SendInput, {BS %l%}
            If (IsLabel(SubStr(x2, 1, -1)) && SubStr(x2,0) = ":")
               Gosub, % SubStr(x2, 1, -1)
            Else
            {
               Transform, x0, Deref, %x2%
               Send, %x0%
            }
         }

Just makes it so you have to put a colon ( : ) after a label name if you want it to go to a label instead of replace the text; simply makes it a bit harder to accidentally go to a label instead of replacing the text...

Edit: Fixed with updated code.


Last edited by Krogdor on Mon Jan 05, 2009 8:53 am; edited 1 time in total
Back to top
View user's profile Send private message AIM Address
Lexikos



Joined: 17 Oct 2006
Posts: 4471
Location: Qld, Australia

PostPosted: Mon Jan 05, 2009 8:31 am    Post subject: Reply with quote

Thanks Titan. [Edit: However, I suppose you assumed avoiding RegExReplace would be more efficient, without having actually benchmarked it. With my sample text, the method which I had been using benchmarked 327% faster for removing, and 54% faster for replacing:
Code:
    Else If a =
        t := RegExReplace(t, "\n\Q" . k . "\E\r.*?\n")
    Else If k !=
        t := RegExReplace(t, "\n\Q" . k . "\E\r.*?\n|$", "`n" RegExReplace(k,"\$","$$$$") "`r" RegExReplace(a,"\$","$$$$") "`n", _, 1)
Or maybe you just felt like rewriting it the long way. Razz
End edit.]

Krogdor, it isn't possible for a label name to end with ":", therefore (IsLabel(x2) && SubStr(x2,0) = ":") will always evaluate to false. I suggest:
Code:
if (SubStr(x2,0)=":" && IsLabel(SubStr(x2,1,-1)))


Last edited by Lexikos on Mon Jan 05, 2009 9:00 am; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
Krogdor



Joined: 18 Apr 2008
Posts: 1381
Location: The Interwebs

PostPosted: Mon Jan 05, 2009 8:52 am    Post subject: Reply with quote

Yeah, sorry about that Lexikos—I wasn't at the computer with my script so I was just going off of what I remembered. That would be the correct way to implement it.
Back to top
View user's profile Send private message AIM Address
Titan



Joined: 11 Aug 2004
Posts: 5043
Location: /b/

PostPosted: Mon Jan 05, 2009 2:06 pm    Post subject: Reply with quote

Krogdor wrote:
Just makes it so you have to put a colon ( : ) after a label name if you want it to go to a label instead of replace the text
I like the idea, but I'll keep it as it is now for the sake of compatibility.

Lexikos wrote:
I suppose you assumed avoiding RegExReplace would be more efficient, without having actually benchmarked it.
I had a tough time with the GC on Mono so I was actually concerned with the memory usage of:

RegExMatch Performance wrote:
To improve performance, the 100 most recently used regular expressions are kept cached in memory (in compiled form).

I haven't benchmarked this either so I can't be certain. Either way I should hope a parsing loop is more newb friendly which is a good enough reason to keep it.
_________________
Chat (IRC) • PlusNet • Scripts • IronAHK • Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
rjwilmsi



Joined: 18 May 2005
Posts: 17

PostPosted: Mon Jan 05, 2009 8:20 pm    Post subject: Reply with quote

Thanks to all for the continued work on this script. I have a bug with the latest version of the script to report. I believe Lexikos may have already mentioned this, but here goes:
Code:
hotstrings("(A|a)quir" , "%$1%cquir") ; acquire

using the above hotstring if 'aquir' is typed this is autoreplaced to 'acquir'. All correct so far, but if you then press backspace and 'r' another 'a' is added to the front of the word. This can be continued multiple times. I believe this is a problem for any hotstrings where the replace is longer than the find.

If the line with 'e = BS' is changed to remove 'BS' this goes away, but then this removes the fact that the function can work on user-corrected words.
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5043
Location: /b/

PostPosted: Mon Jan 05, 2009 9:14 pm    Post subject: Reply with quote

Thanks for the report. Fixed in v2.54.
_________________
Chat (IRC) • PlusNet • Scripts • IronAHK • Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
indeez
Guest





PostPosted: Thu Mar 19, 2009 8:37 pm    Post subject: Reply with quote

First if all, many thanx for your script!

Possibly you'd find it interesting: I'd had modified it a little bit in order to catch the numpad keys. I had to correct IP addresses because in my native keyboard layout there's a comma `,' on the numpad Del and often IP addresses were typed as 1,2,3,4

So here's the trivial addition to your script (suppose diff-form suits you)
Code:
--- Hotstrings.ahk-orig   Thu Mar 19 19:43:12 2009
+++ Hotstrings.ahk   Thu Mar 19 21:57:20 2009
@@ -33,7 +33,7 @@
          If A_Index not between 33 and 58
             Hotkey, %m%%c%, __hs
       }
-      e = BS|Space|Enter|Return|Tab
+      e = BS|Space|Enter|Return|Tab|Numpad0|Numpad1|Numpad2|Numpad3|Numpad4|Numpad5|Numpad6|Numpad7|Numpad8|Numpad9|NumpadDot|NumpadDel
       Loop, Parse, e, |
          Hotkey, %m%%A_LoopField%, __hs
       z = 1
@@ -54,6 +54,28 @@
             q := "`t"
          Else If q in Enter,Return
             q := "`n"
+         Else If q = Numpad0
+            q := "0"
+         Else If q = Numpad1
+            q := "1"
+         Else If q = Numpad2
+            q := "2"
+         Else If q = Numpad3
+            q := "3"
+         Else If q = Numpad4
+            q := "4"
+         Else If q = Numpad5
+            q := "5"
+         Else If q = Numpad6
+            q := "6"
+         Else If q = Numpad7
+            q := "7"
+         Else If q = Numpad8
+            q := "8"
+         Else If q = Numpad9
+            q := "9"
+         Else If q in NumpadDot,NumpadDel
+            q := ","
          Else If (StrLen(q) != 1)
             q = {%q%}
          Else If (GetKeyState("Shift") or GetKeyState("CapsLock", "T"))

After than the code
Quote:
hotstrings("(\d+)[^\d\s.](\d+)[^\d\s.](\d+)[^\d\s.](\d+)", "%$1%.%$2%.%$3%.%$4%")
works quite as expected

Thank you once more for that great script!
Back to top
programmable



Joined: 02 May 2008
Posts: 8

PostPosted: Thu Jul 02, 2009 9:27 pm    Post subject: Reply with quote

This script works just fine for me, until I start using cut/paste.

Code:

hotstrings("(abcdefg)", "showHotstr")
Return

showHotstr:
msg := $1
MsgBox %msg%
Return


It works fine if i type
Quote:
abcdefg

However, it fails if I cut/paste any part of the "abcdefg" string.

Any thoughts?
Back to top
View user's profile Send private message Send e-mail
MasterFocus



Joined: 08 Apr 2009
Posts: 1037
Location: Rio de Janeiro - RJ - Brasil

PostPosted: Thu Sep 03, 2009 3:16 am    Post subject: Reply with quote

Just to inform, the link is broken.
Hotstrings.ahk is currently located HERE.
_________________
Antonio Franηa
+ My AHK Stuff: Google Profile
+ AHK @ irc.freenode.net: #ahk
Wanna contact me? Send a PM.
Back to top
View user's profile Send private message Visit poster's website
HotKeyIt



Joined: 18 Jun 2008
Posts: 2198
Location: GERMANY

PostPosted: Thu Sep 03, 2009 6:13 pm    Post subject: Reply with quote

Here is a small fix because some hotkeys are not being created, for example:
Code:
hotstrings("(\d\d?)\;(\d\d?)", "%$1%:%$2%")
Code:
If A_Index not between 33 and 58 ;should be 64 I think

_________________
AutoHotFile - ToolTip(n,text,title,options) Wink
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3
Page 3 of 3

 
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