ox-ascii: Use cl-lib

* lisp/ox-ascii.el (org-ascii--current-text-width): Refactor code.
(org-ascii--list-listings):
(org-ascii--list-tables): Use "cl-" prefix.
This commit is contained in:
Nicolas Goaziou 2016-07-25 15:36:09 +02:00
parent 72461eaeaf
commit b6dfc75654
1 changed files with 21 additions and 19 deletions

View File

@ -27,9 +27,9 @@
;;; Code: ;;; Code:
(eval-when-compile (require 'cl))
(require 'ox) (require 'ox)
(require 'ox-publish) (require 'ox-publish)
(require 'cl-lib)
(declare-function aa2u "ext:ascii-art-to-unicode" ()) (declare-function aa2u "ext:ascii-art-to-unicode" ())
@ -564,8 +564,9 @@ INFO is a plist used as a communication channel."
;; Total width is determined by the presence, or not, of an ;; Total width is determined by the presence, or not, of an
;; inline task among ELEMENT parents. ;; inline task among ELEMENT parents.
(total-width (total-width
(if (loop for parent in genealogy (if (cl-some (lambda (parent)
thereis (eq (org-element-type parent) 'inlinetask)) (eq (org-element-type parent) 'inlinetask))
genealogy)
(plist-get info :ascii-inlinetask-width) (plist-get info :ascii-inlinetask-width)
;; No inlinetask: Remove global margin from text width. ;; No inlinetask: Remove global margin from text width.
(- (plist-get info :ascii-text-width) (- (plist-get info :ascii-text-width)
@ -584,19 +585,20 @@ INFO is a plist used as a communication channel."
(- total-width (- total-width
;; Each `quote-block' and `verse-block' above narrows text ;; Each `quote-block' and `verse-block' above narrows text
;; width by twice the standard margin size. ;; width by twice the standard margin size.
(+ (* (loop for parent in genealogy (+ (* (cl-count-if (lambda (parent)
when (memq (org-element-type parent) (memq (org-element-type parent)
'(quote-block verse-block)) '(quote-block verse-block)))
count parent) genealogy)
2 (plist-get info :ascii-quote-margin)) 2
(plist-get info :ascii-quote-margin))
;; Apply list margin once per "top-level" plain-list ;; Apply list margin once per "top-level" plain-list
;; containing current line ;; containing current line
(* (let ((count 0)) (* (cl-count-if
(dolist (e genealogy count) (lambda (e)
(and (eq (org-element-type e) 'plain-list) (and (eq (org-element-type e) 'plain-list)
(not (eq (org-element-type (org-export-get-parent e)) (not (eq (org-element-type (org-export-get-parent e))
'item)) 'item))))
(incf count)))) genealogy)
(plist-get info :ascii-list-margin)) (plist-get info :ascii-list-margin))
;; Text width within a plain-list is restricted by ;; Text width within a plain-list is restricted by
;; indentation of current item. If that's the case, ;; indentation of current item. If that's the case,
@ -604,9 +606,9 @@ INFO is a plist used as a communication channel."
;; parent item, if any. ;; parent item, if any.
(let ((item (let ((item
(if (eq (org-element-type element) 'item) element (if (eq (org-element-type element) 'item) element
(loop for parent in genealogy (cl-find-if (lambda (parent)
when (eq (org-element-type parent) 'item) (eq (org-element-type parent) 'item))
return parent)))) genealogy))))
(if (not item) 0 (if (not item) 0
;; Compute indentation offset of the current item, ;; Compute indentation offset of the current item,
;; that is the sum of the difference between its ;; that is the sum of the difference between its
@ -806,7 +808,7 @@ generation. INFO is a plist used as a communication channel."
;; filling (like contents of a description list item). ;; filling (like contents of a description list item).
(let* ((initial-text (let* ((initial-text
(format (org-ascii--translate "Listing %d:" info) (format (org-ascii--translate "Listing %d:" info)
(incf count))) (cl-incf count)))
(initial-width (string-width initial-text))) (initial-width (string-width initial-text)))
(concat (concat
initial-text " " initial-text " "
@ -846,7 +848,7 @@ generation. INFO is a plist used as a communication channel."
;; filling (like contents of a description list item). ;; filling (like contents of a description list item).
(let* ((initial-text (let* ((initial-text
(format (org-ascii--translate "Table %d:" info) (format (org-ascii--translate "Table %d:" info)
(incf count))) (cl-incf count)))
(initial-width (string-width initial-text))) (initial-width (string-width initial-text)))
(concat (concat
initial-text " " initial-text " "