|
@@ -46,7 +46,7 @@
|
|
|
(declare-function org-inlinetask-remove-END-maybe "org-inlinetask" ())
|
|
|
(declare-function org-table-cookie-line-p "org-table" (line))
|
|
|
(declare-function org-table-colgroup-line-p "org-table" (line))
|
|
|
-(declare-function org-pop-to-buffer-same-window "org-compat"
|
|
|
+(declare-function org-pop-to-buffer-same-window "org-compat"
|
|
|
(&optional buffer-or-name norecord label))
|
|
|
|
|
|
(autoload 'org-export-generic "org-export-generic" "Export using the generic exporter" t)
|
|
@@ -2729,7 +2729,54 @@ INDENT was the original indentation of the block."
|
|
|
(org-add-props rtn nil 'original-indentation indent))))
|
|
|
|
|
|
(defun org-export-number-lines (text &optional skip1 skip2 number cont
|
|
|
- replace-labels label-format)
|
|
|
+ replace-labels label-format preprocess)
|
|
|
+ "Apply line numbers to literal examples and handle code references.
|
|
|
+Handle user-specified options under info node `(org)Literal
|
|
|
+examples' and return the modified source block.
|
|
|
+
|
|
|
+TEXT contains the source or example block.
|
|
|
+
|
|
|
+SKIP1 and SKIP2 are the number of lines that are to be skipped at
|
|
|
+the beginning and end of TEXT. Use these to skip over
|
|
|
+backend-specific lines pre-pended or appended to the original
|
|
|
+source block.
|
|
|
+
|
|
|
+NUMBER is non-nil if the literal example specifies \"+n\" or
|
|
|
+\"-n\" switch. If NUMBER is non-nil add line numbers.
|
|
|
+
|
|
|
+CONT is non-nil if the literal example specifies \"+n\" switch.
|
|
|
+If CONT is nil, start numbering this block from 1. Otherwise
|
|
|
+continue numbering from the last numbered block.
|
|
|
+
|
|
|
+REPLACE-LABELS is dual-purpose.
|
|
|
+1. It controls the retention of labels in the exported block.
|
|
|
+2. It specifies in what manner the links (or references) to a
|
|
|
+ labelled line be formatted.
|
|
|
+
|
|
|
+REPLACE-LABELS is the symbol `keep' if the literal example
|
|
|
+specifies \"-k\" option, is numeric if the literal example
|
|
|
+specifies \"-r\" option and is nil otherwise.
|
|
|
+
|
|
|
+Handle REPLACE-LABELS as below:
|
|
|
+- If nil, retain labels in the exported block and use
|
|
|
+ user-provided labels for referencing the labelled lines.
|
|
|
+- If it is a number, remove labels in the exported block and use
|
|
|
+ one of line numbers or labels for referencing labelled lines based
|
|
|
+ on NUMBER option.
|
|
|
+- If it is a keep, retain labels in the exported block and use
|
|
|
+ one of line numbers or labels for referencing labelled lines
|
|
|
+ based on NUMBER option.
|
|
|
+
|
|
|
+LABEL-FORMAT is the value of \"-l\" switch associated with
|
|
|
+literal example. See `org-coderef-label-format'.
|
|
|
+
|
|
|
+PREPROCESS is intended for backend-agnostic handling of source
|
|
|
+block numbering. When non-nil do the following:
|
|
|
+- do not number the lines
|
|
|
+- always strip the labels from exported block
|
|
|
+- do not make the labelled line a target of an incoming link.
|
|
|
+ Instead mark the labelled line with `org-coderef' property and
|
|
|
+ store the label in it."
|
|
|
(setq skip1 (or skip1 0) skip2 (or skip2 0))
|
|
|
(if (and number (not cont)) (setq org-export-last-code-line-counter-value 0))
|
|
|
(with-temp-buffer
|
|
@@ -2768,9 +2815,10 @@ INDENT was the original indentation of the block."
|
|
|
|
|
|
(org-goto-line (1+ skip1))
|
|
|
(while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
|
|
|
- (if number
|
|
|
- (insert (format fm (incf n)))
|
|
|
- (forward-char 1))
|
|
|
+ (when number (incf n))
|
|
|
+ (if (or preprocess (not number))
|
|
|
+ (forward-char 1)
|
|
|
+ (insert (format fm n)))
|
|
|
(when (looking-at lbl-re)
|
|
|
(setq ref (match-string 3))
|
|
|
(cond ((numberp replace-labels)
|
|
@@ -2783,7 +2831,8 @@ INDENT was the original indentation of the block."
|
|
|
;; lines are numbered, use labels otherwise
|
|
|
(goto-char (match-beginning 2))
|
|
|
(delete-region (match-beginning 2) (match-end 2))
|
|
|
- (insert "(" ref ")")
|
|
|
+ (unless preprocess
|
|
|
+ (insert "(" ref ")"))
|
|
|
(push (cons ref (if (> n 0) n (concat "(" ref ")")))
|
|
|
org-export-code-refs))
|
|
|
(t
|
|
@@ -2791,15 +2840,19 @@ INDENT was the original indentation of the block."
|
|
|
;; references
|
|
|
(goto-char (match-beginning 2))
|
|
|
(delete-region (match-beginning 2) (match-end 2))
|
|
|
- (insert "(" ref ")")
|
|
|
+ (unless preprocess
|
|
|
+ (insert "(" ref ")"))
|
|
|
(push (cons ref (concat "(" ref ")")) org-export-code-refs)))
|
|
|
- (when (eq org-export-current-backend 'html)
|
|
|
+ (when (and (eq org-export-current-backend 'html) (not preprocess))
|
|
|
(save-excursion
|
|
|
(beginning-of-line 1)
|
|
|
(insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
|
|
|
ref))
|
|
|
(end-of-line 1)
|
|
|
- (insert "</span>")))))
|
|
|
+ (insert "</span>")))
|
|
|
+ (when preprocess
|
|
|
+ (add-text-properties
|
|
|
+ (point-at-bol) (point-at-eol) (list 'org-coderef ref)))))
|
|
|
(setq org-export-last-code-line-counter-value n)
|
|
|
(goto-char (point-max))
|
|
|
(newline)
|