org-dblock-write:columnview: Write width specifications
* lisp/org-colview.el (org-dblock-write:columnview): When writing table, write width specifications as well and apply them. * testing/lisp/test-org-colview.el (test-org-colview/dblock): Add test. * etc/ORG-NEWS (=colview= dynamic block now writes column width specifications): Document the change. Link: https://orgmode.org/list/87r1015w30.fsf@localhost
This commit is contained in:
parent
d491a74fd9
commit
b2827aed98
30
etc/ORG-NEWS
30
etc/ORG-NEWS
|
@ -984,6 +984,36 @@ properties, links to headlines in the file can also be made more
|
||||||
robust by using the file id instead of the file path.
|
robust by using the file id instead of the file path.
|
||||||
|
|
||||||
** New features
|
** New features
|
||||||
|
*** =colview= dynamic block now writes column width specifications
|
||||||
|
|
||||||
|
When column format contains width specifications, =colview= dynamic
|
||||||
|
block now writes these specifications as column width in the generated
|
||||||
|
tables and automatically shrinks the columns on display.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
: * PROYECTO EMACS
|
||||||
|
: :PROPERTIES:
|
||||||
|
: :COLUMNS: %10ITEM(PROJECT)
|
||||||
|
: :END:
|
||||||
|
:
|
||||||
|
: Before
|
||||||
|
:
|
||||||
|
: #+BEGIN: columnview :id local
|
||||||
|
: | PROJECT |
|
||||||
|
: |----------------|
|
||||||
|
: | PROYECTO EMACS |
|
||||||
|
: #+END:
|
||||||
|
:
|
||||||
|
: After
|
||||||
|
:
|
||||||
|
: #+BEGIN: columnview :id local
|
||||||
|
: | <10> |
|
||||||
|
: | PROJECT |
|
||||||
|
: |----------------|
|
||||||
|
: | PROYECTO EMACS |
|
||||||
|
: #+END:
|
||||||
|
|
||||||
*** =ob-tangle.el=: New flag to remove tangle targets before writing
|
*** =ob-tangle.el=: New flag to remove tangle targets before writing
|
||||||
|
|
||||||
When ~org-babel-tangle-remove-file-before-write~ is set to ~t~ the
|
When ~org-babel-tangle-remove-file-before-write~ is set to ~t~ the
|
||||||
|
|
|
@ -1559,7 +1559,10 @@ PARAMS is a property list of parameters:
|
||||||
(plist-get params :skip-empty-rows)
|
(plist-get params :skip-empty-rows)
|
||||||
(plist-get params :exclude-tags)
|
(plist-get params :exclude-tags)
|
||||||
(plist-get params :format)
|
(plist-get params :format)
|
||||||
view-pos))))))
|
view-pos)))))
|
||||||
|
(width-specs
|
||||||
|
(mapcar (lambda (spec) (nth 2 spec))
|
||||||
|
org-columns-current-fmt-compiled)))
|
||||||
(when table
|
(when table
|
||||||
;; Prune level information from the table. Also normalize
|
;; Prune level information from the table. Also normalize
|
||||||
;; headings: remove stars, add indentation entities, if
|
;; headings: remove stars, add indentation entities, if
|
||||||
|
@ -1595,6 +1598,11 @@ PARAMS is a property list of parameters:
|
||||||
(append (mapcar (lambda (x) (if (eq 'hline x) x (cons "" x)))
|
(append (mapcar (lambda (x) (if (eq 'hline x) x (cons "" x)))
|
||||||
table)
|
table)
|
||||||
(list (cons "/" (make-list size "<>")))))))
|
(list (cons "/" (make-list size "<>")))))))
|
||||||
|
(when (seq-find #'identity width-specs)
|
||||||
|
;; There are width specifiers in column format. Pass them
|
||||||
|
;; to the resulting table, adding alignment field as the first
|
||||||
|
;; row.
|
||||||
|
(push (mapcar (lambda (width) (when width (format "<%d>" width))) width-specs) table))
|
||||||
(let ((content-lines (org-split-string (plist-get params :content) "\n"))
|
(let ((content-lines (org-split-string (plist-get params :content) "\n"))
|
||||||
recalc)
|
recalc)
|
||||||
;; Insert affiliated keywords before the table.
|
;; Insert affiliated keywords before the table.
|
||||||
|
@ -1616,7 +1624,9 @@ PARAMS is a property list of parameters:
|
||||||
(insert "\n" line)
|
(insert "\n" line)
|
||||||
(unless recalc (setq recalc t))))))
|
(unless recalc (setq recalc t))))))
|
||||||
(when recalc (org-table-recalculate 'all t))
|
(when recalc (org-table-recalculate 'all t))
|
||||||
(org-table-align)))))
|
(org-table-align)
|
||||||
|
(when (seq-find #'identity width-specs)
|
||||||
|
(org-table-shrink))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun org-columns-insert-dblock ()
|
(defun org-columns-insert-dblock ()
|
||||||
|
|
|
@ -1422,6 +1422,19 @@
|
||||||
"* H\n:PROPERTIES:\n:A: 1\n:END:\n<point>#+BEGIN: columnview\n#+END:"
|
"* H\n:PROPERTIES:\n:A: 1\n:END:\n<point>#+BEGIN: columnview\n#+END:"
|
||||||
(let ((org-columns-default-format "%ITEM %A")) (org-update-dblock))
|
(let ((org-columns-default-format "%ITEM %A")) (org-update-dblock))
|
||||||
(buffer-substring-no-properties (point) (point-max)))))
|
(buffer-substring-no-properties (point) (point-max)))))
|
||||||
|
;; Test column widths.
|
||||||
|
(should
|
||||||
|
(equal
|
||||||
|
"#+BEGIN: columnview
|
||||||
|
| <5> |
|
||||||
|
| ITEM |
|
||||||
|
|------|
|
||||||
|
| H |
|
||||||
|
#+END:"
|
||||||
|
(org-test-with-temp-text
|
||||||
|
"* H\n<point>#+BEGIN: columnview\n#+END:"
|
||||||
|
(let ((org-columns-default-format "%5ITEM")) (org-update-dblock))
|
||||||
|
(buffer-substring-no-properties (point) (point-max)))))
|
||||||
;; Properties are case insensitive.
|
;; Properties are case insensitive.
|
||||||
(should
|
(should
|
||||||
(equal
|
(equal
|
||||||
|
|
Loading…
Reference in New Issue