* Re: Quick math calc on any buffer
[not found] <mailman.1378.1235234577.31690.help-gnu-emacs@gnu.org>
@ 2009-02-21 19:08 ` B. T. Raven
2009-02-21 19:50 ` Thierry Volpiatto
2009-02-21 22:53 ` Marc Tfardy
2009-02-22 12:45 ` Scott Frazer
2 siblings, 1 reply; 12+ messages in thread
From: B. T. Raven @ 2009-02-21 19:08 UTC (permalink / raw)
To: help-gnu-emacs
Rodrigo Lazo wrote:
> Hi all,
>
> Is there a way to compute a math expression on any buffer? I mean, if I
> have a buffer with the following expression
>
> 2 + 3
>
> I want to mark the region and compute the result
>
> 2 + 3 = 5
>
> It doesn't seems too hard to do, I've looked on calculator.el for a
> "computing" function I can call but I didn't find it.
>
> Regards
>
Bind the calculator-save-and-quit function to a key-chord. I use
C-<enter>. Then the same combo will copy result to kill-ring and exit
(that is, kill calc buffer). C-y will paste result into buffer from
which the calculator was invoked. If you don't like this solution, you
can open a line in a buffer in any mode and then evaluate the lisp
expression on that line
(+ 2 3) C-x C-e
shows 5 in the mini-buffer.
Ed
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Quick math calc on any buffer
2009-02-21 19:08 ` Quick math calc on any buffer B. T. Raven
@ 2009-02-21 19:50 ` Thierry Volpiatto
0 siblings, 0 replies; 12+ messages in thread
From: Thierry Volpiatto @ 2009-02-21 19:50 UTC (permalink / raw)
To: help-gnu-emacs
"B. T. Raven" <nihil@nihilo.net> writes:
> Rodrigo Lazo wrote:
>> Hi all,
>>
>> Is there a way to compute a math expression on any buffer? I mean, if I
>> have a buffer with the following expression
>>
>> 2 + 3
>>
>> I want to mark the region and compute the result
>>
>> 2 + 3 = 5
>>
>> It doesn't seems too hard to do, I've looked on calculator.el for a
>> "computing" function I can call but I didn't find it.
>>
>> Regards
>>
>
> Bind the calculator-save-and-quit function to a key-chord. I use
> C-<enter>. Then the same combo will copy result to kill-ring and exit
> (that is, kill calc buffer). C-y will paste result into buffer from
> which the calculator was invoked. If you don't like this solution, you
> can open a line in a buffer in any mode and then evaluate the lisp
> expression on that line
>
> (+ 2 3) C-x C-e
>
> shows 5 in the mini-buffer.
Also,
C-u M-x eshell-command RET (+ 2 3) RET
will insert the result (5) at point in current buffer.
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Quick math calc on any buffer
[not found] <mailman.1378.1235234577.31690.help-gnu-emacs@gnu.org>
2009-02-21 19:08 ` Quick math calc on any buffer B. T. Raven
@ 2009-02-21 22:53 ` Marc Tfardy
2009-02-21 23:37 ` Richard Riley
2009-02-22 12:45 ` Scott Frazer
2 siblings, 1 reply; 12+ messages in thread
From: Marc Tfardy @ 2009-02-21 22:53 UTC (permalink / raw)
To: help-gnu-emacs
Rodrigo Lazo schrieb:
> Hi all,
>
> Is there a way to compute a math expression on any buffer? I mean, if I
> have a buffer with the following expression
>
> 2 + 3
>
> I want to mark the region and compute the result
>
> 2 + 3 = 5
>
> It doesn't seems too hard to do, I've looked on calculator.el for a
> "computing" function I can call but I didn't find it.
Try with embeded mode of calc: C-x * E (no need to mark the region)
and similar commands (J or W in place of E). You need to type C-x * E
again to exit the embeded mode.
Another solution:
- mark the region with math expression and put it into kill-ring (M-w)
- type SPC = SPC
- run the calc (C-x * c)
- type ' (apostrophe) and yank yor math expression (C-y)
- type RET
- type y (or C-x * y) to copy the result into buffer
- exit calc (q)
regards
marc
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Quick math calc on any buffer
2009-02-21 22:53 ` Marc Tfardy
@ 2009-02-21 23:37 ` Richard Riley
0 siblings, 0 replies; 12+ messages in thread
From: Richard Riley @ 2009-02-21 23:37 UTC (permalink / raw)
To: help-gnu-emacs
Marc Tfardy <m-t-o___CUT__IT@web.de> writes:
> Rodrigo Lazo schrieb:
>> Hi all,
>>
>> Is there a way to compute a math expression on any buffer? I mean, if I
>> have a buffer with the following expression
>>
>> 2 + 3
>>
>> I want to mark the region and compute the result
>>
>> 2 + 3 = 5
>>
>> It doesn't seems too hard to do, I've looked on calculator.el for a
>> "computing" function I can call but I didn't find it.
>
> Try with embeded mode of calc: C-x * E (no need to mark the region)
> and similar commands (J or W in place of E). You need to type C-x * E
> again to exit the embeded mode.
>
>
> Another solution:
>
> - mark the region with math expression and put it into kill-ring (M-w)
> - type SPC = SPC
> - run the calc (C-x * c)
> - type ' (apostrophe) and yank yor math expression (C-y)
> - type RET
> - type y (or C-x * y) to copy the result into buffer
> - exit calc (q)
>
>
> regards
> marc
>
>
You might consider using "anything". There is a plugin
"anything-c-source-calculation-result".
http://www.emacswiki.org/emacs/Anything
http://www.emacswiki.org/emacs-en/init-anything.el
--
important and urgent problems of the technology of today are no longer the satisfactions of the primary needs or of archetypal wishes, but the reparation of the evils and damages by the technology of yesterday. ~Dennis Gabor, Innovations: Scientific, Technological and Social, 1970
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Quick math calc on any buffer
[not found] <mailman.1378.1235234577.31690.help-gnu-emacs@gnu.org>
2009-02-21 19:08 ` Quick math calc on any buffer B. T. Raven
2009-02-21 22:53 ` Marc Tfardy
@ 2009-02-22 12:45 ` Scott Frazer
2009-02-22 14:30 ` Rodrigo Lazo
` (2 more replies)
2 siblings, 3 replies; 12+ messages in thread
From: Scott Frazer @ 2009-02-22 12:45 UTC (permalink / raw)
To: help-gnu-emacs
On Feb 21, 11:42 am, Rodrigo Lazo <rlazo....@gmail.com> wrote:
> Hi all,
>
> Is there a way to compute a math expression on any buffer? I mean, if I
> have a buffer with the following expression
>
> 2 + 3
>
> I want to mark the region and compute the result
>
> 2 + 3 = 5
>
> It doesn't seems too hard to do, I've looked on calculator.el for a
> "computing" function I can call but I didn't find it.
>
(defun my-calc-result (beg end)
(interactive "r")
(insert " = " (calc-eval (buffer-substring beg end))))
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Quick math calc on any buffer
2009-02-22 12:45 ` Scott Frazer
@ 2009-02-22 14:30 ` Rodrigo Lazo
2009-02-22 17:16 ` Marc Tfardy
2009-02-24 23:20 ` Chetan
2 siblings, 0 replies; 12+ messages in thread
From: Rodrigo Lazo @ 2009-02-22 14:30 UTC (permalink / raw)
To: help-gnu-emacs
Scott Frazer <frazer.scott@gmail.com> writes:
> On Feb 21, 11:42 am, Rodrigo Lazo <rlazo....@gmail.com> wrote:
>> Hi all,
>>
>> Is there a way to compute a math expression on any buffer? I mean, if I
>> have a buffer with the following expression
>>
>> 2 + 3
>>
>> I want to mark the region and compute the result
>>
>> 2 + 3 = 5
>>
>> It doesn't seems too hard to do, I've looked on calculator.el for a
>> "computing" function I can call but I didn't find it.
>>
>
> (defun my-calc-result (beg end)
> (interactive "r")
> (insert " = " (calc-eval (buffer-substring beg end))))
>
Excellent! that is exactly what I was looking for.
Thanks a lot
--
Rodrigo Lazo (rlazo)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Quick math calc on any buffer
2009-02-22 12:45 ` Scott Frazer
2009-02-22 14:30 ` Rodrigo Lazo
@ 2009-02-22 17:16 ` Marc Tfardy
2009-02-24 23:20 ` Chetan
2 siblings, 0 replies; 12+ messages in thread
From: Marc Tfardy @ 2009-02-22 17:16 UTC (permalink / raw)
To: help-gnu-emacs
Scott Frazer schrieb:
> On Feb 21, 11:42 am, Rodrigo Lazo <rlazo....@gmail.com> wrote:
>> Hi all,
>>
>> Is there a way to compute a math expression on any buffer? I mean, if I
>> have a buffer with the following expression
>>
>> 2 + 3
>>
>> I want to mark the region and compute the result
>>
>> 2 + 3 = 5
>>
>> It doesn't seems too hard to do, I've looked on calculator.el for a
>> "computing" function I can call but I didn't find it.
>>
>
> (defun my-calc-result (beg end)
> (interactive "r")
> (insert " = " (calc-eval (buffer-substring beg end))))
Great! Much more elegant than my last attempt:
(defun my-calc-result2 (beg end)
(interactive "r")
(insert " = " (number-to-string (apply 'eval (math-read-exprs
(buffer-substring beg end))))))
regards
marc
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Quick math calc on any buffer
2009-02-22 12:45 ` Scott Frazer
2009-02-22 14:30 ` Rodrigo Lazo
2009-02-22 17:16 ` Marc Tfardy
@ 2009-02-24 23:20 ` Chetan
2009-02-24 23:29 ` Marc Tfardy
2 siblings, 1 reply; 12+ messages in thread
From: Chetan @ 2009-02-24 23:20 UTC (permalink / raw)
To: help-gnu-emacs
Scott Frazer <frazer.scott@gmail.com> writes:
> On Feb 21, 11:42 am, Rodrigo Lazo <rlazo....@gmail.com> wrote:
>> Hi all,
>>
>> Is there a way to compute a math expression on any buffer? I mean, if I
>> have a buffer with the following expression
>>
>> 2 + 3
>>
>> I want to mark the region and compute the result
>>
>> 2 + 3 = 5
>>
>> It doesn't seems too hard to do, I've looked on calculator.el for a
>> "computing" function I can call but I didn't find it.
>>
>
> (defun my-calc-result (beg end)
> (interactive "r")
> (insert " = " (calc-eval (buffer-substring beg end))))
This makes me wonder, is there a rewriter of math expressions,
something like a macro that can rewrite the arithmetic expression as
regular lisp function calls?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Quick math calc on any buffer
2009-02-24 23:20 ` Chetan
@ 2009-02-24 23:29 ` Marc Tfardy
2009-02-25 0:22 ` Chetan
0 siblings, 1 reply; 12+ messages in thread
From: Marc Tfardy @ 2009-02-24 23:29 UTC (permalink / raw)
To: help-gnu-emacs
Chetan schrieb:
> Scott Frazer <frazer.scott@gmail.com> writes:
>
>> On Feb 21, 11:42 am, Rodrigo Lazo <rlazo....@gmail.com> wrote:
>>> Hi all,
>>>
>>> Is there a way to compute a math expression on any buffer? I mean, if I
>>> have a buffer with the following expression
>>>
>>> 2 + 3
>>>
>>> I want to mark the region and compute the result
>>>
>>> 2 + 3 = 5
>>>
>>> It doesn't seems too hard to do, I've looked on calculator.el for a
>>> "computing" function I can call but I didn't find it.
>>>
>> (defun my-calc-result (beg end)
>> (interactive "r")
>> (insert " = " (calc-eval (buffer-substring beg end))))
> This makes me wonder, is there a rewriter of math expressions,
> something like a macro that can rewrite the arithmetic expression as
> regular lisp function calls?
Yes. See my last post before. The call:
(math-read-exprs "2 + 3")
gives:
((+ 2 3))
This was my attempt in my version of my-calc-result.
reagrds
Marc
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Quick math calc on any buffer
2009-02-24 23:29 ` Marc Tfardy
@ 2009-02-25 0:22 ` Chetan
0 siblings, 0 replies; 12+ messages in thread
From: Chetan @ 2009-02-25 0:22 UTC (permalink / raw)
To: help-gnu-emacs
Marc Tfardy <m-t-o___CUT__IT@web.de> writes:
> Chetan schrieb:
>> Scott Frazer <frazer.scott@gmail.com> writes:
>>
>>> On Feb 21, 11:42 am, Rodrigo Lazo <rlazo....@gmail.com> wrote:
>>>> Hi all,
>>>>
>>>> Is there a way to compute a math expression on any buffer? I mean, if I
>>>> have a buffer with the following expression
>>>>
>>>> 2 + 3
>>>>
>>>> I want to mark the region and compute the result
>>>>
>>>> 2 + 3 = 5
>>>>
>>>> It doesn't seems too hard to do, I've looked on calculator.el for a
>>>> "computing" function I can call but I didn't find it.
>>>>
>>> (defun my-calc-result (beg end)
>>> (interactive "r")
>>> (insert " = " (calc-eval (buffer-substring beg end))))
>
>> This makes me wonder, is there a rewriter of math expressions,
>> something like a macro that can rewrite the arithmetic expression as
>> regular lisp function calls?
>
> Yes. See my last post before. The call:
>
> (math-read-exprs "2 + 3")
>
> gives:
>
> ((+ 2 3))
>
> This was my attempt in my version of my-calc-result.
>
> reagrds
> Marc
I was thinking more like
(expr 2 + 3 + value) => (+ 2 3 value)
or (expr a + b * c) => (+ a (* b c))
which is, perhaps, simpler than reading from a string.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Quick math calc on any buffer
@ 2009-02-24 15:25 Xavier Maillard
0 siblings, 0 replies; 12+ messages in thread
From: Xavier Maillard @ 2009-02-24 15:25 UTC (permalink / raw)
To: Marc Tfardy; +Cc: help-gnu-emacs
Hi,
> (defun my-calc-result (beg end)
> (interactive "r")
> (insert " = " (calc-eval (buffer-substring beg end))))
Great! Much more elegant than my last attempt:
(defun my-calc-result2 (beg end)
(interactive "r")
(insert " = " (number-to-string (apply 'eval (math-read-exprs
(buffer-substring beg end))))))
This works partially and insert the result in the wrong place if
you mark the region in the inverse order -i.e beg is end and end
is beg.
Regards,
Xavier
--
http://www.gnu.org
http://www.april.org
http://www.lolica.org
^ permalink raw reply [flat|nested] 12+ messages in thread
* Quick math calc on any buffer
@ 2009-02-21 16:42 Rodrigo Lazo
0 siblings, 0 replies; 12+ messages in thread
From: Rodrigo Lazo @ 2009-02-21 16:42 UTC (permalink / raw)
To: help-gnu-emacs
Hi all,
Is there a way to compute a math expression on any buffer? I mean, if I
have a buffer with the following expression
2 + 3
I want to mark the region and compute the result
2 + 3 = 5
It doesn't seems too hard to do, I've looked on calculator.el for a
"computing" function I can call but I didn't find it.
Regards
--
Rodrigo Lazo (rlazo)
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2009-02-25 0:22 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.1378.1235234577.31690.help-gnu-emacs@gnu.org>
2009-02-21 19:08 ` Quick math calc on any buffer B. T. Raven
2009-02-21 19:50 ` Thierry Volpiatto
2009-02-21 22:53 ` Marc Tfardy
2009-02-21 23:37 ` Richard Riley
2009-02-22 12:45 ` Scott Frazer
2009-02-22 14:30 ` Rodrigo Lazo
2009-02-22 17:16 ` Marc Tfardy
2009-02-24 23:20 ` Chetan
2009-02-24 23:29 ` Marc Tfardy
2009-02-25 0:22 ` Chetan
2009-02-24 15:25 Xavier Maillard
-- strict thread matches above, loose matches on Subject: below --
2009-02-21 16:42 Rodrigo Lazo
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.