From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Table rows and ranges as LHS of formulas Date: Tue, 1 Mar 2011 15:28:07 +0100 Message-ID: <5A22097F-A1F9-480E-B2E5-030CD6493B2F@gmail.com> Mime-Version: 1.0 (Apple Message framework v1078) Content-Type: multipart/mixed; boundary=Apple-Mail-11-707424296 Return-path: Received: from [140.186.70.92] (port=53621 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PuQZs-00063c-LO for emacs-orgmode@gnu.org; Tue, 01 Mar 2011 09:29:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PuQZr-0001Xs-Hu for emacs-orgmode@gnu.org; Tue, 01 Mar 2011 09:29:28 -0500 Received: from mail-ew0-f41.google.com ([209.85.215.41]:36631) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PuQZr-0001XF-3E for emacs-orgmode@gnu.org; Tue, 01 Mar 2011 09:29:27 -0500 Received: by ewy10 with SMTP id 10so1733517ewy.0 for ; Tue, 01 Mar 2011 06:29:26 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode List --Apple-Mail-11-707424296 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Hi everyone, A frequently requested feature for tables has been to be able to define row formulas in a way similar to column formulas. The patch below allows things like @3= @2$2..@5$7= @I$2..@II$4= as the left hand side for table formulas in order to write a formula that is valid for an entire column or for a rectangular section in a table. Note that in contrast to column formulas, @3= will not automatically skip a "header column" or field formulas in the same row. In fact, making both a range formula and a field point to the same field is forbidden and throws an error. So to have a formula apply to all but the first column, use something like this: @3$2..@3$8=.... Testing is welcome, but I am confident that this works pretty well. Bastien, please let me know if you want to have this integrated before the release, then I will do so. --Apple-Mail-11-707424296 Content-Disposition: attachment; filename=0001-Implement-table-formulas-that-apply-to-field-ranges.patch Content-Type: application/octet-stream; name="0001-Implement-table-formulas-that-apply-to-field-ranges.patch" Content-Transfer-Encoding: quoted-printable =46rom=20a8bfe81b33c4eeb5a46482c5435ace68d5c6ccf3=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Carsten=20Dominik=20= =0ADate:=20Tue,=201=20Mar=202011=2009:05:56=20= +0100=0ASubject:=20[PATCH]=20Implement=20table=20formulas=20that=20apply=20= to=20field=20ranges=0A=0A*=20lisp/org-table.el=20= (org-table-fedit-finish):=20Read=20more=20general=20LHS=20of=20formulas.=0A= (org-table-current-ncol):=20New=20variable.=0A(org-table-line-to-dline):=20= New=20function.=0A(org-table-get-stored-formulas):=20Accept=20range=20= formulas=20as=20matches.=0A(org-table-get-specials):=20Compute=20and=20= store=20the=20number=20of=20columns.=0A(org-table-get-range):=20New=20= optional=20argument=20CORNERS-ONLY,=20to=20retrieve=0Aonly=20the=20= region=20marked=20by=20the=20range,=20not=20the=20content.=0A= (org-table-recalculate):=20Call=20`org-table-expand-lhs-ranges'=20to=20= expand=0Arange=20targets.=20=20Also=20check=20for=20duplicate=20access=20= to=20fields.=0A(org-table-expand-lhs-ranges):=20New=20funktion.=0A= (org-table-get-remote-range):=20Bind=20`org-table-current-ncol'=20to=20= protect=0Athe=20caller's=20value.=0A(org-table-edit-formulas):=20Support=20= highlighting=20of=20range=20targets.=0A=0A*=20doc/org.texi=20(Field=20= and=20range=20formulas):=20Renamed=20from=20"Field=20formulas".=0A= Document=20the=20use=20of=20range=20operators=20as=20targets.=0A---=0A=20= doc/org.texi=20=20=20=20=20=20|=20=20=2033=20+++++++++----=0A=20= lisp/org-table.el=20|=20=20140=20= ++++++++++++++++++++++++++++++++++++++++++----------=0A=202=20files=20= changed,=20136=20insertions(+),=2037=20deletions(-)=0A=0Adiff=20--git=20= a/doc/org.texi=20b/doc/org.texi=0Aindex=205288604..f5fa976=20100644=0A= ---=20a/doc/org.texi=0A+++=20b/doc/org.texi=0A@@=20-378,7=20+378,7=20@@=20= The=20spreadsheet=0A=20*=20References::=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20How=20to=20refer=20to=20another=20field=20or=20range=0A= =20*=20Formula=20syntax=20for=20Calc::=20=20=20=20=20Using=20Calc=20to=20= compute=20stuff=0A=20*=20Formula=20syntax=20for=20Lisp::=20=20=20=20=20= Writing=20formulas=20in=20Emacs=20Lisp=0A-*=20Field=20formulas::=20=20=20= =20=20=20=20=20=20=20=20=20=20=20Formulas=20valid=20for=20a=20single=20= field=0A+*=20Field=20and=20range=20formulas::=20=20=20=20Formula=20for=20= specific=20(ranges=20of)=20fields=0A=20*=20Column=20formulas::=20=20=20=20= =20=20=20=20=20=20=20=20=20Formulas=20valid=20for=20an=20entire=20column=0A= =20*=20Editing=20and=20debugging=20formulas::=20=20Fixing=20formulas=0A=20= *=20Updating=20the=20table::=20=20=20=20=20=20=20=20=20=20Recomputing=20= all=20dependent=20fields=0A@@=20-670,6=20+670,8=20@@=20Specific=20header=20= arguments=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20directory=20for=20code=20block=20= execution=0A=20*=20exports::=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20Export=20code=20and/or=20results=0A=20*=20tangle::=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20Toggle=20= tangling=20and=20specify=20file=20name=0A+*=20mkdirp::=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20Toggle=20creation=20of=20= parent=20directories=20of=20target=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20files=20= during=20tangling=0A=20*=20comments::=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20Toggle=20insertion=20of=20comments=20in=20= tangled=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20code=20files=0A=20*=20no-expand::=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20Turn=20off=20variable=20= assignment=20and=20noweb=0A@@=20-677,7=20+679,7=20@@=20Specific=20header=20= arguments=0A=20*=20session::=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20Preserve=20the=20state=20of=20code=20evaluation=0A=20*=20= noweb::=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20Toggle=20expansion=20of=20noweb=20references=0A=20*=20cache::=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20Avoid=20= re-evaluating=20unchanged=20code=20blocks=0A-*=20sep::=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20Specify=20= delimiter=20for=20writing=20external=20tables=0A+*=20sep::=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20Delimiter=20= for=20writing=20tabular=20results=20outside=20Org=0A=20*=20hlines::=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20Handle=20= horizontal=20lines=20in=20tables=0A=20*=20colnames::=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20Handle=20column=20names=20in=20= tables=0A=20*=20rownames::=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20Handle=20row=20names=20in=20tables=0A@@=20-2243,7=20+2245,7=20= @@=20formula,=20moving=20these=20references=20by=20arrow=20keys=0A=20*=20= References::=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20How=20= to=20refer=20to=20another=20field=20or=20range=0A=20*=20Formula=20syntax=20= for=20Calc::=20=20=20=20=20Using=20Calc=20to=20compute=20stuff=0A=20*=20= Formula=20syntax=20for=20Lisp::=20=20=20=20=20Writing=20formulas=20in=20= Emacs=20Lisp=0A-*=20Field=20formulas::=20=20=20=20=20=20=20=20=20=20=20=20= =20=20Formulas=20valid=20for=20a=20single=20field=0A+*=20Field=20and=20= range=20formulas::=20=20=20=20Formula=20for=20specific=20(ranges=20of)=20= fields=0A=20*=20Column=20formulas::=20=20=20=20=20=20=20=20=20=20=20=20=20= Formulas=20valid=20for=20an=20entire=20column=0A=20*=20Editing=20and=20= debugging=20formulas::=20=20Fixing=20formulas=0A=20*=20Updating=20the=20= table::=20=20=20=20=20=20=20=20=20=20Recomputing=20all=20dependent=20= fields=0A@@=20-2501,7=20+2503,7=20@@=20Calc=20also=20contains=20a=20= complete=20set=20of=20logical=20operations.=20=20For=20example=0A=20= if($1<20,teen,string(""))=20=20@r{``teen''=20if=20age=20$1=20less=20than=20= 20,=20else=20empty}=0A=20@end=20example=0A=20=0A-@node=20Formula=20= syntax=20for=20Lisp,=20Field=20formulas,=20Formula=20syntax=20for=20= Calc,=20The=20spreadsheet=0A+@node=20Formula=20syntax=20for=20Lisp,=20= Field=20and=20range=20formulas,=20Formula=20syntax=20for=20Calc,=20The=20= spreadsheet=0A=20@subsection=20Emacs=20Lisp=20forms=20as=20formulas=0A=20= @cindex=20Lisp=20forms,=20as=20table=20formulas=0A=20=0A@@=20-2532,10=20= +2534,12=20@@=20like=20@code{"$3"}.=20=20Ranges=20are=20inserted=20as=20= space-separated=20fields,=20so=20you=20can=0A=20=20=20'(apply=20'+=20= '($1..$4));N=0A=20@end=20example=0A=20=0A-@node=20Field=20formulas,=20= Column=20formulas,=20Formula=20syntax=20for=20Lisp,=20The=20spreadsheet=0A= -@subsection=20Field=20formulas=0A+@node=20Field=20and=20range=20= formulas,=20Column=20formulas,=20Formula=20syntax=20for=20Lisp,=20The=20= spreadsheet=0A+@subsection=20Field=20and=20range=20formulas=0A=20@cindex=20= field=20formula=0A+@cindex=20range=20formula=0A=20@cindex=20formula,=20= for=20individual=20table=20field=0A+@cindex=20formula,=20for=20range=20= of=20fields=0A=20=0A=20To=20assign=20a=20formula=20to=20a=20particular=20= field,=20type=20it=20directly=20into=20the=0A=20field,=20preceded=20by=20= @samp{:=3D},=20for=20example=20@samp{:=3D$1+$2}.=20=20When=20you=0A@@=20= -2565,7=20+2569,14=20@@=20formula=20with=20default=20taken=20from=20the=20= @samp{#+TBLFM:}=20line,=20applies=0A=20it=20to=20the=20current=20field,=20= and=20stores=20it.=0A=20@end=20table=0A=20=0A-@node=20Column=20formulas,=20= Editing=20and=20debugging=20formulas,=20Field=20formulas,=20The=20= spreadsheet=0A+The=20left=20hand=20side=20of=20the=20formula=20may=20= also=20be=20a=20column=20or=20range=20reference=20in=0A+order=20to=20= assign=20the=20same=20formula=20to=20a=20range=20of=20fields.=20=20These=20= formulas=20can=0A+only=20be=20entered=20directly=20in=20the=20= @code{#+TBLFM:}=20line,=20or=20by=20using=20the=20formula=0A+editor=20= (@pxref{Editing=20and=20debugging=20formulas}).=20=20For=20example=20= @code{@@5=3D...}=0A+will=20define=20a=20formula=20for=20all=20fields=20= in=20row=205,=20and=20@code{@@1$1..@@2$2=3D...}=20will=0A+define=20a=20= formula=20for=20the=20four=20fields=20in=20the=20rectangle.=0A+=0A+@node=20= Column=20formulas,=20Editing=20and=20debugging=20formulas,=20Field=20and=20= range=20formulas,=20The=20spreadsheet=0A=20@subsection=20Column=20= formulas=0A=20@cindex=20column=20formula=0A=20@cindex=20formula,=20for=20= table=20column=0A@@=20-2575,7=20+2586,9=20@@=20particular=20column.=20=20= Instead=20of=20having=20to=20copy=20the=20formula=20to=20all=20fields=0A=20= in=20that=20column,=20Org=20allows=20you=20to=20assign=20a=20single=20= formula=20to=20an=20entire=0A=20column.=20=20If=20the=20table=20contains=20= horizontal=20separator=20hlines,=20everything=0A=20before=20the=20first=20= such=20line=20is=20considered=20part=20of=20the=20table=20@emph{header}=0A= -and=20will=20not=20be=20modified=20by=20column=20formulas.=0A+and=20= will=20not=20be=20modified=20by=20column=20formulas.=20=20Also,=20fields=20= that=20have=0A+individual=20field=20or=20range=20formulas=20assigning=20= to=20them=20will=20be=20skipped=20by=0A+column=20formulas.=0A=20=0A=20To=20= assign=20a=20formula=20to=20a=20column,=20type=20it=20directly=20into=20= any=20field=20in=20the=0A=20column,=20preceded=20by=20an=20equal=20sign,=20= like=20@samp{=3D$1+$2}.=20=20When=20you=20press=0A@@=20-2617,7=20+2630,7=20= @@=20if=20possible.=20=20If=20you=20prefer=20to=20only=20work=20with=20= the=20internal=20format=20(like=0A=20@table=20@kbd=0A=20@orgcmdkkc{C-c=20= =3D,C-u=20C-c=20=3D,org-table-eval-formula}=0A=20Edit=20the=20formula=20= associated=20with=20the=20current=20column/field=20in=20the=0A= -minibuffer.=20=20See=20@ref{Column=20formulas},=20and=20@ref{Field=20= formulas}.=0A+minibuffer.=20=20See=20@ref{Column=20formulas},=20and=20= @ref{Field=20and=20range=20formulas}.=0A=20@orgcmd{C-u=20C-u=20C-c=20= =3D,org-table-eval-formula}=0A=20Re-insert=20the=20active=20formula=20= (either=20a=0A=20field=20formula,=20or=20a=20column=20formula)=20into=20= the=20current=20field,=20so=20that=20you=0A@@=20-2720,7=20+2733,7=20@@=20= following=20commands:=0A=20@table=20@kbd=0A=20@orgcmd{C-c=20= *,org-table-recalculate}=0A=20Recalculate=20the=20current=20row=20by=20= first=20applying=20the=20stored=20column=20formulas=0A-from=20left=20to=20= right,=20and=20all=20field=20formulas=20in=20the=20current=20row.=0A= +from=20left=20to=20right,=20and=20all=20field/range=20formulas=20in=20= the=20current=20row.=0A=20@c=0A=20@kindex=20C-u=20C-c=20*=0A=20@item=20= C-u=20C-c=20*=0Adiff=20--git=20a/lisp/org-table.el=20b/lisp/org-table.el=0A= index=2056d927e..d4ae2b1=20100644=0A---=20a/lisp/org-table.el=0A+++=20= b/lisp/org-table.el=0A@@=20-316,6=20+316,8=20@@=20available=20= parameters."=0A=20=20=20"Table=20begin=20line,=20non-nil=20only=20for=20= the=20duration=20of=20a=20command.")=0A=20(defvar=20= org-table-current-begin-pos=20nil=0A=20=20=20"Table=20begin=20position,=20= non-nil=20only=20for=20the=20duration=20of=20a=20command.")=0A+(defvar=20= org-table-current-ncol=20nil=0A+=20=20"Number=20of=20columns=20in=20= table,=20non-nil=20only=20for=20the=20duration=20of=20a=20command.")=0A=20= (defvar=20org-table-dlines=20nil=0A=20=20=20"Vector=20of=20data=20line=20= line=20numbers=20in=20the=20current=20table.")=0A=20(defvar=20= org-table-hlines=20nil=0A@@=20-1246,6=20+1248,28=20@@=20However,=20when=20= FORCE=20is=20non-nil,=20create=20new=20columns=20if=20necessary."=0A=20=09= (error=0A=20=09=20"Please=20position=20cursor=20in=20a=20data=20line=20= for=20column=20operations")))))=0A=20=0A+(defun=20= org-table-line-to-dline=20(line=20&optional=20above)=0A+=20=20"Turn=20a=20= buffer=20line=20number=20into=20a=20data=20line=20number.=0A+If=20there=20= is=20no=20data=20line=20in=20this=20line,=20return=20nil.=0A+If=20there=20= is=20no=20matchin=20dline=20(most=20likely=20te=20refrence=20was=20a=20= hline),=20the=0A+first=20dline=20below=20it=20is=20used.=20=20When=20= ABOVE=20is=20non-nil,=20the=20one=20above=20is=20used."=0A+=20=20(catch=20= 'exit=0A+=20=20=20=20(let=20((ll=20(length=20org-table-dlines))=0A+=09=20= =20i)=0A+=20=20=20=20=20=20(if=20above=0A+=09=20=20(progn=0A+=09=20=20=20= =20(setq=20i=20(1-=20ll))=0A+=09=20=20=20=20(while=20(>=20i=200)=0A+=09=20= =20=20=20=20=20(if=20(<=3D=20(aref=20org-table-dlines=20i)=20line)=0A+=09= =09=20=20(throw=20'exit=20i))=0A+=09=20=20=20=20=20=20(setq=20i=20(1-=20= i))))=0A+=09(setq=20i=201)=0A+=09(while=20(<=20i=20ll)=0A+=09=20=20(if=20= (>=3D=20(aref=20org-table-dlines=20i)=20line)=0A+=09=20=20=20=20=20=20= (throw=20'exit=20i))=0A+=09(setq=20i=20(1+=20i)))))=0A+=20=20=20=20=20=20= nil))=0A+=0A=20(defun=20org-table-delete-column=20()=0A=20=20=20"Delete=20= a=20column=20from=20the=20table."=0A=20=20=20(interactive)=0A@@=20= -1966,7=20+1990,7=20@@=20When=20NAMED=20is=20non-nil,=20look=20for=20a=20= named=20equation."=0A=20=20=20=20=20=20=20(when=20(looking-at=20"\\([=20= \t]*\n\\)*[=20\t]*#\\+TBLFM:=20*\\(.*\\)")=0A=20=09(setq=20strings=20= (org-split-string=20(match-string=202)=20"=20*::=20*"))=0A=20=09(while=20= (setq=20string=20(pop=20strings))=0A-=09=20=20(when=20(string-match=20= "\\`\\(@[0-9]+\\$[0-9]+\\|\\$\\([a-zA-Z0-9]+\\)\\)=20*=3D=20*\\(.*[^=20= \t]\\)"=20string)=0A+=09=20=20(when=20(string-match=20"\\`\\(@[^=3D=20= \t\n]+\\|\\$\\([a-zA-Z0-9]+\\)\\)=20*=3D=20*\\(.*[^=20\t]\\)"=20string)=0A= =20=09=20=20=20=20(setq=20scol=20(if=20(match-end=202)=0A=20=09=09=09=20=20= =20(match-string=202=20string)=0A=20=09=09=09=20(match-string=201=20= string))=0A@@=20-2022,7=20+2046,8=20@@=20For=20all=20numbers=20larger=20= than=20LIMIT,=20shift=20them=20by=20DELTA."=0A=20=09=20=20=20=20= org-table-named-field-locations=20nil=0A=20=09=20=20=20=20= org-table-current-begin-line=20nil=0A=20=09=20=20=20=20= org-table-current-begin-pos=20nil=0A-=09=20=20=20=20= org-table-current-line-types=20nil)=0A+=09=20=20=20=20= org-table-current-line-types=20nil=0A+=09=20=20=20=20= org-table-current-ncol=200)=0A=20=20=20=20=20=20=20(goto-char=20beg)=0A=20= =20=20=20=20=20=20(when=20(re-search-forward=20"^[=20\t]*|=20*!=20= *\\(|.*\\)"=20end=20t)=0A=20=09(setq=20names=20(org-split-string=20= (match-string=201)=20"=20*|=20*")=0A@@=20-2078,6=20+2103,7=20@@=20For=20= all=20numbers=20larger=20than=20LIMIT,=20shift=20them=20by=20DELTA."=0A=20= =09=09=20=20=20=20=20=20"[=20\t]*|[=20\t]*"))=0A=20=09=20=20=20=20=20= (nfields=20(length=20fields))=0A=20=09=20=20=20=20=20al=20al2)=0A+=09= (setq=20org-table-current-ncol=20nfields)=0A=20=09(loop=20for=20i=20from=20= 1=20to=20nfields=20do=0A=20=09=20=20=20=20=20=20(push=20(list=20(format=20= "LR%d"=20i)=20l=20i)=20al)=0A=20=09=20=20=20=20=20=20(push=20(cons=20= (format=20"LR%d"=20i)=20(nth=20(1-=20i)=20fields))=20al2))=0A@@=20= -2415,11=20+2441,16=20@@=20$1->=20=20=20=20%s\n"=20orig=20formula=20= form0=20form))=0A=20=09=09=20=20=20=20=20=20=20(progn=20= (skip-chars-forward=20"^|")=20(point))=0A=20=09=09=20=20=20=20=20=20=20= prop=20value)))=0A=20=0A-(defun=20org-table-get-range=20(desc=20= &optional=20tbeg=20col=20highlight)=0A+(defun=20org-table-get-range=20= (desc=20&optional=20tbeg=20col=20highlight=20corners-only)=0A=20=20=20= "Get=20a=20calc=20vector=20from=20a=20column,=20according=20to=20= descriptor=20DESC.=0A=20Optional=20arguments=20TBEG=20and=20COL=20can=20= give=20the=20beginning=20of=20the=20table=20and=0A=20the=20current=20= column,=20to=20avoid=20unnecessary=20parsing.=0A-HIGHLIGHT=20means=20= just=20highlight=20the=20range."=0A+=0A+HIGHLIGHT=20means=20just=20= highlight=20the=20range.=0A+=0A+When=20CORNERS-ONLY=20is=20set,=20only=20= return=20the=20corners=20of=20the=20range=20as=0A+a=20list=20(line1=20= column1=20line2=20column2)=20where=20line1=20and=20line2=20are=20line=20= numbers=0A+in=20the=20buffer=20and=20column1=20and=20column2=20are=20= table=20column=20numbers."=0A=20=20=20(if=20(not=20(equal=20= (string-to-char=20desc)=20?@))=0A=20=20=20=20=20=20=20(setq=20desc=20= (concat=20"@"=20desc)))=0A=20=20=20(save-excursion=0A@@=20-2448,7=20= +2479,8=20@@=20HIGHLIGHT=20means=20just=20highlight=20the=20range."=0A=20= =20=20=20=20=20=20(if=20(not=20r2)=20(setq=20r2=20thisline))=0A=20=20=20=20= =20=20=20(if=20(not=20c1)=20(setq=20c1=20col))=0A=20=20=20=20=20=20=20= (if=20(not=20c2)=20(setq=20c2=20col))=0A-=20=20=20=20=20=20(if=20(or=20= (not=20rangep)=20(and=20(=3D=20r1=20r2)=20(=3D=20c1=20c2)))=0A+=20=20=20=20= =20=20(if=20(and=20(not=20corners-only)=0A+=09=20=20=20=20=20=20=20(or=20= (not=20rangep)=20(and=20(=3D=20r1=20r2)=20(=3D=20c1=20c2))))=0A=20=09=20=20= ;;=20just=20one=20field=0A=20=09=20=20(progn=0A=20=09=20=20=20=20= (org-goto-line=20r1)=0A@@=20-2460,22=20+2492,26=20@@=20HIGHLIGHT=20means=20= just=20highlight=20the=20range."=0A=20=09;;=20First=20sort=20the=20= numbers=20to=20get=20a=20regular=20ractangle=0A=20=09(if=20(<=20r2=20r1)=20= (setq=20tmp=20r1=20r1=20r2=20r2=20tmp))=0A=20=09(if=20(<=20c2=20c1)=20= (setq=20tmp=20c1=20c1=20c2=20c2=20tmp))=0A-=09(org-goto-line=20r1)=0A-=09= (while=20(not=20(looking-at=20org-table-dataline-regexp))=0A-=09=20=20= (beginning-of-line=202))=0A-=09(org-table-goto-column=20c1)=0A-=09(setq=20= beg=20(point))=0A-=09(org-goto-line=20r2)=0A-=09(while=20(not=20= (looking-at=20org-table-dataline-regexp))=0A-=09=20=20(beginning-of-line=20= 0))=0A-=09(org-table-goto-column=20c2)=0A-=09(setq=20end=20(point))=0A-=09= (if=20highlight=0A-=09=20=20=20=20(org-table-highlight-rectangle=0A-=09=20= =20=20=20=20beg=20(progn=20(skip-chars-forward=20"^|\n")=20(point))))=0A= -=09;;=20return=20string=20representation=20of=20calc=20vector=0A-=09= (mapcar=20'org-trim=0A-=09=09(apply=20'append=20(org-table-copy-region=20= beg=20end)))))))=0A+=09(if=20corners-only=0A+=09=20=20=20=20;;=20Only=20= return=20the=20corners=20of=20the=20range=0A+=09=20=20=20=20(list=20r1=20= c1=20r2=20c2)=0A+=09=20=20;;=20Copy=20the=20range=20values=20into=20a=20= list=0A+=09=20=20(org-goto-line=20r1)=0A+=09=20=20(while=20(not=20= (looking-at=20org-table-dataline-regexp))=0A+=09=20=20=20=20= (beginning-of-line=202))=0A+=09=20=20(org-table-goto-column=20c1)=0A+=09=20= =20(setq=20beg=20(point))=0A+=09=20=20(org-goto-line=20r2)=0A+=09=20=20= (while=20(not=20(looking-at=20org-table-dataline-regexp))=0A+=09=20=20=20= =20(beginning-of-line=200))=0A+=09=20=20(org-table-goto-column=20c2)=0A+=09= =20=20(setq=20end=20(point))=0A+=09=20=20(if=20highlight=0A+=09=20=20=20=20= =20=20(org-table-highlight-rectangle=0A+=09=20=20=20=20=20=20=20beg=20= (progn=20(skip-chars-forward=20"^|\n")=20(point))))=0A+=09=20=20;;=20= return=20string=20representation=20of=20calc=20vector=0A+=09=20=20= (mapcar=20'org-trim=0A+=09=09=20=20(apply=20'append=20= (org-table-copy-region=20beg=20end))))))))=0A=20=0A=20(defun=20= org-table-get-descriptor-line=20(desc=20&optional=20cline=20bline=20= table)=0A=20=20=20"Analyze=20descriptor=20DESC=20and=20retrieve=20the=20= corresponding=20line=20number.=0A@@=20-2595,7=20+2631,8=20@@=20known=20= that=20the=20table=20will=20be=20realigned=20a=20little=20later=20= anyway."=0A=20=09=20=20=20(line-re=20org-table-dataline-regexp)=0A=20=09=20= =20=20(thisline=20(org-current-line))=0A=20=09=20=20=20(thiscol=20= (org-table-current-column))=0A-=09=20=20=20beg=20end=20entry=20eqlnum=20= eqlname=20eqlname1=20eql=20(cnt=200)=20eq=20a=20name)=0A+=09=20=20=20= seen-fields=0A+=09=20=20=20beg=20end=20entry=20eqlnum=20eqlname=20= eqlname1=20eql=20(cnt=200)=20eq=20a=20name=20name1)=0A=20=20=20=20=20=20=20= ;;=20Insert=20constants=20in=20all=20formulas=0A=20=20=20=20=20=20=20= (setq=20eqlist=0A=20=09=20=20=20=20(mapcar=20(lambda=20(x)=0A@@=20= -2608,6=20+2645,10=20@@=20known=20that=20the=20table=20will=20be=20= realigned=20a=20little=20later=20anyway."=0A=20=09=20=20=20=20(push=20eq=20= eqlnum)=0A=20=09=20=20(push=20eq=20eqlname)))=0A=20=20=20=20=20=20=20= (setq=20eqlnum=20(nreverse=20eqlnum)=20eqlname=20(nreverse=20eqlname))=0A= +=20=20=20=20=20=20;;=20Expand=20ranges=20in=20lhs=20of=20formulas=0A+=20= =20=20=20=20=20(setq=20eqlname=20(org-table-expand-lhs-ranges=20= eqlname))=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20;;=20Get=20the=20= correct=20line=20range=20to=20process=0A=20=20=20=20=20=20=20(if=20all=0A= =20=09=20=20(progn=0A=20=09=20=20=20=20(setq=20end=20(move-marker=20= (make-marker)=20(1+=20(org-table-end))))=0A@@=20-2626,11=20+2667,19=20@@=20= known=20that=20the=20table=20will=20be=20realigned=20a=20little=20later=20= anyway."=0A=20=20=20=20=20=20=20(goto-char=20beg)=0A=20=20=20=20=20=20=20= (and=20all=20(message=20"Re-applying=20formulas=20to=20full=20= table..."))=0A=20=0A-=20=20=20=20=20=20;;=20First=20find=20the=20named=20= fields,=20and=20mark=20them=20untouchable=0A+=20=20=20=20=20=20;;=20= First=20find=20the=20named=20fields,=20and=20mark=20them=20untouchable.=0A= +=20=20=20=20=20=20;;=20Also=20check=20if=20several=20field/range=20= formulas=20try=20to=20set=20the=20same=20field.=0A=20=20=20=20=20=20=20= (remove-text-properties=20beg=20end=20'(org-untouchable=20t))=0A=20=20=20= =20=20=20=20(while=20(setq=20eq=20(pop=20eqlname))=0A=20=09(setq=20name=20= (car=20eq)=0A=20=09=20=20=20=20=20=20a=20(assoc=20name=20= org-table-named-field-locations))=0A+=09(setq=20name1=20name)=0A+=09(if=20= a=20(setq=20name1=20(format=20"@%d$%d"=20(org-table-line-to-dline=20(nth=20= 1=20a))=0A+=09=09=09=09=20=20(nth=202=20a))))=0A+=09(when=20(member=20= name1=20seen-fields)=0A+=09=20=20=20=20=20=20(error=20"Several=20= field/range=20formulas=20try=20to=20set=20%s"=20name1))=0A+=09(push=20= name1=20seen-fields)=0A+=09=20=20=0A=20=09(and=20(not=20a)=0A=20=09=20=20= =20=20=20(string-match=20"@\\([0-9]+\\)\\$\\([0-9]+\\)"=20name)=0A=20=09=20= =20=20=20=20(setq=20a=20(list=20name=0A@@=20-2646,7=20+2695,7=20@@=20= known=20that=20the=20table=20will=20be=20realigned=20a=20little=20later=20= anyway."=0A=20=09=20=20(org-table-goto-column=20(nth=202=20a))=0A=20=09=20= =20(push=20(append=20a=20(list=20(cdr=20eq)))=20eqlname1)=0A=20=09=20=20= (org-table-put-field-property=20:org-untouchable=20t)))=0A-=0A+=20=20=20=20= =20=20=0A=20=20=20=20=20=20=20;;=20Now=20evaluate=20the=20column=20= formulas,=20but=20skip=20fields=20covered=20by=0A=20=20=20=20=20=20=20;;=20= field=20formulas=0A=20=20=20=20=20=20=20(goto-char=20beg)=0A@@=20-2735,6=20= +2784,35=20@@=20known=20that=20the=20table=20will=20be=20realigned=20a=20= little=20later=20anyway."=0A=20=09=20=20=20=20=20(setq=20checksum=20= c1)))=0A=20=09=20(error=20"No=20convergence=20after=20%d=20iterations"=20= imax))))))=0A=20=0A+(defun=20org-table-expand-lhs-ranges=20(equations)=0A= +=20=20"Expand=20list=20of=20formulas.=0A+If=20some=20of=20the=20RHS=20= in=20the=20formulas=20are=20ranges=20or=20a=20row=20reference,=20expand=0A= +them=20to=20individual=20field=20equations=20for=20each=20field."=0A+=20= =20(let=20(e=20res=20lhs=20rhs=20range=20r1=20r2=20c1=20c2)=0A+=20=20=20=20= (while=20(setq=20e=20(pop=20equations))=0A+=20=20=20=20=20=20(setq=20lhs=20= (car=20e)=20rhs=20(cdr=20e))=0A+=20=20=20=20=20=20(cond=0A+=20=20=20=20=20= =20=20((string-match=20"^@-?[-+I0-9]+\\$-?[0-9]+$"=20lhs)=0A+=09;;=20= This=20just=20refers=20to=20one=20fixed=20field=0A+=09(push=20e=20res))=0A= +=20=20=20=20=20=20=20((string-match=20"^[a-zA-Z][a-zA-Z0-9]*$"=20lhs)=0A= +=09;;=20This=20just=20refers=20to=20one=20fixed=20named=20field=0A+=09= (push=20e=20res))=0A+=20=20=20=20=20=20=20((string-match=20"^@[0-9]+$"=20= lhs)=0A+=09(loop=20for=20ic=20from=201=20to=20org-table-current-ncol=20= do=0A+=09=20=20=20=20=20=20(push=20(cons=20(format=20"%s$%d"=20lhs=20ic)=20= rhs)=20res)))=0A+=20=20=20=20=20=20=20(t=0A+=09(setq=20range=20= (org-table-get-range=20lhs=20org-table-current-begin-pos=0A+=09=09=09=09=09= =201=20nil=20'corners))=0A+=09(setq=20r1=20(nth=200=20range)=20c1=20(nth=20= 1=20range)=0A+=09=20=20=20=20=20=20r2=20(nth=202=20range)=20c2=20(nth=20= 3=20range))=0A+=09(setq=20r1=20(org-table-line-to-dline=20r1))=0A+=09= (setq=20r2=20(org-table-line-to-dline=20r2=20'above))=0A+=09(loop=20for=20= ir=20from=20r1=20to=20r2=20do=0A+=09=20=20=20=20=20=20(loop=20for=20ic=20= from=20c1=20to=20c2=20do=0A+=09=09=20=20=20=20(push=20(cons=20(format=20= "@%d$%d"=20ir=20ic)=20rhs)=20res))))))=0A+=20=20=20=20(nreverse=20res)))=0A= +=0A=20(defun=20org-table-formula-substitute-names=20(f)=0A=20=20=20= "Replace=20$const=20with=20values=20in=20string=20F."=0A=20=20=20(let=20= ((start=200)=20a=20(f1=20f)=20(pp=20(/=3D=20(string-to-char=20f)=20?')))=0A= @@=20-2837,7=20+2915,7=20@@=20Parameters=20get=20priority."=0A=20=09(wc=20= (current-window-configuration))=0A=20=09(sel-win=20(selected-window))=0A=20= =09(titles=20'((column=20.=20"#=20Column=20Formulas\n")=0A-=09=09=20=20= (field=20.=20"#=20Field=20Formulas\n")=0A+=09=09=20=20(field=20.=20"#=20= Field=20and=20Range=20Formulas\n")=0A=20=09=09=20=20(named=20.=20"#=20= Named=20Field=20Formulas\n")))=0A=20=09entry=20s=20type=20title)=0A=20=20= =20=20=20(org-switch-to-buffer-other-window=20"*Edit=20Formulas*")=0A@@=20= -2861,7=20+2939,7=20@@=20Parameters=20get=20priority."=0A=20=20=20=20=20=20= =20(when=20(setq=20title=20(assq=20type=20titles))=0A=20=09(or=20(bobp)=20= (insert=20"\n"))=0A=20=09(insert=20(org-add-props=20(cdr=20title)=20nil=20= 'face=20font-lock-comment-face))=0A-=09(setq=20titles=20(delq=20title=20= titles)))=0A+=09(setq=20titles=20(remove=20title=20titles)))=0A=20=20=20=20= =20=20=20(if=20(equal=20key=20(car=20entry))=20(setq=20startline=20= (org-current-line)))=0A=20=20=20=20=20=20=20(setq=20s=20(concat=20(if=20= (equal=20(string-to-char=20(car=20entry))=20?@)=20""=20"$")=0A=20=09=09=20= =20=20=20=20=20(car=20entry)=20"=20=3D=20"=20(cdr=20entry)=20"\n"))=0A@@=20= -3078,7=20+3156,7=20@@=20With=20prefix=20ARG,=20apply=20the=20new=20= formulas=20to=20the=20table."=0A=20=20=20(let=20((pos=20org-pos)=20= (sel-win=20org-selected-window)=20eql=20var=20form)=0A=20=20=20=20=20= (goto-char=20(point-min))=0A=20=20=20=20=20(while=20(re-search-forward=0A= -=09=20=20=20=20"^\\(@[0-9]+\\$[0-9]+\\|\\$\\([a-zA-Z0-9]+\\)\\)=20*=3D=20= *\\(.*\\(\n[=20\t]+.*$\\)*\\)"=0A+=09=20=20=20=20"^\\(@[^=3D\n=20= \t]+\\|\\$\\([a-zA-Z0-9]+\\)\\)=20*=3D=20*\\(.*\\(\n[=20\t]+.*$\\)*\\)"=0A= =20=09=20=20=20=20nil=20t)=0A=20=20=20=20=20=20=20(setq=20var=20(if=20= (match-end=202)=20(match-string=202)=20(match-string=201))=0A=20=09=20=20= =20=20form=20(match-string=203))=0A@@=20-3167,6=20+3245,12=20@@=20With=20= prefix=20ARG,=20apply=20the=20new=20formulas=20to=20the=20table."=0A=20=09= =20=20var=20name=20e=20what=20match=20dest)=0A=20=20=20=20=20=20=20(if=20= local=20(org-table-get-specials))=0A=20=20=20=20=20=20=20(setq=20what=20= (cond=0A+=09=09=20=20((org-at-regexp-p=20"^@[0-9]+[=20\t=3D]")=0A+=09=09=20= =20=20(setq=20match=20(concat=20(substring=20(match-string=200)=200=20= -1)=0A+=09=09=09=09=20=20=20=20=20=20=20"$1.."=0A+=09=09=09=09=20=20=20=20= =20=20=20(substring=20(match-string=200)=200=20-1)=0A+=09=09=09=09=20=20=20= =20=20=20=20"$100"))=0A+=09=09=20=20=20'range)=0A=20=09=09=20=20((or=20= (org-at-regexp-p=20org-table-range-regexp2)=0A=20=09=09=20=20=20=20=20=20= =20(org-at-regexp-p=20org-table-translate-regexp)=0A=20=09=09=20=20=20=20= =20=20=20(org-at-regexp-p=20org-table-range-regexp))=0A@@=20-4359,6=20= +4443,7=20@@=20list=20of=20the=20fields=20in=20the=20rectangle=20."=0A=20= =09=20=20org-table-local-parameters=20org-table-named-field-locations=0A=20= =09=20=20org-table-current-line-types=20org-table-current-begin-line=0A=20= =09=20=20org-table-current-begin-pos=20org-table-dlines=0A+=09=20=20= org-table-current-ncol=0A=20=09=20=20org-table-hlines=20= org-table-last-alignment=0A=20=09=20=20org-table-last-column-widths=20= org-table-last-alignment=0A=20=09=20=20org-table-last-column-widths=20= tbeg=0A@@=20-4402,3=20+4487,4=20@@=20list=20of=20the=20fields=20in=20the=20= rectangle=20."=0A=20;;=20arch-tag:=20= 4d21cfdd-0268-440a-84b0-09237a0fe0ef=0A=20=0A=20;;;=20org-table.el=20= ends=20here=0A+=0A--=20=0A1.7.1.575.gf526=0A=0A= --Apple-Mail-11-707424296 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --Apple-Mail-11-707424296--