mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-08-26 16:02:52 +00:00
Remember the original indentation of source code snippets
As the export preprocessor removes indentation from indented blocks, this causes conflicts about interpreting indentation as list termination. Now the original indentation is stored in a text property, so hopefully the exporters can make use of this information in due time.
This commit is contained in:
parent
b6152ed5b0
commit
4cc6309f6f
|
@ -1,5 +1,8 @@
|
|||
2009-06-04 Carsten Dominik <carsten.dominik@gmail.com>
|
||||
|
||||
* org-exp.el (org-export-format-source-code-or-example): Remember
|
||||
the original indentation of source code snippets and examples.
|
||||
|
||||
* org-latex.el (org-export-as-latex): Relocate the table of
|
||||
contents.
|
||||
|
||||
|
|
|
@ -2124,32 +2124,33 @@ in the list) and remove property and value from the list in LISTVAR."
|
|||
lang code trans opts)
|
||||
(goto-char (point-min))
|
||||
(while (re-search-forward
|
||||
"\\(^[ \t]*#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\\)\\|\\(^[ \t]*#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\\)"
|
||||
"\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\\)\\|\\(^[ \t]*#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\\)"
|
||||
nil t)
|
||||
(if (match-end 1)
|
||||
;; src segments
|
||||
(setq lang (match-string 2)
|
||||
opts (match-string 3)
|
||||
code (match-string 4))
|
||||
(setq lang (match-string 3)
|
||||
opts (match-string 4)
|
||||
code (match-string 5))
|
||||
(setq lang nil
|
||||
opts (match-string 6)
|
||||
code (match-string 7)))
|
||||
opts (match-string 7)
|
||||
code (match-string 8)))
|
||||
|
||||
(setq trans (org-export-format-source-code-or-example
|
||||
backend lang code opts))
|
||||
backend lang code opts (length (match-string 2))))
|
||||
(replace-match trans t t))))
|
||||
|
||||
(defvar htmlp) ;; dynamically scoped
|
||||
(defvar latexp) ;; dynamically scoped
|
||||
|
||||
(defun org-export-format-source-code-or-example (backend
|
||||
lang code &optional opts)
|
||||
(defun org-export-format-source-code-or-example
|
||||
(backend lang code &optional opts indent)
|
||||
"Format CODE from language LANG and return it formatted for export.
|
||||
If LANG is nil, do not add any fontification.
|
||||
OPTS contains formatting optons, like `-n' for triggering numbering lines,
|
||||
and `+n' for continuing previous numering.
|
||||
Code formatting according to language currently only works for HTML.
|
||||
Numbering lines works for all three major backends (html, latex, and ascii)."
|
||||
Numbering lines works for all three major backends (html, latex, and ascii).
|
||||
INDENT was the original indentation of the block."
|
||||
(save-match-data
|
||||
(let (num cont rtn rpllbl keepp textareap cols rows fmt)
|
||||
(setq opts (or opts "")
|
||||
|
@ -2184,6 +2185,7 @@ Numbering lines works for all three major backends (html, latex, and ascii)."
|
|||
(end-of-line 1))
|
||||
(buffer-string))))
|
||||
;; Now backend-specific coding
|
||||
(setq rtn
|
||||
(cond
|
||||
((eq backend 'docbook)
|
||||
(setq rtn (org-export-number-lines rtn 'docbook 0 0 num cont rpllbl fmt))
|
||||
|
@ -2257,7 +2259,8 @@ Numbering lines works for all three major backends (html, latex, and ascii)."
|
|||
"\n")
|
||||
"\n")
|
||||
'(org-protected t))
|
||||
"#+END_ASCII\n"))))))
|
||||
"#+END_ASCII\n"))))
|
||||
(org-add-props rtn nil 'original-indentation indent))))
|
||||
|
||||
(defun org-export-number-lines (text backend
|
||||
&optional skip1 skip2 number cont
|
||||
|
|
Loading…
Reference in a new issue