diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index fff4f47de..8c1f6a026 100644 --- a/etc/ORG-NEWS +++ b/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. ** 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 When ~org-babel-tangle-remove-file-before-write~ is set to ~t~ the diff --git a/lisp/org-colview.el b/lisp/org-colview.el index d71c84a76..8a5c33236 100644 --- a/lisp/org-colview.el +++ b/lisp/org-colview.el @@ -1559,7 +1559,10 @@ PARAMS is a property list of parameters: (plist-get params :skip-empty-rows) (plist-get params :exclude-tags) (plist-get params :format) - view-pos)))))) + view-pos))))) + (width-specs + (mapcar (lambda (spec) (nth 2 spec)) + org-columns-current-fmt-compiled))) (when table ;; Prune level information from the table. Also normalize ;; 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))) table) (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")) recalc) ;; Insert affiliated keywords before the table. @@ -1616,7 +1624,9 @@ PARAMS is a property list of parameters: (insert "\n" line) (unless recalc (setq recalc t)))))) (when recalc (org-table-recalculate 'all t)) - (org-table-align))))) + (org-table-align) + (when (seq-find #'identity width-specs) + (org-table-shrink)))))) ;;;###autoload (defun org-columns-insert-dblock () diff --git a/testing/lisp/test-org-colview.el b/testing/lisp/test-org-colview.el index 03a2c834a..7f0aa763e 100644 --- a/testing/lisp/test-org-colview.el +++ b/testing/lisp/test-org-colview.el @@ -1422,6 +1422,19 @@ "* H\n:PROPERTIES:\n:A: 1\n:END:\n#+BEGIN: columnview\n#+END:" (let ((org-columns-default-format "%ITEM %A")) (org-update-dblock)) (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#+BEGIN: columnview\n#+END:" + (let ((org-columns-default-format "%5ITEM")) (org-update-dblock)) + (buffer-substring-no-properties (point) (point-max))))) ;; Properties are case insensitive. (should (equal