/mc-calc

Combine multiple-cursors and calc

Primary LanguageEmacs LispGNU General Public License v3.0GPL-3.0

Emacs Package mc-calc

This Emacs package allows the use of calc in regions with multiple-cursors.

Installation

You can install mc-calc through package.el.

It is available on MELPA:

M-x package-install mc-calc

The package depends on the multiple-cursors package, so if you do not use package.el, you would need to install that too.

Documentation

Please use M-x finder-commentary mc-calc for documentation.

Usage Examples

All following examples assume you know how to use multiple-cursors. But so that you can follow without knowing multiple-cursors, I use the verb to mc, which means the following operations:

  • move the cursor to the beginning of the first element of interest (number or expression),
  • mark each line with M-x mc/mark-next-lines,
  • activate the region for each cursor over the element of interest by issuing C-SPC and moving the cursor right.

You can disable multiple-cursors after using it by entering RET.

Simple Calculations

Say you write code in C and want to evaluate the following formulas:

#defun BITMASK_BIT1 2^1
#defun BITMASK_BIT2 2^2
#defun BITMASK_BIT6 2^6

All you have to do is to mc the 2^* parts and issue M-x mc-calc-eval to get:

#defun BITMASK_BIT1 2
#defun BITMASK_BIT2 4
#defun BITMASK_BIT6 64

Vectors

Consider you have the following org table and quickly want to calculate 2 to the power of those values:

| 1 |
| 2 |
| 6 |

You simply mc each number and use M-x mc-calc-grab:

--- Emacs Calculator Mode ---
1:  [1, 2, 6]
    .

Then in the calc buffer you enter 2 and TAB followed by VM^ to get the desired values:

--- Emacs Calculator Mode ---
1:  [2, 4, 64]
    .

To get these values back into the table you use M-x mc-calc-copy-to-buffer, disable multiple-cursors with RET and re-align the table with TAB:

|  2 |
|  4 |
| 64 |

Testing

First install Cask.

Then execute unit tests:

./ut.sh

and behavior tests:

./br.sh

Useful links for test development:


GPL v3 MELPA Compile Test Lint Unit Test Behaviour Test Build Status