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 

REAL Wildcard Hotstring Option
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
[¤GoO¤]



Joined: 22 Feb 2005
Posts: 60
Location: Sweden

PostPosted: Fri Nov 25, 2005 3:39 pm    Post subject: REAL Wildcard Hotstring Option Reply with quote

Hi Chris!

I would like to see a a new option in hotstrings. An example: ("&" represents my requested option character)
The hotstring:
Code:
:<&>::</&>


This should produce something like
Code:
</htmltag>
out of
Code:
<htmltag>


Do you understand what I mean? I would like AHK to replace the < and > (for example) regardless of what has been written between.

Maybe that is too complicated to accomplish, or someone is going to say that I'm lazy. Razz

Thanks!
_________________
"Make everything as simple as possible, but not simpler."
- Albert Einstein (1879-1955)
Back to top
View user's profile Send private message Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5041
Location: imaginationland

PostPosted: Fri Nov 25, 2005 5:40 pm    Post subject: Reply with quote

I would also like this feature added.
If the wildcard feature is made, it would be great to extend it for capabilities like StringGetPos and other commands.
Back to top
View user's profile Send private message Visit poster's website
Nemroth



Joined: 07 Sep 2004
Posts: 262
Location: France

PostPosted: Sat Nov 26, 2005 10:20 am    Post subject: Reply with quote

I think the idea is very good but need a little change in its implementation, because hotstrings can execute a script. They are not used only for text replacement, and I think that your notation proposal limits the hotstring to string replacement.

What do you think about :
Code:
:&:<&>::
   Send, </A_HSContent>
return

The '&' option character says that in the hotstring, the character preceding the '&' character is the starting character and the character after is the terminating character (you need it with the '*' option).
Between them, the '&' character "replace" one or more character(s).
In A_HSContent, you will find the character(s) witch was typed between the starting and the ending character (< and > in this case)

And I think that this notation would allow one or more starting and/or ending character(s) :
Code:
:&:</&>::
   Send, <A_HSContent>
return

You can have an complementary/alternative notation :
Code:
:&:"&11::
   Send, "A_HSContent"
return

In this case, after the second '&' character, you will have the number of character(s) to be typed before the hotstring executes the script content, so you don't have any terminating character. In this example, the starting character is " and after the user have typed 11 characters, the hotstring is executed.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4001
Location: Pittsburgh

PostPosted: Sat Nov 26, 2005 6:21 pm    Post subject: Reply with quote

Your examples can be solved with just replacing "<" with "</". If you mean, that a ">" should follow within some 10 characters (otherwise the "<" was not a tag start), things get complicated. AHK cannot wait forever for a terminating ">". What happens if you press arrow keys, click your mouse or change the active window?
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4001
Location: Pittsburgh

PostPosted: Sat Nov 26, 2005 6:44 pm    Post subject: Reply with quote

Here is a simple workaround in 11 lines.
Code:
$$<::
   Send {<}
   Loop 10
   {
      Input ch, I L1 M V, {TAB}{Esc}{BS}{Enter}{LControl}{RControl}{LAlt}{RAlt}{LWin}{RWin}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}
      IfNotEqual ErrorLevel, Max, Return  ; non-letter key pressed
      IfNotEqual ch, >, Continue
      Send {Left %A_index%}/{Right %A_index%}
      Return
   }
Return
Back to top
View user's profile Send private message
Nemroth



Joined: 07 Sep 2004
Posts: 262
Location: France

PostPosted: Sat Nov 26, 2005 7:45 pm    Post subject: Reply with quote

Of course you can allways do the things that the hotstrings do by the use of the Input command.
That brings us to the first ages of AHK. There was people who said "why hotstrings ?, There is Input witch can do the job..."
The utility of the hotstrings in the core of AHK is (with other things) the simplicity of use.
Laszlo wrote:
What happens if you press arrow keys, click your mouse or change the active window?
There could be an option to avoid that, or in the code of the hotstring (if any), you can use BlockInput, send the text, with ^v, using the Shimanov's Buffered Send and SendRaw, and so on...
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4001
Location: Pittsburgh

PostPosted: Sat Nov 26, 2005 8:51 pm    Post subject: Reply with quote

This is why I called it workaround, not a solution. Still, if you can do something with 8 extra lines of code, making it a built-in feature might not be of very high priority.

The script I posted should be used as a vehicle of experiment. Add checking for mouse clicks, change of active window, blockinput, or whatever you think is important, and request the complete solution as a new AHK feature. It helps Chris since you already investigated the important features, special cases. For example, you could get the desired A_HSContent variable with a 15-line script, and test if this is what you really want.
Code:
$<::
   A_HSContent =
   Send {<}
   Loop 10
   {
      Input ch, I L1 M V, {TAB}{Esc}{BS}{Enter}{LControl}{RControl}{LAlt}{RAlt}{LWin}{RWin}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}
      IfNotEqual ErrorLevel, Max, Break   ; non-letter key pressed
      IfEqual ch, >, {
         Send {Left %A_index%}/{Right %A_index%} ; ...or do whatever you want with A_HSContent
         Return
      }
      A_HSContent = %A_HSContent%%ch%
   }
   A_HSContent =
Return

The following is a little cleaner script, as it separates the search for tags from the actions you take with them.
Code:
$<::
   A_HScontent =
   Send {<}
   Loop 10
   {
      Input ch, I L1 M V, {TAB}{Esc}{BS}{Enter}{LControl}{RControl}{LAlt}{RAlt}{LWin}{RWin}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}
      IfNotEqual ErrorLevel, Max, Break   ; non-letter key pressed
      IfEqual ch, >, GoTo FoundTag
      A_HScontent = %A_HScontent%%ch%
   }
   A_HScontent =
Return

FoundTag:   ; do whatever you want with A_HScontent
   $len := StrLen(A_HScontent)+1
   Send {Left %$len%}/{Right %$len%}
Return
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Sat Nov 26, 2005 10:06 pm    Post subject: Reply with quote

The original wish is a good one but I have trouble imagine uses for it beyond writing HTML tags by hand. Can anyone think of other common uses?

If there aren't many others, it might be difficult to justify it on a cost vs. benefit basis. This is not to say that general wildcard support won't ever get added, because that is still planned.

Thanks for the idea.
Back to top
View user's profile Send private message Send e-mail
Laszlo



Joined: 14 Feb 2005
Posts: 4001
Location: Pittsburgh

PostPosted: Sat Nov 26, 2005 11:56 pm    Post subject: Reply with quote

Actually, what is more useful (and probably the original wish meant) is not to change the tag, but to send its closing pair automatically. That is, if you type <tag> the script writes the closing </tag> and moves the cursor in between: <tag>|</tag>. It needs just a trivial change in my last script:
Code:
$<::
   A_HScontent =
   Send {<}
   Loop 10
   {
      Input ch, I L1 M V, {TAB}{Esc}{BS}{Enter}{LControl}{RControl}{LAlt}{RAlt}{LWin}{RWin} {F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}
      IfNotEqual ErrorLevel, Max, Break   ; non-letter key pressed
      IfEqual ch, >, GoTo FoundTag
      A_HScontent = %A_HScontent%%ch%
   }
   A_HScontent =
Return

FoundTag:   ; do whatever you want with A_HScontent
   $len := StrLen(A_HScontent)+3
   Send </%A_HScontent%>{Left %$len%}
Return
It is really useful if you write HTML.
Back to top
View user's profile Send private message
Guest






PostPosted: Sun Nov 27, 2005 12:34 am    Post subject: Reply with quote

Cool

Is there any way to make it skip certain tags, those that don't need a closing tag, like br or p?
Back to top
Laszlo



Joined: 14 Feb 2005
Posts: 4001
Location: Pittsburgh

PostPosted: Sun Nov 27, 2005 1:21 am    Post subject: Reply with quote

Yes. Look here.
Back to top
View user's profile Send private message
kapege.de



Joined: 07 Feb 2005
Posts: 186
Location: Munich, Germany

PostPosted: Mon Nov 28, 2005 9:18 am    Post subject: Reply with quote

Anonymous wrote:
Is there any way to make it skip certain tags, those that don't need a closing tag, like br or p?

For a clean programming it's strongly recommended to type a </p> also. Further allowed is this construct: <br>NoContent</br>
[wisenheimer mode off] Very Happy
_________________
Peter

Wisenheiming for beginners: KaPeGe (German only, sorry)
Back to top
View user's profile Send private message Visit poster's website
kapege.de



Joined: 07 Feb 2005
Posts: 186
Location: Munich, Germany

PostPosted: Mon Nov 28, 2005 2:09 pm    Post subject: Reply with quote

And for the poor with Win 98:
Code:
$>::
   SetTitleMatchMode, 2
   WinGetActiveTitle, exp
   ifInString, exp, EditPlus ; or what your favourite editor ever may be
   {
      SetKeyDelay, 0
      send, +{home}
      send, {Ctrl Down}c{CTRLUP}{right}
      IfNotInString, clipboard,<
      {
         send, >
         return
      }
      StringSplit, abc, clipboard,<
      ghi = ></%abc2%>
      j := StrLen(abc2) + 3
      send, %ghi%{left %j%}
   }
   else
      send, >
return

Edit: V2 Very Happy
_________________
Peter

Wisenheiming for beginners: KaPeGe (German only, sorry)
Back to top
View user's profile Send private message Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4001
Location: Pittsburgh

PostPosted: Mon Nov 28, 2005 6:38 pm    Post subject: Reply with quote

If your editor supports Shift-Ctrl-Left (or some other keys) to select the last word you typed, it would allow simplifying Peter's script.
Code:
SetTitleMatchMode, 2
~$>::
   IfWinNotActive Multi-Edit ; put here part of the window title of your editor
      Return
   Send ^+{Left}+{Left}^c    ; adjust to fit your editor: select word left, with leading "<"
   Send % "{Right " StrLen(ClipBoard) "}"
   IfInString ClipBoard, <
      Send % ClipBoard "{Left " StrLen(ClipBoard)-1 "}/{Left 2}"
Return
The price for the simplicity is that the script is not universal: only works in certain editors. Also, when using the clipboard you probably want to save its content beforehand into an AHK variable, and restore it at the end. On slow PC's you might need to empty the clipboard before sending ^c, and "ClipWait 1" before continuing, to make sure the selection has arrived at the clipboard.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4001
Location: Pittsburgh

PostPosted: Thu Dec 29, 2005 10:12 pm    Post subject: Reply with quote

Guest wrote:
Where can I obtain more information about "replacing"?

Your editor (or browser) screwed up the original characters. There were "less-than" (shifted comma) characters in the post. You could change it back in notepad, by replacing &lt; with the less-than character (<). What the original post meant, was that the examples were not wisely chosen. Replacing an html tag with its closing pair is trivially done by just inserting a slash (/) after the starting less-than character. A hotkey can do it
Code:
$<::Send </
or a hotstring
Code:
:*:<::</
Read more about it in the Help under "hotkey basics" or "Hotstrings and Auto-replace".
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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