OLV Basiliek Zwolle

Main Menu

  • Home
  • Browser list
  • Browser software
  • Browser types
  • Browser news

OLV Basiliek Zwolle

OLV Basiliek Zwolle

  • Home
  • Browser list
  • Browser software
  • Browser types
  • Browser news
Browser list
Home›Browser list›Linux Fu: the Emacs Fusion browser

Linux Fu: the Emacs Fusion browser

By Ronnie A. Huntsman
July 6, 2022
0
0

It’s no secret that I have a few items permanently etched in my neurons: the 1802 instruction set, the commands for WordStar, and the commands for emacs. There was a time when emacs was almost my operating system. Without X11, emacs gave you a way to have a shell in a window, check your mail, and keep your work open.

I still use emacs a lot (although I’m more and more happy with vscode with an emacs hotkey extension). But I also spend a lot of time — like right now — writing in a web browser. Especially if I’m writing about code it gets hard to remember which keyset you should use and I’ve wanted to do something about this for a long time. The answer is a very cool program called Autokey. (You can download my files for this, but you’ll probably want to read more first.) This probably won’t work if you’ve switched to Wayland, but it can do a lot for you, from saving you typing work to reprogramming your favorite program to have different keystrokes. However, it’s not without its problems, and I’ll tell you what I know about it.

The value proposition

Autokey sits in your system tray and monitors what you type. In its simplest use, you can set up different phrases to replace what you type.

For example, I could reprogram HaD to appear as Hackaday to save me typing work. I usually use a weird character at the start or end so I don’t accidentally trigger things. So maybe I’m tired of typing or mistyping http://www.hackaday.com. I could set up ~had to automatically type in the correct URL for me.

Scripts vs. Phrases

If that’s all AutoKey has done, that would be pretty handy. But it does much more than that. On the other hand, if that’s all you want, it’s easy to set it up using phrases. A phrase has two parts: a trigger and text. The trigger can be a keyboard shortcut (like Alt+Shift+F6) or it can be text you type like ~had. It is possible to add multiple abbreviations, so I could have additional triggers from had~ and http://www.hakday.com if I wanted the program to automatically correct my spelling mistake.

Autokey is easy to configure for simple text replacement, but can also support complex Python scripting

A phrase can only have one hotkey, but you can have hotkey and abbreviations; either will trigger the phrase. Of course, you can also support multiple hotkeys with multiple identical entries. Finally, you can limit the match to a particular window class associated with a regular expression. So it’s possible to have one set of shortcuts for your word processor and another set for your web browser.

The real power, however, is that you can script In place of sentences. They are exactly the same except instead of typing a sentence, a piece of Python code runs. There are some classes to help you do things like control the keyboard and mouse from a script. You can even create GUI dialogs using QT or GTK. However, I found that there is a slight downside to using scripts, but for many things they work just fine. You’ll see what I mean in a moment.

In addition to scripts, sentences can have some dynamic content like date, file or even program output. There are also provisions to position the cursor at a certain place after entering text, which is useful for creating code snippets.

Power abbreviations

There are many options for dealing with abbreviation triggers

There are a few useful options you can apply to abbreviations. For one, you can control how they send text to the target program. I usually use the keyboard method to simulate typing because I will be using special characters, but you can also paste the text using one of many common shortcuts. That is, the program can load the clipboard with your phrase, then paste it with a control + V.

The real power comes when you configure the abbreviations. A dialog allows you to select a list of trigger words and you can set options. By default, the abbreviation will not expand until you type a non-verbal character. You can also require a space or a tab. However, there are other options. For example, you can have Autokey trigger immediately or even if the text is part of another word. There are options to ignore or match case, among other things.

Window classes

The last thing you can use to control trigger logic is to restrict a script or phrase to a window class that matches a regular expression. That’s fine because you probably don’t want to map weird stuff to all windows. Of course, it’s handy to have !address enter your mailing address in each program, but if you want to do main develop a boilerplate core function, you might not like that happening in LibreOffice.

In my case the window class functionality was quite important as I didn’t want to remap things like control+s in every program, just the browser.

All together

So how do you put all this together to emulate emacs? Most of the commands are very simple. For example, in emacs, control+s launches a search, so all you have to do is create a phase with this shortcut which types: +f that the browser knows is a search. Obviously, you can’t easily do things that the browser doesn’t already know how to do. Control+r for reverse lookup, for example, is not possible. I ended up mapping just over a dozen basic emacs commands this way. I disabled the control+w keyboard shortcut to make a copy of the clipboard because the browser uses it to close a tab, and I didn’t want to block it.

I used the built-in tool to find the Vivaldi browser class I’m using. I would later discover that I needed to make a change in this area, as you will see.

For now, this has taken care of one-touch controls. However, there are also two-character commands. I had a plan, but that plan didn’t work out very well. For now, I just live without them, but I’ve left a disabled example in the code for your review.

Since you can run a script and there is a global variable storage mechanism for scripts, my plan was simple. Consider control+xu which is emacsese for undo. You can’t use an unprintable character in an abbreviation, so you have to handle the situation with just one keyboard shortcut. My plan was to set control + x to enable a prefix flag in the script’s global storage. Then I could use Autokey to treat you like a hotkey – just the letter u – and send au or a control+z, depending on the state of the flag. Coincidentally, the code would also reset the flag.

Problems

There are issues with this even though everything worked fine, which it didn’t. For example, if you pressed control + x and then an unexpected key, the flag stays set and the next time Autokey sees au, you’ll get an undo. It would surprise you! Seems like the right thing to do would be to enable a catch-all rule that disables itself, or have the script read a key. However, it doesn’t seem possible to do so, at least not easily.

However, I was ready to accept this limitation. I wrote a little Python code for control+x:

store.set_global_value("vmacs-prefix-x","true");

Then, just to test one thing at a time, I did the following for the letter u:

state=store.get_global_value("vmacs-prefix-x");
if state == "true":
   keyboard.send_keys("+z");
   store.set_global_value("vmacs-prefix-x","false");
else:
   keyboard.send_key("U");  # note send key will respect shift, etc.

I was glad it worked. Kind of. As I was typing, I noticed something was wrong. I’m typing pretty fast but something distracts me and I couldn’t figure out what it was. I finally realized that when an Autokey script or phrase runs, the browser loses focus for a single tick. When you press a cursor control, you don’t notice it, but when you’re typing fast, watch out! I left the scripts, but disabled them like I did with control+w. You may not be as sensitive to brief disconnects, and if so, you may want to implement other two-key combinations in the same way.

Disappointment avoided

The other issue I had was a big disappointment. Macros didn’t work in multi-line or WordPress editors, where I spend way too much time. A quick check shows that the edit boxes have a different window class. I ended up turning the filters into a regular expression: .*Vivalid-stable. Of course, if you use another browser, you will have to adapt.

AutoKey can probe window properties for you.

I’m still a bit disappointed that while two-key combinations are workable, they’re not practical for me. I suspect it would bite you if you tried to emulate vi as well, since you would have to catch almost every normal key.

Still, I wrote this whole post using emacs semantics, and other than sometimes forgetting to paste using control + y, it worked fine. I can still re-enable control+w because I accidentally closed the window multiple times when trying to paste.

There are browser extensions that claim to let you edit text fields in your editor of choice. They work, but they do little more than copy text back and forth to the editor. It’s great for small things, but trying to create a big post with WordPress functionality isn’t exactly practical. With this system you can have emacs semantics when editing text and in the URL bar. It would be trivial to adapt the system to almost any program.

You may not care about emacs, but there are a lot of things you can do to save time with a program like Autokey. From shortcuts for URLs, to simple bash lines, to things you type over and over again, Autokey is both simple to set up for simple things and complex enough to handle big jobs. I just wish it worked on Wayland.

Previous Article

How to Clear Browser Cache in Chrome, ...

Next Article

Navigation Software Market Size, Share and Forecast ...

  • Privacy Policy
  • Terms and Conditions