Quick Summary: A Few Emacs Packages I've Written

I'll give a brief summary of the Emacs packages I've written so far. All of them are fairly simple:-). You can find them on Melpa, except for my fork of matlab-mode.

Here is the list of packages I've written so far:

I'll give a brief and not-too-technical introduction to each package and share some personal feeling about the packages. For detailed usage for a package, please find the corresponding GitHub README file.

1 gscholar-bibtex

Retrieve BibTeX entries from Google Scholar, ACM Digital Library, IEEE Xplore and DBLP.

Strangely, before I wrote gscholar-bibtex, there was no pure Elisp package that supported to download BibTeX entries from Google Scholar directly. Some Python or Perl scripts did exist, but I don't think we need the help from other scripting languages, which introduces unnecessary dependencies. And although bibretrieve supports to download BibTeX entries from various sources, Google Scholar is not supported and personally speaking, I don't like the way that bibretrieve does: it only fetches BibTeX entries. In some cases, it is hard to figure out whether the fetched BibTeX entry is what we want due to the lack of certain context. On the other hand, if we fetch too often from Google Scholar, our IP will be banned! I used to encounter such situations very often when I ran gscholar, a Python script which does similar things.

So what gscholar-bibtex does is: first it asks you for the keyword to search, then it displays the search results with the title and the excerpt. Users can select a result and preview the corresponding BibTeX entry. If that is what he/she wants, store the BibTeX entries to the database or some other file. The whole process is pretty much like what you would do in a web browser, but the workflow is simplified and it is implemented only in Emacs Lisp so is tightly integrated into Emacs.

Later I added support for ACM Digital Library and IEEE Xplore, and thanks to Liblit, we also got support for DBLP. The package right now is pretty stable. For future improvements, I would like to investigate helm-bibtex and org-ref a little bit to find the possibilities to integrate these packages.

2 ace-jump-mode and avy extensions

avy is one of the most important Emacs extensions I have ever used. Jumping to anywhere in the screen using avy is super fast. However, at the time I started to write these packages, it was ace-jump-mode that provided such functionalities, and at first abo-abo didn't plan to release =avy=(See here. He changed his mind later, which is really a good decision!). You can notice that some of the packages I've written have ace- in their names. That's simply because originally I wrote these packages as an extension for ace-jump-mode, although most of them now supports avy or actually uses avy.

2.1 ace-pinyin

Jump to Chinese character by pinyin with ace-jump-mode or avy

This package supports ace-jump-mode and avy. It's a real pain that avy only supports English and we can't use avy to jump to Chinese characters since I use avy heavily to navigate in files. Then I found find-by-pinyin-dired by Chen Bin, and inspired by this package, I wrote ace-pinyin. As long as ace-pinyin-mode is enabled, we can jump to either English or Chinese characters, using either ace-jump-mode or avy.

For Japanese users, this article provides a way to use ace-pinyin in Japanese, and thanks to erstern, we got support for traditional Chinese characters!

An outdated screenshot:

2.2 ace-flyspell

Jump to and correct spelling errors using ace-jump-mode and flyspell

This package is inspired by abo-abo's ace-link. Once you have enabled flyspell-mode, you can jump to an error found by flyspell using ace-jump-mode. If you're using the command ace-flyspell-dwim, provided in this package, you can further fix the error and jump back to where you are in the beginning after you accept the fix. See this demo for the command =ace-flyspell-dwim=(it is a little out of date though):

I use ace-flyspell-dwim very often. If flyspell finds a spelling error, I can quickly jump to the misspelled word, fix it and jump back. I feel the least interrupt during my writing using such a method.

Unfortunately, right now this package is still using ace-jump-mode, and some features that I've planned haven't been added. For most of my use cases, it is good enough now, but I would like to use avy as the backend and add more features to it.

2.3 ace-jump-helm-line

Ace-jump to a candidate in helm window

This is another simple, naive, yet useful package. anything.el has a similar function but helm gets rid of it.(May not be true now, see here). The original idea is proposed by hick(I don't know your link, sorry). To select a candidate in helm quickly, we can invoke ace-jump-helm-line, using the similar interface as avy-goto-line, to jump to a candidate. Another command is ace-jump-helm-line-execute-action, which will execute the persistent action after jumping to a candidate.

Let's see what would happen:

2.4 avy-zap

Zap to char using avy

This package is basically a fork of the functionality of ace-jump-zap, but using avy instead of ace-jump-mode as the jumping method. Yeah, finally a package named with avy!

2.5 A Little Comparison: ace-jump-mode vs avy

In terms of the extensibility, avy is much better than ace-jump-mode since it is fully synchronized. In ace-jump-mode, you have to rely on the hooks to run some custom functions, and there is a high probability that different packages may interfere and conflict with each other because the developers may not take care of the hooked functions used by other packages. Also, it is generally easier to do some complicated things and get the code right when using the fully synchronized way provided by avy.

ace-jump-mode is not longer maintained. Using avy instead, and thanks to abo-abo for this awesome package(and his other packages such as hydra and ace-link)!

3 For Chinese Users

In addition to ace-pinyin, I have also written some other packages, which might be useful especially for Chinese users.

3.1 fcitx.el

Make fcitx better in Emacs

In Vim, fcitx.vim helps toggle fcitx in normal mode and insert mode, and in Emacs, we have fcitx.el, which adds the same functionalities to Evil, and besides, we have extra features for prefix keys and minibuffer input.

User can set up the package either by fcitx-default-setup or fcitx-aggressive-setup. The difference between fcitx-default-setup and fcitx-aggressive-setup is that the latter completely disables fcitx in the minibuffer. For users who spend most of their time typing Chinese only in buffers, I suggests to use fcitx-aggressive-setup.

As I'm not a hardcore Evil user, and most of the time I'm using Emacs key bindings, personally speaking, I like the prefix keys features most. It can disable fcitx after the user presses some certain prefix keys, such as C-x and C-c, so that the next single letter input, say b, will not block by fcitx.

For OSX users, who don't have fcitx available, install fcitx-remote-for-osx. It is compatible for both fcitx.el and fcitx.vim (modified version, see the project's README).

3.2 bing-dict.el

Minimalists' Bing dictionary for Emacs

This package will ask the user for the word that he/she wants to find the translation from Bing Dict, and shows the one-line result in the echo area, and that's it, no bullshit and minimum of interference!

Here is the screenshot:

Why using Bing Dictionary? Because it does a fairly good job and its competitors really suck, for example, Youdao Dictionary.

4 company-qml

Emacs company-mode backend for QML

The package name explains almost everything if you know what is company-mode. In fact, auto-complete comes with a dictionary-based QML completion, while company-mode doesn't. However, you can simply use the dictionary in auto-complete and add all the keywords in the dictionary to company-keywords-alist so that company-keywords backend is able to complete these keywords. However, I wanna achieve something a little more intelligent.

I wrote a simple parser to parse the information provided in plugins.qmltypes files, which can be generated by qmlplugindump. After parsing type information, the company backend should be able to utilize the extracted type information. Several screenshots:

Using plugins.qmltypes is very flexible. If you want completions for other libraries, say, if you are writing plugins for Plasma, you can feed the plugin.qmltypes file to the parser. As far as I know, QtCreator takes a similar approach.

It is quite usable, but far from perfect for the time being. I would like to improve it in the near future. Several possible improvements that are on my top TODO list for this package are:

  1. Simplify the configuration process. For example, provide out-of-box completions for QML files using standard QML libraries. Extra settings are only needed when you need completions for third-party libraries.
  2. Better QML parser. For example, support nested object completions(current only one nested level) and as in import statement.

Javascript support will be considered a little bit later.

5 gmpl-mode

Major mode for editing GMPL(MathProg) files

When I decided to use glpk for the project in my Linear Programming course, I was surprised to see that Emacs had no support for GNU MathProg(GMPL), which is the mathematical programming language used to describe models that can be solved by glpk. Before writing this major mode, I found ampl-mode on GitHub, but it has poor support for GMPL files, e.g., keywords not highlighted properly, some GMPL syntaxes are not supported, and its indentation function is too simple to indent my code correctly.

So here comes gmpl-mode, and this is how it looks like using Emacs 24’s builtin theme tsdh-dark:

If you only need to solve linear programs, you can use C-c C-c to call gmpl-glpsol-solve-dwim. The solutions and the sensitivity report will be shown in a new buffer. I also added some font-lock keywords to the solution buffer, so the key parts of the solutions can be recognized very quickly.

6 emacs-firefox-controller

An improved Firefox controller for Emacs

Wow, control Firefox from Emacs, cool idea, huh?

You have two different modes to choose: firefox-controller-direct-mode and firefox-controller-remote-mode. firefox-controller-direct-mode, as the names suggests, you can control the Firefox as if you are currently in Firefox, while your Emacs window keep the current focus of your window manager. All the keys you pressed will be processed by Firefox, except for some special keys. firefox-controller-remote-mode, on the other hands, provides some commands and binds these commands to a short key sequence. The keys pressed are processed by Emacs and Emacs remotely controls the Firefox.

Confused? See the screenshots!

Here is the screenshot for firefox-controller-direct-mode:

What on the earth am I doing here? First I invoke firefox-controller-direct-mode. After that I type C-l to go to the address bar, and use M-g to highlight my current location(which is the address bar of course). Then go to google.com, and use M-g again to confirm the current focused element in firefox is the search box. After I type and search "emacs", I use KeySnail's plugin hok to jump to a link and open it.

And what about firefox-controller-remote-mode? Here it is:

Instead of using your Firefox key bindings, you can use the previous key bindings to control Firefox, like what we do when using a TV remote controller! This mode is good enough for just viewing the web page, but for tasks like editing text or jumping to a link, go to firefox-controller-direct-mode and use it with KeySnail.

Note this is a reimplementation of emacs-moz-controller by RenWenshan. It adds a lot of new features and provides a complete different user interface. Thanks to RenWenshan for such an awesome idea!

See also the discussions on /r/emacs.

7 matlab-mode

This is a fork repo of pronobis's matlab-mode repo.

Thanks to probobis, who added some initial company-mode support for matlab-mode, but unfortunately, I can't really get company-matlab-shell.el to work. So I rewrote company-matlab-shell.el to fix many bugs, and added support to company-matlab.el so that it can complete the functions in the files under the current directory, which means you can get completions for your own functions. Cool.

I don't create a pull request against the upstream repo since the code is kind of a mess(although it really works for me without any problems so far), and it contains some opinionated changes. Use my fork at your own risk:-).

8 My Thoughts on Elisp Development

I've written several Emacs packages and contributed a few lines of code to some popular Emacs packages. However, I'm not a hardcore Elisp developer, as I haven't really written anything complex enough in Elisp. All these packages are simple, but I personally find them really useful in my daily Emacs use.

As an Emacs user, I would like to see more people coming into this community so that more awesome packages can be obtained! Elisp is not hard to learn if you have some scripting or functional language experience. I myself comes from a Python, Ruby and Scala background. So far, writing Elisp has been a fun journey.

Welcome aboard, Elisp hackers!

Junpeng Qiu 18 December 2015
blog comments powered by Disqus