Function: org-ascii--current-text-width

org-ascii--current-text-width is a byte-compiled function defined in ox-ascii.el.gz.

Signature

(org-ascii--current-text-width ELEMENT INFO)

Documentation

Return maximum text width for ELEMENT's contents.

INFO is a plist used as a communication channel.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox-ascii.el.gz
(defun org-ascii--current-text-width (element info)
  "Return maximum text width for ELEMENT's contents.
INFO is a plist used as a communication channel."
  (pcase (org-element-type element)
    ;; Elements with an absolute width: `headline' and `inlinetask'.
    (`inlinetask (plist-get info :ascii-inlinetask-width))
    (`headline
     (- (plist-get info :ascii-text-width)
        (let ((low-level-rank (org-export-low-level-p element info)))
          (if low-level-rank (* low-level-rank 2)
            (plist-get info :ascii-global-margin)))))
    ;; Elements with a relative width: store maximum text width in
    ;; TOTAL-WIDTH.
    (_
     (let* ((genealogy (org-element-lineage element nil t))
            ;; Total width is determined by the presence, or not, of an
            ;; inline task among ELEMENT parents.
            (total-width
             (if (cl-some (lambda (parent)
                            (org-element-type-p parent 'inlinetask))
                          genealogy)
                 (plist-get info :ascii-inlinetask-width)
               ;; No inlinetask: Remove global margin from text width.
               (- (plist-get info :ascii-text-width)
                  (plist-get info :ascii-global-margin)
                  (let ((parent (org-element-lineage element 'headline)))
                    ;; Inner margin doesn't apply to text before first
                    ;; headline.
                    (if (not parent) 0
                      (let ((low-level-rank
                             (org-export-low-level-p parent info)))
                        ;; Inner margin doesn't apply to contents of
                        ;; low level headlines, since they've got their
                        ;; own indentation mechanism.
                        (if low-level-rank (* low-level-rank 2)
                          (plist-get info :ascii-inner-margin)))))))))
       (- total-width
          ;; Each `quote-block' and `verse-block' above narrows text
          ;; width by twice the standard margin size.
          (+ (* (cl-count-if (lambda (parent)
                               (org-element-type-p
                                parent '(quote-block verse-block)))
                             genealogy)
                2
                (plist-get info :ascii-quote-margin))
             ;; Apply list margin once per "top-level" plain-list
             ;; containing current line
             (* (cl-count-if
                 (lambda (e)
                   (and (org-element-type-p e 'plain-list)
                        (not (org-element-type-p
                            (org-element-parent e) 'item))))
                 genealogy)
                (plist-get info :ascii-list-margin))
             ;; Compute indentation offset due to current list.  It is
	     ;; `org-ascii-quote-margin' per descriptive item in the
	     ;; genealogy, bullet's length otherwise.
             (let ((indentation 0))
               (dolist (e genealogy)
                 (cond
                  ((not (org-element-type-p e 'item)))
                  ((eq (org-element-property :type (org-element-parent e))
                       'descriptive)
                   (cl-incf indentation org-ascii-quote-margin))
                  (t
                   (cl-incf indentation
                            (+ (string-width
                                (or (org-ascii--checkbox e info) ""))
                               (string-width
                                (org-element-property :bullet e)))))))
               indentation)))))))