all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* I want to add a package to GNU ELPA: infix-notation-calculator
@ 2021-08-16 21:14 Christian Johansson
  2021-08-16 22:01 ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: Christian Johansson @ 2021-08-16 21:14 UTC (permalink / raw)
  To: emacs-devel

Hi!

Here is the plugin: 
https://github.com/cjohansson/emacs-infix-notation-calculator

Features are:
* Calculate selected text
* Calculate input in minibuffer
* A calculate-mode where calculation of line is done automatically when 
pressing C-return
* A history buffer of all calculations

-- 
Hälsningar / Best Regards
Christian




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I want to add a package to GNU ELPA: infix-notation-calculator
  2021-08-16 21:14 I want to add a package to GNU ELPA: infix-notation-calculator Christian Johansson
@ 2021-08-16 22:01 ` Stefan Monnier
  2021-08-17  7:32   ` Christian Johansson
  0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2021-08-16 22:01 UTC (permalink / raw)
  To: Christian Johansson; +Cc: emacs-devel

Christian Johansson [2021-08-16 23:14:27] wrote:

> Hi!
>
> Here is the plugin:
> https://github.com/cjohansson/emacs-infix-notation-calculator
>
> Features are:
> * Calculate selected text
> * Calculate input in minibuffer
> * A calculate-mode where calculation of line is done automatically when
>     pressing C-return
> * A history buffer of all calculations

Any chance you could expand a bit on what this does?
The `README.md` and the `Commentary:` are both fairly limited, basically
the only description of what it computes is given by the package's name.

I think it needs some description of the format it accepts, and maybe
a brief comparison with other Emacs calculators (such as the bundled
`calc` and `calculator`).


        Stefan




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I want to add a package to GNU ELPA: infix-notation-calculator
  2021-08-16 22:01 ` Stefan Monnier
@ 2021-08-17  7:32   ` Christian Johansson
  2021-08-17 11:01     ` Eric S Fraga
  2021-08-17 23:28     ` Stefan Monnier
  0 siblings, 2 replies; 13+ messages in thread
From: Christian Johansson @ 2021-08-17  7:32 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Hi!

Sure, I think calc and calculator are more full-focused calculators that 
require a learning-curve, this plugin is more of an quick ad-hoc 
calculator that calculates values like (infix notation)

* 1+3*5
* 4 + 4.5 - (34/(8*3+-3))
* -56 + 2
* 3^2

So you can just select a region (regardless of mode) containing any 
expression like that and you will get the calculated result in the echo 
area and in the calculation log buffer.

You can also use the mode infix-notation-calculator-mode in a buffer to 
make calculations at chosen places in the buffer, so you can mix notes 
with calculations (like a spreadsheet but less advanced), example 
buffer-contents:
---

Morgage:
100000*0.05
=5000.0

Skates to my daughter:
6000+2000+1500
=9500.0

;; Some random notes here

Ratio:
4 + 4.5 - (34/(8*3+-3))
=6.880952380952381
---

Here the calculations are inserted automatically on the next line when 
pressing <C-return>. This is very handy I think when making everyday 
ad-hoc notes

Lastly you can calculate any input in the mini-buffer on demand

Hälsningar / Best Regards
Christian

On 17/08/2021 00:01, Stefan Monnier wrote:
> Christian Johansson [2021-08-16 23:14:27] wrote:
>
>> Hi!
>>
>> Here is the plugin:
>> https://github.com/cjohansson/emacs-infix-notation-calculator
>>
>> Features are:
>> * Calculate selected text
>> * Calculate input in minibuffer
>> * A calculate-mode where calculation of line is done automatically when
>>      pressing C-return
>> * A history buffer of all calculations
> Any chance you could expand a bit on what this does?
> The `README.md` and the `Commentary:` are both fairly limited, basically
> the only description of what it computes is given by the package's name.
>
> I think it needs some description of the format it accepts, and maybe
> a brief comparison with other Emacs calculators (such as the bundled
> `calc` and `calculator`).
>
>
>          Stefan
>
>



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I want to add a package to GNU ELPA: infix-notation-calculator
  2021-08-17  7:32   ` Christian Johansson
@ 2021-08-17 11:01     ` Eric S Fraga
  2021-08-17 11:20       ` Christian Johansson
  2021-08-17 23:28     ` Stefan Monnier
  1 sibling, 1 reply; 13+ messages in thread
From: Eric S Fraga @ 2021-08-17 11:01 UTC (permalink / raw)
  To: emacs-devel

On Tuesday, 17 Aug 2021 at 09:32, Christian Johansson wrote:
> You can also use the mode infix-notation-calculator-mode in a buffer
> to make calculations at chosen places in the buffer, so you can mix
> notes with calculations (like a spreadsheet but less advanced),
> example buffer-contents:

Doesn't Embedded Calc do all of this already?
-- 
Eric S Fraga via Emacs 28.0.50 & org 9.4.6 on Debian 11.0




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I want to add a package to GNU ELPA: infix-notation-calculator
  2021-08-17 11:01     ` Eric S Fraga
@ 2021-08-17 11:20       ` Christian Johansson
  2021-08-17 15:21         ` Eric S Fraga
  0 siblings, 1 reply; 13+ messages in thread
From: Christian Johansson @ 2021-08-17 11:20 UTC (permalink / raw)
  To: Eric S Fraga, emacs-devel

Hi!

If you mean calc-embedded.el I didn't know about that. Reading the 
manual at: 
https://www.gnu.org/software/emacs/manual/html_node/calc/Embedded-Mode.html
and it doesn't seem to do the same, it's integrated into calc.el and 
uses the same stack as calc.el, when running C-x * e on any line in my 
example buffer I get "Parse Error", pressing C-x * w I get error "Too 
few elements on stack"

Hälsningar / Best Regards
Christian

On 17/08/2021 13:01, Eric S Fraga wrote:
> On Tuesday, 17 Aug 2021 at 09:32, Christian Johansson wrote:
>> You can also use the mode infix-notation-calculator-mode in a buffer
>> to make calculations at chosen places in the buffer, so you can mix
>> notes with calculations (like a spreadsheet but less advanced),
>> example buffer-contents:
> Doesn't Embedded Calc do all of this already?



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I want to add a package to GNU ELPA: infix-notation-calculator
  2021-08-17 11:20       ` Christian Johansson
@ 2021-08-17 15:21         ` Eric S Fraga
  2021-08-17 15:27           ` Christian Johansson
  0 siblings, 1 reply; 13+ messages in thread
From: Eric S Fraga @ 2021-08-17 15:21 UTC (permalink / raw)
  To: emacs-devel

On Tuesday, 17 Aug 2021 at 13:20, Christian Johansson wrote:
> and it doesn't seem to do the same, it's integrated into calc.el and
> uses the same stack as calc.el, when running C-x * e on any line in my
> example buffer I get "Parse Error", pressing C-x * w I get error "Too
> few elements on stack"

Make sure the line has only a valid (infix) equation and it will
work.  Your example had *at the start of each time which means multiply
but there is no left hand side...

Embedded Calc allows you to customize how equations are found, in any
case, but the default is often just blank lines before and after.

-- 
Eric S Fraga via Emacs 28.0.50 & org 9.4.6 on Debian 11.0




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I want to add a package to GNU ELPA: infix-notation-calculator
  2021-08-17 15:21         ` Eric S Fraga
@ 2021-08-17 15:27           ` Christian Johansson
  2021-08-17 15:54             ` Eric S Fraga
  0 siblings, 1 reply; 13+ messages in thread
From: Christian Johansson @ 2021-08-17 15:27 UTC (permalink / raw)
  To: Eric S Fraga; +Cc: emacs-devel

No I tried with the example buffer contents, without * and I got those errors. However I got it working in emacs-lisp-mode buffer but it deleted my calculation and replaced it with the answer.. can that feature be turned off?

> 17 aug. 2021 kl. 17:22 skrev Eric S Fraga <e.fraga@ucl.ac.uk>:
> 
> On Tuesday, 17 Aug 2021 at 13:20, Christian Johansson wrote:
>> and it doesn't seem to do the same, it's integrated into calc.el and
>> uses the same stack as calc.el, when running C-x * e on any line in my
>> example buffer I get "Parse Error", pressing C-x * w I get error "Too
>> few elements on stack"
> 
> Make sure the line has only a valid (infix) equation and it will
> work.  Your example had *at the start of each time which means multiply
> but there is no left hand side...
> 
> Embedded Calc allows you to customize how equations are found, in any
> case, but the default is often just blank lines before and after.
> 
> -- 
> Eric S Fraga via Emacs 28.0.50 & org 9.4.6 on Debian 11.0
> 
> 




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I want to add a package to GNU ELPA: infix-notation-calculator
  2021-08-17 15:27           ` Christian Johansson
@ 2021-08-17 15:54             ` Eric S Fraga
  2021-08-17 16:55               ` Christian Johansson
  0 siblings, 1 reply; 13+ messages in thread
From: Eric S Fraga @ 2021-08-17 15:54 UTC (permalink / raw)
  To: emacs-devel

On Tuesday, 17 Aug 2021 at 17:27, Christian Johansson wrote:
> No I tried with the example buffer contents, without *and I got those
> errors. However I got it working in emacs-lisp-mode buffer but it
> deleted my calculation and replaced it with the answer.. can that
> feature be turned off?

The general form for an Embedded Calc question is:

var := expression => 

where "var :=" (means assign the result to variable called "var") and
"=>" are optional.  The result will replace the expression if there is
no "=>" but will place the result after the => if it's there.

For instance:

y := sqrt(2) => 1.41421356237

and

x := y^2 => 1.99999999999

The info manual is very comprehensive.

-- 
Eric S Fraga via Emacs 28.0.50 & org 9.4.6 on Debian 11.0




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I want to add a package to GNU ELPA: infix-notation-calculator
  2021-08-17 15:54             ` Eric S Fraga
@ 2021-08-17 16:55               ` Christian Johansson
  0 siblings, 0 replies; 13+ messages in thread
From: Christian Johansson @ 2021-08-17 16:55 UTC (permalink / raw)
  To: Eric S Fraga; +Cc: emacs-devel

Ok I see, I'll check the manual to see if it can do what I want, that is calculate selected region without touching the current buffer contents, and the other features. But I agree there is overlap in functionality but there seems be differences as well

> 17 aug. 2021 kl. 17:55 skrev Eric S Fraga <e.fraga@ucl.ac.uk>:
> 
> On Tuesday, 17 Aug 2021 at 17:27, Christian Johansson wrote:
>> No I tried with the example buffer contents, without *and I got those
>> errors. However I got it working in emacs-lisp-mode buffer but it
>> deleted my calculation and replaced it with the answer.. can that
>> feature be turned off?
> 
> The general form for an Embedded Calc question is:
> 
> var := expression => 
> 
> where "var :=" (means assign the result to variable called "var") and
> "=>" are optional.  The result will replace the expression if there is
> no "=>" but will place the result after the => if it's there.
> 
> For instance:
> 
> y := sqrt(2) => 1.41421356237
> 
> and
> 
> x := y^2 => 1.99999999999
> 
> The info manual is very comprehensive.
> 
> -- 
> Eric S Fraga via Emacs 28.0.50 & org 9.4.6 on Debian 11.0
> 
> 




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I want to add a package to GNU ELPA: infix-notation-calculator
  2021-08-17  7:32   ` Christian Johansson
  2021-08-17 11:01     ` Eric S Fraga
@ 2021-08-17 23:28     ` Stefan Monnier
  2021-08-18  6:40       ` Michael Heerdegen
  2021-08-18  9:03       ` Christian Johansson
  1 sibling, 2 replies; 13+ messages in thread
From: Stefan Monnier @ 2021-08-17 23:28 UTC (permalink / raw)
  To: Christian Johansson; +Cc: emacs-devel

> Sure, I think calc and calculator are more full-focused calculators that
> require a learning-curve, this plugin is more of an quick ad-hoc calculator
> that calculates values like (infix notation)
[...]

Thanks, but I meant to add that to the README or the `Commentary:`.

Also I was thinking more about the documentation on which operations are
supported.  [ IIUC you only support the four basic arithmetic
operations, with standard precedence rules, plus parentheses for
grouping, right?  ]

Also, I was wondering if you had considered implementing the parser with
the following approach:

- read the line with (read-from-string (concat "(" STRING ")"))
- massage the resulting sexp to implement the desired infix syntax.

You could even do the massaging via a macro, where

    (infix 2 + 3 * 5)
    (infix 2 + (3 * 5))
    (infix (2 + ((3) * 5)))

all macroexpand to

    (+ 2 (* 3 5))

so your syntax could be used inside code as well.


        Stefan




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I want to add a package to GNU ELPA: infix-notation-calculator
  2021-08-17 23:28     ` Stefan Monnier
@ 2021-08-18  6:40       ` Michael Heerdegen
  2021-08-18  9:03       ` Christian Johansson
  1 sibling, 0 replies; 13+ messages in thread
From: Michael Heerdegen @ 2021-08-18  6:40 UTC (permalink / raw)
  To: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> - read the line with (read-from-string (concat "(" STRING ")"))
> - massage the resulting sexp to implement the desired infix syntax.

`calc-eval' is an existing solution for this task.  Christian may want
to have a look at it before investing his time for this.

Michael.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I want to add a package to GNU ELPA: infix-notation-calculator
  2021-08-17 23:28     ` Stefan Monnier
  2021-08-18  6:40       ` Michael Heerdegen
@ 2021-08-18  9:03       ` Christian Johansson
  2021-08-18 10:47         ` Eric S Fraga
  1 sibling, 1 reply; 13+ messages in thread
From: Christian Johansson @ 2021-08-18  9:03 UTC (permalink / raw)
  To: Stefan Monnier, Eric S Fraga; +Cc: emacs-devel

Eric: calc-embedded is really good, even better than my plugin, thanks 
for the tip! Storing calculations in variables is a good feature

Stefan: Looks cool, didn't it's possible to do stuff like that, however 
this project was primarily about testing my parser generator so I 
wouldn't want to change those parts of the program

Hälsningar / Best Regards
Christian

On 18/08/2021 01:28, Stefan Monnier wrote:
>> Sure, I think calc and calculator are more full-focused calculators that
>> require a learning-curve, this plugin is more of an quick ad-hoc calculator
>> that calculates values like (infix notation)
> [...]
>
> Thanks, but I meant to add that to the README or the `Commentary:`.
>
> Also I was thinking more about the documentation on which operations are
> supported.  [ IIUC you only support the four basic arithmetic
> operations, with standard precedence rules, plus parentheses for
> grouping, right?  ]
>
> Also, I was wondering if you had considered implementing the parser with
> the following approach:
>
> - read the line with (read-from-string (concat "(" STRING ")"))
> - massage the resulting sexp to implement the desired infix syntax.
>
> You could even do the massaging via a macro, where
>
>      (infix 2 + 3 * 5)
>      (infix 2 + (3 * 5))
>      (infix (2 + ((3) * 5)))
>
> all macroexpand to
>
>      (+ 2 (* 3 5))
>
> so your syntax could be used inside code as well.
>
>
>          Stefan
>



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: I want to add a package to GNU ELPA: infix-notation-calculator
  2021-08-18  9:03       ` Christian Johansson
@ 2021-08-18 10:47         ` Eric S Fraga
  0 siblings, 0 replies; 13+ messages in thread
From: Eric S Fraga @ 2021-08-18 10:47 UTC (permalink / raw)
  To: emacs-devel

On Wednesday, 18 Aug 2021 at 11:03, Christian Johansson wrote:
> Eric: calc-embedded is really good, even better than my plugin, thanks
> for the tip! Storing calculations in variables is a good feature

Emacs Calc is one of the most powerful packages in Emacs yet mostly
unknown unfortunately or at least under-used.  It's definitely worth
investing the effort to learn it properly, I have found.

-- 
Eric S Fraga via Emacs 28.0.50 & org 9.4.6 on Debian 11.0




^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-08-18 10:47 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-16 21:14 I want to add a package to GNU ELPA: infix-notation-calculator Christian Johansson
2021-08-16 22:01 ` Stefan Monnier
2021-08-17  7:32   ` Christian Johansson
2021-08-17 11:01     ` Eric S Fraga
2021-08-17 11:20       ` Christian Johansson
2021-08-17 15:21         ` Eric S Fraga
2021-08-17 15:27           ` Christian Johansson
2021-08-17 15:54             ` Eric S Fraga
2021-08-17 16:55               ` Christian Johansson
2021-08-17 23:28     ` Stefan Monnier
2021-08-18  6:40       ` Michael Heerdegen
2021-08-18  9:03       ` Christian Johansson
2021-08-18 10:47         ` Eric S Fraga

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.