diff --git a/doc/org-manual.org b/doc/org-manual.org index 89592b12d..53ed01ff8 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 4dcfbd3b0..8dfc07a4e 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))