Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cute-jumper/emacs-firefox-controller

An improved Firefox controller for Emacs
https://github.com/cute-jumper/emacs-firefox-controller

emacs firefox

Last synced: about 2 months ago
JSON representation

An improved Firefox controller for Emacs

Awesome Lists containing this project

README

        

#+TITLE: firefox-controller: An Improved Firefox Controller for Emacs!
[[http://melpa.org/#/firefox-controller][file:http://melpa.org/packages/firefox-controller-badge.svg]]
[[http://stable.melpa.org/#/firefox-controller][file:http://stable.melpa.org/packages/firefox-controller-badge.svg]]

* Installation
** Firefox Extension
Install [[https://addons.mozilla.org/en-US/firefox/addon/mozrepl/][MozRepl]] in Firefox.
** Emacs Extensions
This package is now on [[http://melpa.org/][melpa]]. You can install directly from [[http://melpa.org/][melpa]] using
=package.el=.

Or use the following steps to install manually:
1. Install [[https://github.com/bard/mozrepl/wiki/Emacs-integration][moz.el]] and [[https://github.com/m2ym/popwin-el][popwin-el]].
2. Install this package and add it to your load path
: (add-to-list 'load-path "/path/to/firefox-controller.el")
: (require 'firefox-controller)

* Introduction
This project started as a fork of [[https://github.com/RenWenshan][Wenshan]]'s [[https://github.com/RenWenshan/emacs-moz-controller][moz-controller]], but I ended up
rewriting most of the code and chose a quite different way to use it.

In =firefox-controller=, we have two different modes:
1. =firefox-controller-remote-mode=: This is based on the original
=moz-controller=, but the number of available commands increases from 11 to
more than 30, and simpler key bindings and a better UI are also provided.
2. =firefox-controller-direct-mode=: In this mode, you can send the keys
directly to firefox.

* =firefox-controller-remote-mode=
Use =M-x firefox-controller-remote-mode= to enter
=firefox-controller-remote-mode=. It is called =remote-mode= because the keys
that you pressed are handled by Emacs and Emacs will send control commands to
firefox.

Here is the screeshot when using =firefox-controller-remote-mode=:
[[./screenshots/remote-mode.png]]

As we can see in the screenshot, we have defined most of the commonly used
commands in firefox. For example, @@html:@@n@@html:@@ to scroll down
by one page, and @@html:@@t@@html:@@ to open a new tab and switch to
it. You can exit the =firefox-controller-remote-mode= by
@@html:@@q@@html:@@.

To search the web page, press @@html:@@s@@html:@@. Here is the
screenshot for the search mode in =firefox-controller-remote-mode= (we are
searching "bibtex" in the current web page): [[./screenshots/search-mode.png]]

However, you don't necessarily need to call =firefox-controller-remote-mode= to
use these commands. You can bind your own key to a specific command. Look at the
=firefox-controller--remote-mode-keymap-alist= variable to find out the commands
that can be bound to. For example, you can use @@html:@@C-c m
L@@html:
@@ to copy the current tab' URL by:
#+BEGIN_SRC elisp
(global-set-key (kbd "C-c m L")
#'firefox-controller-get-current-url)
#+END_SRC

* =firefox-controller-direct-mode=
The limitation of =firefox-controller-remote-mode= is that under that mode, the
web page is /non-interactive/. We can only view, scroll, switch tab, search and
open another tab for a new URL. However, if you want to jump to a link or enter
some text in the input box, these functions are not implemented. Here comes
=firefox-controller-direct-mode=, which can be combined with some powerful
firefox extensions such as [[https://github.com/mooz/keysnail][KeySnail]] to build emacs-like mouseless browsing
experience for firefox. We don't have to recreate some firefox extensions in
=firefox-controller-remote-mode=.

The use of =firefox-controller-direct-mode= is quite straightforward. =M-x
firefox-controller-direct-mode=, then you can use all the key bindings as if you
are in firefox instead of Emacs, except for four special key bindings:
1. @@html:@@C-M-g@@html:@@: Move the current focus to the content
window. This is useful when you want to move out of the address bar or search
bar to perform some page navigation(scroll up/down, open some link, etc.).
2. @@html:@@M-g@@html:@@: This is bound to
=firefox-controller-highlight-focus=, which can show a temporary background
color in the current focused element. This command is useful since the
foreground application is Emacs, firefox won't show the current focused
element(at least, we can't see it in Plasma 5 in Linux, which is my test
environment). You can use @@html:@@M-g@@html:@@ to give you a
visual hint about the location of the cursor.
3. @@html:@@C-z@@html:@@: This command switches from the current mode
to =firefox-controller-remote-mode=.
4. @@html:@@C-g@@html:@@: Exit =firefox-controller-direct-mode=.

Here is the screenshot to use =firefox-controller-direct-mode=:
[[./screenshots/direct-mode.gif]]

Explanation: After I invoke =firefox-controller-direct-mode=, I type
@@html:@@C-l@@html:@@ to go to the address bar, and use
@@html:@@M-g@@html:@@ to highlight my current location(which is the
address bar of course). Then go to google.com, and use
@@html:@@M-g@@html:@@ again to confirm the current focused element in
firefox is the search box. After I type and search "emacs", I use KeySnail's
plugin [[https://github.com/mooz/keysnail/raw/master/plugins/hok.ks.js][hok]] to jump to a link and open it.

* Define Your Own Key Sequences to Be Sent
You can use =firefox-controller-send-key-sequence= function to define your
own key sequences which can be sent directly to firefox.

For example, we define @@html:@@C-c m g@@html:@@ to open a new tab
and go to www.google.com:
#+BEGIN_SRC elisp
(global-set-key (kbd "C-c m g")
(lambda ()
(interactive)
(firefox-controller-send-key-sequence
"C-t C-l www.google.com ")))
#+END_SRC

Make sure your key sequence can be read by the =kbd= function.

* Customization
- =firefox-controller-zoom-step=: Zoom step. Default value is 0.1.
- =firefox-controller-highlight-focus-background=: The background color used by
=firefox-controller-highlight-focus= command. Default value is "yellow".

* Acknowledgment
- [[https://github.com/RenWenshan/][RenWenshan]] for the original [[https://github.com/RenWenshan/emacs-moz-controller][moz-controller]].