Coder Social home page Coder Social logo

mc-calc's Introduction

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

mc-calc's People

Contributors

hatheroldev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mc-calc's Issues

Provide minor mode

This package has some global and buffer local state, that is not easily visible to the user.
If you used mc-calc-grab in buffer a then a global state changed in which a subsequent call to mc-calc-copy-to-buffer will return to a and insert the calc top element. It would be nice to see:

  • in buffer a that mc-calc is active and will return to this buffer
  • in all other buffers, that mc-calc is active

Additional thoughts:

  • The minor mode indicator could copy the calc result if clicked with left mouse button.
  • Copying the top element should disable the mode. If that is not desired one could keep the mode active with prefix argument.

Provide an API to other "multiple regions"

I would like to have the opportunity to use some alternative to multiple-cursors by setting "get list of strings" and "set list of strings" functions.

From the retrieved list of strings the number of "cursors" should be derivable.

Also a setup function providing a default binding to multiple-cursors can provide current default usage.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.