ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Calculate

Calculations using python. Also provides some number-related functions, like counting (across multiple selections). With contributions from Subhas Dandapani (rdsubhas), Alexander Kirk (akirk), and Kroum Tzanev (kpym)

Labels calculator

Details

  • 2 2013.07.09.15.15.29
    3 2.3.1
  • github.​com
  • github.​com
  • 2 years ago
  • 20 minutes ago
  • 6 years ago

Installs

  • Total 8K
  • Win 4K
  • OS X 3K
  • Linux 1K
Dec 11 Dec 10 Dec 9 Dec 8 Dec 7 Dec 6 Dec 5 Dec 4 Dec 3 Dec 2 Dec 1 Nov 30 Nov 29 Nov 28 Nov 27 Nov 26 Nov 25 Nov 24 Nov 23 Nov 22 Nov 21 Nov 20 Nov 19 Nov 18 Nov 17 Nov 16 Nov 15 Nov 14 Nov 13 Nov 12 Nov 11 Nov 10 Nov 9 Nov 8 Nov 7 Nov 6 Nov 5 Nov 4 Nov 3 Nov 2 Nov 1 Oct 31 Oct 30 Oct 29 Oct 28 Oct 27
Windows 1 2 0 2 1 1 3 4 1 2 2 2 3 3 3 1 1 3 4 2 4 2 3 2 4 2 1 4 0 1 1 0 0 4 3 3 0 2 2 3 2 4 1 2 0 1
OS X 0 1 1 6 0 3 2 3 0 1 2 2 4 4 2 1 0 1 2 5 1 3 2 0 2 1 3 3 0 3 0 0 2 1 4 2 0 1 0 2 5 1 0 1 2 6
Linux 2 2 0 2 1 0 1 2 1 0 0 1 2 1 0 1 2 2 1 0 1 0 0 2 1 0 0 1 0 1 0 0 1 5 1 2 0 1 1 2 1 1 0 0 1 1

Readme

Source
raw.​githubusercontent.​com

Calculate

Select a formula and run calculate to evaluate it using python. The result is appended to the selection (1+1 => 1+1 = 2). Using the replace: true option replaces the selected text with the result. If you have zero selections, you will be prompted for a formula, and the result will be inserted.

Any function from math and random libraries can be used (math and random documentation).

You can generate passwords using pwd(len) (or password(len)). You can calculate averages (mean) using avg([values]) (or average([values])). If you need to use a counter, you can use the i variable. Every selection will increase the counter, and it starts at 0.

i  =>  0        i*i  =>  0        (i+1)*10  =>  10
i  =>  1        i*i  =>  1        (i+1)*10  =>  20
i  =>  2        i*i  =>  4        (i+1)*10  =>  30

There is also a calculate_count command, used to count from 1 (or another index, see below) and incrementing at every cursor.

Installation

  1. Using Package Control, install “Calculate”

Or:

  1. Open the Sublime Text Packages folder

    • OS X: ~/Library/Application Support/Sublime Text 3/Packages/
    • Windows: %APPDATA%/Sublime Text 3/Packages/
    • Linux: ~/.Sublime Text 3/Packages/ or ~/.config/sublime-text-3/Packages
  2. clone this repo

  3. Install keymaps for the commands (see Example.sublime-keymap for my preferred keys)

Sublime Text 2

  1. Open the Sublime Text 2 Packages folder
  2. clone this repo, but use the st2 branch

    git clone -b st2 git@github.com:colinta/SublimeCalculate

Commands

  • calculate: Calculates the selection(s), or prompts for a formula. If replace is false it leaves the content.
  • calculate_count: Counts, adding 1 to the initial index, over each selection.
    • If the first selection is a number, it is used as the initial index.
    • Hexadecimal (0xNNNN) and octal (0NNNN) are matched, too.
    • If it is a letter, the alphabet is used.
    • Otherwise 1 is used, or it can be passed in as an argument to the command (index: N).

Keybindings

Open your key bindings file and add the bindings you want. For example:

Example.sublime-keymap
[
    { "keys": ["ctrl+shift+="], "command": "calculate", "args": {"replace": false} },
    { "keys": ["ctrl+shift+c"], "command": "calculate", "args": {"replace": true} },
    { "keys": ["ctrl+shift+alt+1"], "command": "calculate_count" }
]