Function: org-export-format-code-default
org-export-format-code-default is a byte-compiled function defined in
ox.el.gz.
Signature
(org-export-format-code-default ELEMENT INFO)
Documentation
Return source code from ELEMENT, formatted in a standard way.
ELEMENT is either a src-block or example-block element. INFO
is a plist used as a communication channel.
This function takes care of line numbering and code references inclusion. Line numbers, when applicable, appear at the beginning of the line, separated from the code by two white spaces. Code references, on the other hand, appear flushed to the right, separated by six white spaces from the widest line of code.
Source Code
;; Defined in /usr/src/emacs/lisp/org/ox.el.gz
(defun org-export-format-code-default (element info)
"Return source code from ELEMENT, formatted in a standard way.
ELEMENT is either a `src-block' or `example-block' element. INFO
is a plist used as a communication channel.
This function takes care of line numbering and code references
inclusion. Line numbers, when applicable, appear at the
beginning of the line, separated from the code by two white
spaces. Code references, on the other hand, appear flushed to
the right, separated by six white spaces from the widest line of
code."
;; Extract code and references.
(let* ((code-info (org-export-unravel-code element))
(code (car code-info))
(code-lines (split-string code "\n")))
(if (null code-lines) ""
(let* ((refs (and (org-element-property :retain-labels element)
(cdr code-info)))
;; Handle line numbering.
(num-start (org-export-get-loc element info))
(num-fmt
(and num-start
(format "%%%ds "
(length (number-to-string
(+ (length code-lines) num-start))))))
;; Prepare references display, if required. Any reference
;; should start six columns after the widest line of code,
;; wrapped with parenthesis.
(max-width
(+ (apply #'max (mapcar #'length code-lines))
(if (not num-start) 0 (length (format num-fmt num-start))))))
(org-export-format-code
code
(lambda (loc line-num ref)
(let ((number-str (and num-fmt (format num-fmt line-num))))
(concat
number-str
loc
(and ref
(concat (make-string (- (+ 6 max-width)
(+ (length loc) (length number-str)))
?\s)
(format "(%s)" ref))))))
num-start refs)))))