From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chetan Newsgroups: gmane.emacs.help Subject: Re: Quick math calc on any buffer Date: Tue, 24 Feb 2009 16:22:14 -0800 Organization: Noname Inc. Message-ID: References: <866ac838-c9b2-4507-acca-08df9ddf5b94@l1g2000yqj.googlegroups.com> <70je6rFa1ksvU1@mid.individual.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1235522449 17475 80.91.229.12 (25 Feb 2009 00:40:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 25 Feb 2009 00:40:49 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Feb 25 01:42:05 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Lc7qY-0002RI-F4 for geh-help-gnu-emacs@m.gmane.org; Wed, 25 Feb 2009 01:41:58 +0100 Original-Received: from localhost ([127.0.0.1]:46527 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lc7pD-0000Xr-Po for geh-help-gnu-emacs@m.gmane.org; Tue, 24 Feb 2009 19:40:35 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!newshub.sdsu.edu!flph200.ffdc.sbc.com!prodigy.net!flph199.ffdc.sbc.com!prodigy.com!flpi107.ffdc.sbc.com!nlpi064.nbdc.sbc.com.POSTED!8e1d8614!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Emacs Gnus Cancel-Lock: sha1:wYF0RyI+DED1t3Jp7sbbLxSO++w= Original-Lines: 44 Original-NNTP-Posting-Host: 76.200.183.58 Original-X-Complaints-To: abuse@prodigy.net Original-X-Trace: nlpi064.nbdc.sbc.com 1235521339 ST000 76.200.183.58 (Tue, 24 Feb 2009 19:22:19 EST) Original-NNTP-Posting-Date: Tue, 24 Feb 2009 19:22:19 EST X-UserInfo1: [[PGGVCE[BWASVDY[ZOD]_\@VR]^@B@MCPWZKB]MPXHBTWICYFWUQBKZQLYJX\_ITFD_KFVLUN[DOM_A_NSYNWPFWNS[XV\I]PZ@BQ[@CDQDPCL^FKCBIPC@KLGEZEFNMDYMKHRL_YYYGDSSODXYN@[\BK[LVTWI@AXGQCOA_SAH@TPD^\AL\RLGRFWEARBM Original-Xref: news.stanford.edu gnu.emacs.help:167045 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:62342 Archived-At: Marc Tfardy writes: > Chetan schrieb: >> Scott Frazer writes: >> >>> On Feb 21, 11:42 am, 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. >>>> >>> (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.