Function: org-ascii--fill-string

org-ascii--fill-string is a byte-compiled function defined in ox-ascii.el.gz.

Signature

(org-ascii--fill-string S TEXT-WIDTH INFO &optional JUSTIFY)

Documentation

Fill a string with specified text-width and return it.

S is the string being filled. TEXT-WIDTH is an integer specifying maximum length of a line. INFO is the plist used as a communication channel.

Optional argument JUSTIFY can specify any type of justification among left, center, right or full. A nil value is equivalent to left. For a justification that doesn't also fill string, see org-ascii--justify-lines and org-ascii--justify-element.

Return nil if S isn't a string.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox-ascii.el.gz
;;; Internal Functions

;; Internal functions fall into three categories.

;; The first one is about text formatting.  The core functions are
;; `org-ascii--current-text-width' and
;; `org-ascii--current-justification', which determine, respectively,
;; the current text width allowed to a given element and its expected
;; justification.  Once this information is known,
;; `org-ascii--fill-string', `org-ascii--justify-lines',
;; `org-ascii--justify-element' `org-ascii--box-string' and
;; `org-ascii--indent-string' can operate on a given output string.
;; In particular, justification happens at the regular (i.e.,
;; non-greater) element level, which means that when the exporting
;; process reaches a container (e.g., a center block) content are
;; already justified.

;; The second category contains functions handling elements listings,
;; triggered by "#+TOC:" keyword.  As such, `org-ascii--build-toc'
;; returns a complete table of contents, `org-ascii--list-listings'
;; returns a list of referenceable src-block elements, and
;; `org-ascii--list-tables' does the same for table elements.

;; The third category includes general helper functions.
;; `org-ascii--build-title' creates the title for a given headline
;; or inlinetask element.  `org-ascii--build-caption' returns the
;; caption string associated to a table or a src-block.
;; `org-ascii--describe-links' creates notes about links for
;; insertion at the end of a section.  It uses
;; `org-ascii--unique-links' to get the list of links to describe.
;; Eventually, `org-ascii--translate' translates a string according
;; to language and charset specification.


(defun org-ascii--fill-string (s text-width info &optional justify)
  "Fill a string with specified text-width and return it.

S is the string being filled.  TEXT-WIDTH is an integer
specifying maximum length of a line.  INFO is the plist used as
a communication channel.

Optional argument JUSTIFY can specify any type of justification
among `left', `center', `right' or `full'.  A nil value is
equivalent to `left'.  For a justification that doesn't also fill
string, see `org-ascii--justify-lines' and
`org-ascii--justify-element'.

Return nil if S isn't a string."
  (when (stringp s)
    (let ((double-space-p sentence-end-double-space))
      (with-temp-buffer
	(let ((fill-column text-width)
	      (use-hard-newlines t)
	      (sentence-end-double-space double-space-p))
	  (insert (if (plist-get info :preserve-breaks)
		      (replace-regexp-in-string "\n" hard-newline s)
		    s))
	  (fill-region (point-min) (point-max) justify))
	(buffer-string)))))