[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Creating hline in table from source block?
From: |
Rasmus |
Subject: |
Re: [O] Creating hline in table from source block? |
Date: |
Tue, 26 Nov 2013 01:47:00 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Rasmus <address@hidden> writes:
> Probably you can remove the require 'cl. Also, you can generalize the
> code to take arbitrarily hline positions.
Here's a more fun :post function (again depending on cl).
#+NAME: add_hline
#+BEGIN_SRC emacs-lisp :var data='((a b c) (d e f) (h i j)) h='(0 -2 100 last)
(let* ((d (copy-list data))
(h0 (delq nil
(mapcar (lambda (e)
(when (or (not (numberp e)) (< (abs e) (length
data)))
(cond
((equal e 'last) (length data))
((and (numberp e) (< e 0)) (+ (length data) e))
(t e))))
(if (listp h) h (list h)))))
(h1 (number-sequence 0 (1- (length h0))))
(H (mapcar* '+ h0 h1)))
(dolist (x H) (push 'hline (nthcdr x d)))
d)
#+END_SRC
#+BEGIN_SRC sh :post add_hline(data=*this*, h='(0 1 last))
echo "a b c d"
echo "1 2 3 4"
echo "5 6 7 8"
#+END_SRC
#+RESULTS:
|---+---+---+---|
| a | b | c | d |
|---+---+---+---|
| 1 | 2 | 3 | 4 |
| 5 | 6 | 7 | 8 |
|---+---+---+---|
--
In theory, practice and theory are the same. In practice they are not