Skip to content

davidshepherd7/electric-operator

Repository files navigation

Electric operator mode

CI melpa melpa stable badge

An emacs minor-mode to automatically add spacing around operators.

For example typing

a=10*5+2

results in

a = 10 * 5 + 2

I'm aiming to have electric-operator-mode correctly handle almost every operator for major modes built in to Emacs (and a few that aren't). If you find a case where it doesn't space something as expected then consider it a bug, and please report it :).

Setup

The simplest way to install electric-operator-mode is by using package.el to get it from MELPA unstable. Alternatively you can install the dependencies listed in electric-operator.el and add electric-operator.el to your load path.

Either way you also need to make sure electric-operator is loaded with (require 'electric-operator) (or you could use use-package to load packages and keep your customisations organised).

To temporarily enable electric-operator-mode call electric-operator-mode. To permanently enable it for a major mode add it to the relevant mode hook. For example for python-mode add the following to your config:

(add-hook 'python-mode-hook #'electric-operator-mode)

Note that electric-operator-mode is not a global minor mode. It must be enabled separately for each major mode that you wish to use it with.

Customisation

The spacing around operators is controlled by "rules". The simplest rule is a pair containing the (unspaced) operator and the correctly spaced operator as strings. For example (cons "=" " = ") is the default rule for =