AutoHotkey Community

It is currently May 27th, 2012, 5:24 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: November 25th, 2005, 3:39 pm 
Offline

Joined: February 22nd, 2005, 7:42 pm
Posts: 60
Location: Sweden
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. :P

Thanks!

_________________
"Make everything as simple as possible, but not simpler."
- Albert Einstein (1879-1955)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 25th, 2005, 5:40 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2005, 10:20 am 
Offline

Joined: September 7th, 2004, 9:20 pm
Posts: 275
Location: France
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2005, 6:21 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2005, 6:44 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2005, 7:45 pm 
Offline

Joined: September 7th, 2004, 9:20 pm
Posts: 275
Location: France
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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2005, 8:51 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2005, 10:06 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2005, 11:56 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2005, 12:34 am 
8)

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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2005, 1:21 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Yes. Look here.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2005, 9:18 am 
Offline

Joined: February 7th, 2005, 11:11 am
Posts: 192
Location: Munich, Germany
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] :D

_________________
Peter

Wisenheiming for beginners: KaPeGe (German only, sorry)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2005, 2:09 pm 
Offline

Joined: February 7th, 2005, 11:11 am
Posts: 192
Location: Munich, Germany
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 :D

_________________
Peter

Wisenheiming for beginners: KaPeGe (German only, sorry)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2005, 6:38 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2005, 10:12 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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".


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group