Skip to main content


Fine, I'll build an #emacs pivot table package for #org-mode.

reshared this

in reply to Jonathan Lamothe

I've run into a snag.

I have a function, pivot-table-get-columns (shorthanded as pt-get-columns). Its job is to take an #OrgMode table and produce an alist of mappings of column names to column numbers. The column names are as defined by section 3.5.10 of the org-mode manual.

My code is here.

When I pass this function a table without column labels, it crashes on the format line (which it shouldn't even be reaching).

Can someone explain to me what I'm doing wrong?

(cc: @screwlisp )

#emacs #elisp

Edit: I've been beating my head against a wall for some time on this getting nowhere and less than a minute after asking this, I see it. My first unless should be a when. I'll fix it later.

reshared this

in reply to Jonathan Lamothe

actually, I'm unaware of

(setq result (((format "%s" cell) . n) . result))

being a permissable form. It looks like

(setq result `((,(format "%s" cell) . ,n) . ,result))

to me but I might be wrong. Does it fix the problem or did you have another insight?

This entry was edited (3 weeks ago)
in reply to vintage screwlisp account

Another thing is that you've used eq. Those strings aren't ever going to be eq which means "literally the same thing". You probably meant equal.
in reply to vintage screwlisp account

very cool to see you doing this elisp! By the way, I am a total convert to eev-mode and eepitch.
in reply to vintage screwlisp account

what does org table source look like by the way? I normally pass org tables into org source blocks (where they become s-expressions in lisp), but I'm not sure what the tables look like internally to org.
in reply to vintage screwlisp account

further about eq in common lisp at least, I've seen people make a mistake before- when you compile code, if you referred to "" twice, in common lisp compilers are allowed to coalesce them at which point they /will/ be eq. (Eq would be a good test to see if they /had/ been coalesced). But in the general case two strings entered in different places are not eq.
in reply to vintage screwlisp account

@screwtape
> in common lisp compilers are allowed to coalesce

[constants]Right, for details see what the _file_ compiler in particular may do.

in reply to vintage screwlisp account

I did some testing and found that if I pass a named table into a source block as a variable, it automatically gets converted into s-expression form.

See below:

#+NAME: my-table
|   | a | b |
|---+---+---|
| 1 | 2 | 3 |

#+begin_src emacs-lisp :var table=my-table :colnames no :hlines yes
  (format "%S" table)
#+end_src

#+RESULTS:
: (("" "a" "b") hline (1 2 3))
in reply to vintage screwlisp account

@screwlisp I've not seen the comma prefix used outside a macro before. Also, this would probably be better written as:
(push (cons (format "%s" cell) n) result)

It would certainly be more legible.

in reply to Jonathan Lamothe

@screwlisp Huzzah! That along with your point on eq vs. equal did the trick!

Now I've just got to, you know, write and document all the rest of it.

If this works out, I'm really excited about publishing it. I was surprised that it didn't already seem to exist.

in reply to Jonathan Lamothe

it is very exciting!
commas have to appear inside backticks, and backticks are just quotes that can have certain things inside of them unquoted (using a comma).

Macros to a large extent work like this because one principle of lisp is that lisp code be regular lisp sequences. At read time, the function names are just symbols. So it's a list of symbols/atoms and lists.

However, sometimes we /do/ want to run some code, hence backtick and comma/unquote.

This entry was edited (2 weeks ago)
in reply to Jonathan Lamothe

@screwtape

> the comma prefix used outside a macro

Backquote forms are merely list (S-expression) constructors where some pieces are constant and some pieces are evaluated.
(The latter are marked with commas.)
Such forms can be used anywhere.
Obviously they are often used in macros, because macro functions construct lists (S-expressions).

I often write
`(,foo ,bar)
instead of
(list foo bar)
because the former seems clearer, especially when the structure is more involved.

#CommonLisp

in reply to vintage screwlisp account

@screwtape
> `((,(format "%s" cell) . ,n) . ,result))

In Common Lisp you would write
`(... ,@result))
but right now I am only fairly sure that Elisp has comma splicing.

#CommonLisp
#Elisp

in reply to Jonathan Lamothe

Possibly related: github.com/tbanel/orgaggregate , could always use an easier interface =)
in reply to Sacha Chua

@Sacha Chua This looks like it could solve my problem but I've already started down the rabbit hole.
in reply to Jonathan Lamothe

haha, no worries, I'm sure your adventure will help you learn interesting things!
in reply to Sacha Chua

you might also be interested in mastodon.online/@hajovonta/114…


#cfw got an org-table import/export functionality. Just select the org-table and run M-x cfw-org-load. Analyse, sort, edit, filter your table in CFW. Then update the original org-table by M-x cfw-org-save.

If there was no original org-table (the table was created from scratch or from other source like CSV), the cfw-org-save places the exported table into the kill-ring. This way org pivottables can be generated from CFW.

#emacs


This website uses cookies. If you continue browsing this website, you agree to the usage of cookies.