Git Product home page Git Product logo

vim-crunch's People

Contributors

arecarn avatar ashok-arora avatar gitter-badger avatar konfekt avatar macgyvernl avatar mmontu avatar rcarney-fluke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vim-crunch's Issues

Ignore line prefix

As mentioned on #7 it could be useful to have a list of patterns that would be ignored if occurs in the start of the line . The purpose is to have Crunch to evaluate expressions inside comments:

// var1 = 123
// var2 = 345
// <<expression 1>
// <<expression 2>
// 
if (... // C/C++ code
:
:

// var1 = 678
// var2 = 901
// <<expression 3>
// <<expression 4>
//
if (... // C/C++ code
:
:

Exponent notation not recognized

Vjg= evaluation of the visually selected 2 lines below does not recognize the exponent notation

n = 2.304e7
n/10 = Crunch error: value for e7 not found

g== on the second line produces the correct result:

n/10 = 2304000

Readme is out of date

Before the dev branch is merged with the main branch these updates need to be put in the readme.

  • new screen caps
  • updated info on features.

Expression similar this does not work "var2(40)"

I don't know If I'm going to fix this one because this makes var2 seem like a function.

var1 = -10*200 = -2000
var2 = -20
2var1 + -2var2(-40)            |<---- this line causes an error 'var2 undefined variable'
2var1 + -2var2*-40 = -5600

Change Crunch Mappings

I noticed in #15 that nerdcommenter has conficting mappings with Crunch. I've
been thinking about changing the default mappings of crunch. here are some suggested alternatives the the current mappings.

++ = CrunchLine
+ap = CrunchBlock (+ = crunch , ap = a paragraph)

Include error messages after expressions instead of using Vim errors

It would be better to have error messages appended to an offending line instead of throwing Vim error messages when there is an error on an expression.

An user may think the error is the result of a plugin bug instead of an error on the input.

The error message could include an tag such as CrunchError that could make it easy to remove in RemoveOldResult().

In-line comments

Add support for in-line comments

var = 1.2 // comment
var * 2

Current Output:
var = 1.2 // comment = Crunch error: variable comment not found
var * 2 = Crunch error: value for var not found.

Desired Output:
var = 1.2 // comment
var * 2 = 2.4

Ignore line suffix

As mentioned in #15

/* radius = 5 */
/* pi = 3.1415 */
/* area = pow(radius,2)*pi = 78.5375 */
/* volume = pow(radius,3)*pi*4/3 = 523.583333 */

support for evaluating expressions with a close of a multi line comment at the end of the line need to be supported. (eg the ending */)

vim can't calculate with numbers larger than 9999999

In the int to float conversion of 10000000 it is converted to 1e7 and is not usable by vim

The only way to fix this is to use an alternative method to evaluate math that either handles numbers like 1e7 or one that uses float math by default.

:CrunchBlock command calculatesusing tags incorrectly depending on cursor position

var1# = 123            |<-- incorrect evaluation var1 + var2 = 3
var2# = 345            |<-- incorrect evaluation var1 + var2 = 125
#var1 + #var2 = 468    |<-- correct evaluation   var1 + var2 = 468
                       |
var1# = 1              |<-- incorrect evaluation var1 + var2 = 468
var2# = 2              |<-- incorrect evaluation var1 + var2 = 346
#var1 + #var2 = 3      |<-- correct evaluation   var1 + var2 = 3

Correct evaluation of a block only occurs when you are on the last line of the block

The suggested change to crunch#CrunchBlock() in #7 seems to fix this problem, for the time.

In additions to fixing this problem tests checking for this problem should also be added.

Make sure Dev is ready for merge into Master v2

@mMontu I think what we have worked on In the Dev branch deserves a release, I just want to make sure everything is as it should be. When you get some spare time here and there could you just help me look over everything.

This won't be closed until:

  • v2 release on github
  • code and readme are updated on Vim.org

Append result after = at the end of expression else replace it.

With hotkeys g={motion} and g== there is either replace or append expressions depended on g:crunch_result_type_append.
It would be nice to have option to append result to expression ended with = and replace one without last =.
It may be new option g:crunch_result_type_append = 2 to preserve compatibility with exist installations.

modular arithmetic fails

default conversion of all numbers to floating point by appending .0 to integers makes modular arithmetic fail, for example, 10 % 3 produces the error messages

Errore/i eseguendo function crunch#operator[47]..crunch#eval[29]..crunch#core[6]
..<SNR>372_eval_math[10]..<SNR>372_vim_eval:
riga    8:
E804: Non si può usare '%' con un Numero-a-virgola-mobile
E15: Espressione non valida: 10.0 % 3.0

instead of 10 % 3 = 1.

Does not work after fresh install

Just installed the 2 plugins (selection and crunch) on Vim version 7.4.854 with vundle, but cannot get them to work at all (Vim version is compiled with float option)
Here is a simple test I did after installation:

Open gvim
i
1 + 2

0g=$

displays :

Erreur détectée en traitant function crunch#operator :
ligne 2 :
E117: Fonction inconnue : util#debug#print_header

and typing

:Crunch 1+2

in command mode displays :

Erreur détectée en traitant function crunch#command..75_handle_cmd_input :
ligne 4 :
E117: Fonction inconnue : util#debug#print_header
ligne 5 :
E117: Fonction inconnue : util#debug#print_var_msg
ligne 12 :
E117: Fonction inconnue : util#debug#print_var_msg
ligne 16 :
E117: Fonction inconnue : util#debug#print_var_msg
Erreur détectée en traitant function crunch#command..crunch#cmd_line_crunch..75_valid_line :
ligne 5 :
E117: Fonction inconnue : util#debug#print_header
Erreur détectée en traitant function crunch#command :
ligne 7 :
E171: :endif manquant
Appuyez sur ENTRÉE ou tapez une commande pour continuer

Thanks for help

Last Commit Changing Crunch Input behavior didn't work

The Commit in question is

2d265e8

I know calling crunch#Crunch('') works when you do it explicitly from the command line. I won't when I try to call :Crunch . Where is a mathematical expression

@mMontu do you have any idea why this might be? I think this is what you intended for Crunch input or maybe it was just for testing purposes.

Change the way variable storage is handled

@mMontu wrote:

To be honest I don't like this approach of backward searching. It seems more time consuming and overly complex. Maybe it would be better if each line evaluated includes any variables assigned to a dictionary, then GetTagValue() would simple read variable values from this dictionary. If CrunchLine() handles its range directly it could initialize the dictionary on the begging and destroy it before returning in order to save memory space

Copying result to clipboard

According to :help clipboard (after the Note):

When the "unnamed" string is included in the 'clipboard' option, the unnamed
register is the same as the "* register.  Thus you can yank to and paste the
selection without prepending "* to commands.

So it should be always ok to yank into the unnamed register like here:

call setreg('"', result, 'c')

No need to check for clipboard :) This would have the additional benefit that it will also work if the vim version doesn't have the clipboard option.

Rounding

Is there a way to round results (e.g. ceil, round etc.)

Change on error messages

After playing a while with -exclusive and seeing a lot of error messages I had an idea (which could be used after Master v2 is released): suppress the Vim error, as appending the error message to each fault line seems clear enough.

In order to assure the user doesn't miss the error message on the text we could use matchadd() to highlight Crunch error, and clear that highlight on the next execution of any Crunch command. The group number could be save on a w:var, so the user could also delete the highlight manually through matchdelete.

request: looser syntax for powers

Instead of pow(2,3), could vim-crunch accept also the more common, and intuitive, expressions 2^3 or 2**3 to compute the cube of 2?

Refactor Suffix & Prefix Code

I want to rework how the prefix and suffix are handled to make the code a bit cleaner.

Instead of what happens currently I wasing thinking that at the start of crunch
I was thinking about removing the suffix and prefix if they exist, and only add them back in as the final step.

large number evaluation

It would be great if large numbers were automatically converted to floating point.

Current Output:
41630727/400/60/60 = Crunch error: 41630727 is too large for VimScript evaluation

Current Workaround:
41630727.0/400/60/60 = 28.910229

Add configurable predefined variables

The plugin could have a mechanism to define constant values/aliases to functions which it would replace when parsing the expression.

I thought of two main uses:

  • Constants: despite it is possible to write down the constant before starting the calculation, it could be helpful to have common constants defined on .vimrc and always available to all crunch calculations
  • aliases:
    {1}**{2} : pow({1}, {2})
    then x**y would be the same as pow(x, y)

Just an idea, maybe it is out of the scope for the plugin.

Heading typo

First of all, thank you very much for sharing this great plugin!
I've been using VimCalc for some time now, but I liked this plugin as it doesn't depends on python being available to run or knowledge on that language to contribute to the plugin , and its easy to save the calculations.

English is not my first language, but I believed I spoted a typo. As it is in the heading, you may consider changing from

An easier way to

instead of

A Easier way to...

str2float() not available on vim 7.0

When Crunch is used on vim 7.0 it appears str2float() is unavailable and the following error is shown

Error detected while processing function crunch#Main..crunch#EvalLine..<SNR>42_IntegerToFloat..<SNR>42_ConvertInt2Float: line 8: E117: Unknown function: str2float E15: Invalid expression: str2float(num)

An alternate method of string to float conversion needs to be devised or Vim version requirement needs to posted.

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.