emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org cab81f2428: org-babel: Improve parsing of colnames


From: ELPA Syncer
Subject: [elpa] externals/org cab81f2428: org-babel: Improve parsing of colnames in tables with horizontal lines
Date: Thu, 7 Mar 2024 15:58:25 -0500 (EST)

branch: externals/org
commit cab81f2428880b293e780915cf9762cc59692091
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    org-babel: Improve parsing of colnames in tables with horizontal lines
    
    * lisp/ob-core.el (org-babel-get-colnames): When table starts with
    horizontal lines, consider column names to be the first non-hline row.
    (org-babel-disassemble-tables): When detecting automatic column names,
    do not assign colnames when the first row is an hline.
    * doc/org-manual.org (Passing arguments): Update the manual, detailing
    that leading hline rows are skipped for :colnames yes.
    
    Link: https://orgmode.org/list/87wmqexjoj.fsf@localhost
---
 doc/org-manual.org |  6 +++---
 lisp/ob-core.el    | 15 ++++++++++++---
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 89592b12da..53ed01ff85 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -18121,9 +18121,9 @@ Here are examples of passing values by reference:
   names---because the second row is a horizontal rule---then Org
   removes the column names, processes the table, puts back the column
   names, and then writes the table to the results block.  Using =yes=,
-  Org does the same to the first row, even if the initial table does
-  not contain any horizontal rule.  When set to =no=, Org does not
-  pre-process column names at all.
+  Org does the same to the first non-hline row, even if the initial
+  table does not contain any horizontal rule.  When set to =no=, Org
+  does not pre-process column names at all.
 
   # We keep python blocks unindented on purpose - to keep the example
   # working even for users who changed the default value of 
~org-src-preserve-indentation~
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 4dcfbd3b0c..8dfc07a4e2 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -1834,6 +1834,8 @@ HEADER-ARGUMENTS is alist of all the arguments."
 Return a cons cell, the `car' of which contains the TABLE less
 colnames, and the `cdr' of which contains a list of the column
 names."
+  ;; Skip over leading hlines.
+  (while (eq 'hline (car table)) (pop table))
   (if (eq 'hline (nth 1 table))
       (cons (cddr table) (car table))
     (cons (cdr table) (car table))))
@@ -1895,9 +1897,16 @@ of the vars, cnames and rnames."
           (when (and (not (equal colnames "no"))
                      ;; Compatibility note: avoid `length>', which
                      ;; isn't available until Emacs 28.
-                     (or colnames (and (> (length (cdr var)) 1)
-                                       (eq (nth 1 (cdr var)) 'hline)
-                                       (not (member 'hline (cddr (cdr 
var)))))))
+                     (or colnames
+                         ;; :colnames nil (default)
+                         ;; Auto-assign column names when the table
+                         ;; has hline as the second line after
+                         ;; non-hline row.
+                         (and (> (length (cdr var)) 1)
+                              (not (eq (car (cdr var)) 'hline)) ; first row
+                              (eq (nth 1 (cdr var)) 'hline) ; second row
+                              (not (member 'hline (cddr (cdr var)))) ; other 
rows
+                              )))
             (let ((both (org-babel-get-colnames (cdr var))))
               (setq cnames (cons (cons (car var) (cdr both))
                                  cnames))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]