arecarn / vim-crunch Goto Github PK
View Code? Open in Web Editor NEWA calculator inside Vim
License: Do What The F*ck You Want To Public License
A calculator inside Vim
License: Do What The F*ck You Want To Public License
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
:
:
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
e.g.
counter
_aa3p
very_long_variable_name_with_underscores
FuncLength2
LENGTH
Before the dev branch is merged with the main branch these updates need to be put in the readme.
I'd like to see 1234567890 instead of 1.23456789e9.
is it possible?
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
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)
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()
.
Is it possible to allow Crunch to accept expressions like '1.2E-5' or '1.2e-5' etc.?
When evaluating the entire buffer with the following
x = 20
x = x = 10
x
x = 20
x = x = 10
x = 10
x = 20
x = x = 20
x = 20
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
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 */
)
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.
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.
The former is small and specific enough to be added to the latter, facilitating its installation.
Current bindings are enforced. Is there a way to remap them? I use g=
for other purposes, I would like to remap it go gc
(go compute/crunch). Is it possible to customize this?
@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:
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.
Add a public interface for crunch so others can use it in their plugins.
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
.
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
Hi, would it be possible to support number formats with comma for decimal point?
For example 123.456,789
The Commit in question is
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.
@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
This issue is currently being worked on the Dev branch.
The following expression fails to evaluate
(1).5
this should result in
(1).5 = .5
Some alternative evaluation methods might include:
Evaluating with these outside programs would optionaly replace the existing Vim Script evaluation
var2a = 10
var2b = 20
var2a + var2b = Crunch error: variable var2 not found
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:
vim-crunch/autoload/crunch.vim
Line 64 in 7a4bc1c
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.
Is there a way to round results (e.g. ceil, round etc.)
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
.
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
?
dosn't seem like it's needed
This doesn't happen when evaluating 5.5e307
This also happens when dividing by 0
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.
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
e.g.
Given:
let g:crunch_user_variables = {'pi':3.14159265359}
Then following occours. because in the second line the 2 is being prepended infront of the pi constant and not being multiplied like expected.
2*pi = 6.283186
2pi = 23.141593 "expected 6.283186"
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:
{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.
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...
Hello,
Is it possible to add an option to sum the numbers in a column? Or maybe such a possibility already exists? Thanks.
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.
at least a basic level, how to work with the plugin
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.