hotstring to turn Mr into Mr. and Mrs into Mrs - autohotkey

Microsoft Word red-flags my Mr and wants to change it to Mr. and Mrs. every time. Since I have gotten used to typing Mr and Mrs, I want to use Autohotkey to change it automatically as I type...
Right now, I have:
:c*:Mrs::Mrs.
:c*:Mr::Mr.
But as you can probably guess, when I type Mrs it changes to Mr.S because of the Mr command, and the Mrs command is never called
Is it possible for me to get it to type Mrs. when I type Mrs, and Mr. when I type Mr?

Reading the docs on Hotstrings and comparing your code I see that you have * option which is triggering your hotstring immediately, this removes the need for a End Character (default is space, enter, tab) to trigger the hotstring replacement. To correct this behavior simply remove the *
:c:Mrs::Mrs.
:c:Mr::Mr.

Like ahkcoder, but I would have used an extra space and replaced the space with an asterisk.
:*:mr ::Mr. `
:*:mrs ::Mrs. `
By not using :c:, this makes it case independent.
Within Word, you could have used auto correct as well.

Related

How to remap Tab key to two dots/period key presses

I want to map two dot/period key presses to Tab key in AutoHotkey script. I tried to map similarly as its shown for remapping semicolon key - on AutoHotkey forums, but it doesn't work. I tried following:
1. `..`::Tab
2. ..::Tab
AutoHotkey gives an error
.
I tried searching on AutoHotkey Remap docs, but couldn't figure it out. The period key is the one with the greater than mark and not the number keypad period key. See this: Dot/period key
Addition info/context in response to reply by user 0x464e:
Basically, I am trying to expand Emmet style abbreviations in devtools style sub-panel since the chrome devtools team wont implement it.
I am not a fast typist, so it's a pain to type complete property names. For example, if I want to type margin-top, (see the image), Chrome autocomplete brings up margin, margin-block margin-block-end etc.
Now, for margin-top, you need to at least type margin-t to get the autocomplete to show that property.
This is the case for many very common CSS properties like margins, paddings, etc., so autocomplete isn't great.
On the other hand, if I just type mt and have Autohotkey expand to margin-top, it's much much faster, saves me much time and keeps me sane.
Basically, I have setup some hotstring in .ahk script and they work too.
However, if I press mt followed by a Tab key press, Chrome's autocomplete takes over and hotstring fails, (try once to see the problem). Instead, currently I press spacebar, or . (period) to trigger the hotstring. It works, but the problem is it leaves a space or a dot with the expanded text. [see this].
So, that's the actual reason I wanted a double period key trigger to replace Tab.
It would be great if the hotstring trigger would work with a double period key, but doesn't leave the trigger character itself and then have send Tab so as to jump to the value input of the just expanded property.
You're not really looking for a traditional remap, which is why you didn't find it from the documentation.
Remapping is just simply remapping one key to another, but you're not trying to do that. You're trying to make some action do another action.
Anyway, what you're asking is doable, but there's loads of different ways it can be achieved with difficulties varying from simple to extremely advanced & complicated.
You'll need to specify things more clearly before this can be answered properly.
Biggest questions that pop into my head right away are at least:
Should this work everywhere, or just in text input fields?
How should the original functionality of . be preserved, if at all.
(What should happen after the initial . keypress?)
Should there be some timeout between the keypresses?
Etc, this is just what I could think of right away, but surely there's more.
Anyway, for now I can give a simple implementation with a hotstring:
:*?:..::{Tab}
So this is a hotstring with the * and ? options.
I'm guessing these would probably be pretty good options for this.
So what this does, is it presses backspace twice and sends a Tab if you type ...
This should be fine for text editors, but it leaves much to be desired (the points I listed above aren't considered since I can't know what you're looking for. This is just what a default simple hotstring can offer).
Looks to me like you don't actually want the additional mapping of .. to Tab, but instead just want to update your existing hotstrings to activate immediately (without waiting for an EndChar) when the hotstring is followed by ..
Normally, you might look to the Ending Characters option to create this functionality, but since you want multiple characters to trigger this, we need to look to other options.
I will be using the example of ::mt::margin-top for my sample implementation. Extend any changes I make to these to the rest of your hotstrings in the script you screenshotted.
Here are the changes I am making to this example:
Add your .. to the end of each of your hotstrings triggers. For example ::mt::margin-top becomes ::mt..::margin-top. However, at this present, this still requires some sort of ending character to be pressed in order to proc. Let's fix that in the next step
Add the Asterisk Modifier to the hotstring. From the docs:
* (asterisk): An ending character (e.g. Space, ., or Enter) is not required to trigger the hotstring.
Final code for ::mt::margin-top example:
:*:mt..::margin-top
And extend this * insertion and .. appendation to each of your hotstrings.
Hope this helped! Lmk if you need any more help or changes.

AutoHotkey send without replacement

I'm using AutoHotkey. Is there a way of using "Send" without getting the previously wirtten Hotstring replaced?
So if I want to use the Hotkey System it always overrides the System with the text I set after "Send". But how can I achive that it is just appending my Send text to the hotstring?
Send, Hotstring Rest of Things You Want to Say
I think you may be mistaken in what you're trying to say or how you're using Send, as it doesn't replace previously written hotstrings. If you post an example of what you're saying, it will be easier to help. Also, what do you mean when you say "Hotkey System"?
Helpful info from the online documentation, Hotkeys & Hotstrings.
EDIT (per your comment below):
I understand what you're saying now. This is the default way that hotstrings work and has nothing to do with using the Send command. If you want to keep the activating text in a hotstring, you need to use the B0 option. Something like this:
:*B0:System::.out.println()
Note that the * makes it so you don't need to type a period after "system". If you want it to work that way instead, remove the asterisk.

Why do hotstrings act unexpectedly?

I have to test cases:
Case 1
#Include test1.ahk
::se::Stack Exchange `{backspace}
(test1.ahk is empty) then typing:
se␣ (with a space at the end) → Stack Exchange (no space at the end)
use␣ → uStack Exchange
But let say I delete the ␣{backspace} at the end or change it to
::se::Stack Exchange `{backspace}
::de::define
then it works normally again.
Case 2
#Include test1.ahk
::se::Stack Exchange
works fine, but
#IfWinActive, ahk_class SunAwtFrame
return
::se::Stack Exchange
makes se→se, i.e. nothing happens.
This is very weird, because there's nothing seems to be wrong. I can't even quarantine it, and updating AHK to the latest version or reinstalling it doesn't help. All I know is that when it happens any hotstring will behave this way. The problem started when I included this script, but even when I've exclude it this still happens. The script itself doesn't seem anything wrong too.
Also ask on Reddit.
Preventing expansion of se to trigger when you type use, is one of the reasons why I end my text expansion strings with a special character. As I maintain text expansion for three languages, I have settled on the following scheme.
text\ is the default (Dutch)
text= is used for English
text] is used for German
I also use the . in some cases to expand abbreviations.
I chose the \, = and ] signs, because they are all close to the Enter key.
Example:
Dutch:
:*:adhv\::aan de hand van
:*:bv\::bijvoorbeeld
English:
:*:am=::Account Management
:*:actm=::Active Monitoring
:*:appr=::approach
:*:art=::article
:*:ba=::business alignment
German:
:*:nrw]::Nordrhein-Westfalen
:*:ma]::Mitarbeiter
:*:fk]::Führungskräfte
Dots:
:*:adhv.::a.d.h.v.
:*:dmv.::d.m.v.
:*:ovv.::o.v.v.
As you can see, I can write adhv either with a . at the end or with a \ and they expand differently.
The * is used to overwrite the default ending characters like {Space}.

How to use a phrase as HotString in AutoHotkey - including spaces in HotString

Is there a way to include a space in the HotString and still have the space trigger the HotString replacement? For example:
::_u_::_you_ <--where the underscores are actually space chars
or
:*:_fo_r::_for_ <--where the underscores are actually space chars
so if I typed
StackOverflow is a great place fo ranswers!
it would be changed to
StackOverflow is a great place for answers!
I'm looking for a way to define a phrase as the hotstring really.
Strange. I tried escaping with `s but that didn't work. The docs say two things:
To send an extra space or tab after a replacement, include the space or tab at the end of the replacement but make the last character an accent/backtick (`). For example:
:*:btw::By the way `
and
Spaces and tabs are treated literally within hotstring definitions. For example, the following would produce two different results: ::btw::by the way and ::btw:: by the way
So, I would think this should work:
:*: fo r:: for `
That works in notepad, but only if I try it at the start of a line. Mid-sentence it fails.
You may be forced to use one of the user-created dynamic regex hotstring libraries.
Using this library, this works:
#include Hotstring.ahk
Hotstring(" fo r", " for ")
edit:
I asked on the AHK forums, and the ? option should do it:
:*?: fo r:: for `
This will work.
:*: fo r::
SetKeyDelay, -1
Send for{space}
return

How can I modify emacs' Search and Replace to perform a more complicated task?

total Emacs noob here. So right now I'm working on a fairly big LaTeX project in Emacs in which there are couple of places where I need to index some words, using the makeidx package. Because I also wanted indexed words to be bold, I created my own command \ind{} which would make the argument go bold and indexed. But right now I'm dissatisifed with this command so I'd like to change every instance of \ind{whatever} in my text by \textbf{whatever}\index{whatever by default}.
The thing is I know exactly what I want :
Go through the text, look for any instance of \ind{ and replace by \textbf{ using search-and-replace
Save the argument of \ind ("whatever" in this case) in memory
Ask me the user what should the argument of \index be. By default (by striking enter), it should be the first argument, but I can also change my mind and enter something different ("whatever by default" in this case). If there's no input (only a space " " for example) stop the program.
Write down \index{, the new argument and }.
Go to next occurance in the text.
But, alas!, I know not how to achieve this, so I need someone's help. If it should take too much time to explain how to do such a thing, would you please send me some tutorial about writing my own functions?
I hope I'm being clear, and thanks for your patience!
This approach seems vaguely unorthodox to me, but it works and seems sufficient for a one-off job...
In the replacement text for replace-regexp and query-replace-regexp (C-M-%), one newer escape sequence is \,(...), where ... can be any Lisp expression. There's a Lisp function read-from-minibuffer which reads arbitrary text typed by the user, with an optional default. Therefore:
C-M-%: Start query-replace-regexp.
\\ind{\([^}]+?\)}: The pattern to search for.
\\textbf{\1}\\index{\,(read-from-minibuffer "index content? " \1)}: The replacement text. The user will be prompted for the text to put in the braces following the \index{} element, using the original text between the braces following the \ind{} element as a default.
Note that when using query-replace-regexp, you'll have to confirm each choice by typing y after each. Use M-x replace-regexp if you want to avoid this step.
Vlad give you the LaTeX answer to your problem. An Emacs solution is the key-macro: start with
C-x (
to define a new macro, then do one step of your change, say:
C-s \ind{
<left>ex
Then copy and paste the argument in the \textbf macro... You have to be careful to move in a way that will be repeatable. Once the standard modification is done, you let the cursor after the whatever by default and end the definition by
C-x )
now C-x e will call the macro you just define, letting your cursor at the correct place to change the part you want to change You can also repeat the e to call the macro several time at once.
Why not just redefine the \ind so that it can get an optional argument?
For example:
\newcommand{\ind}[2][]{%
\def\first{#1}%
\ifx\first\empty
\textbf{#2}\index{#2}%
\else
\textbf{#2}\index{#1}%
\fi
}
This way you can use \ind{whatever} or \ind[whatever-else]{whatever}.