forked from mirrors/org-mode
Merge branch 'maint'
This commit is contained in:
commit
d3eaa6abb6
|
@ -1648,6 +1648,35 @@ CONTENTS is nil."
|
||||||
|
|
||||||
;;;; Example Block
|
;;;; Example Block
|
||||||
|
|
||||||
|
(defun org-element--remove-indentation (s &optional n)
|
||||||
|
"Remove maximum common indentation in string S and return it.
|
||||||
|
When N is a positive integer, remove exactly that indentation,
|
||||||
|
possible, or return S as-is otherwise. Unlike to
|
||||||
|
`org-remove-indentation', this function doesn't call `untabify'
|
||||||
|
on S first."
|
||||||
|
(catch 'exit
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert s)
|
||||||
|
(goto-char (point-min))
|
||||||
|
;; Find maximum common indentation, if not specified.
|
||||||
|
(setq n (or n
|
||||||
|
(catch 'min-ind
|
||||||
|
(let ((min-ind (point-max)))
|
||||||
|
(save-excursion
|
||||||
|
(while (re-search-forward "^[ \t]*\\S-" nil t)
|
||||||
|
(let ((ind (1- (current-column))))
|
||||||
|
(if (zerop ind) (throw 'min-ind 0)
|
||||||
|
(setq min-ind (min min-ind ind))))))
|
||||||
|
min-ind))))
|
||||||
|
;; Remove exactly N indentation, but give up if not possible.
|
||||||
|
(while (not (eobp))
|
||||||
|
(let ((ind (progn (skip-chars-forward " \t") (current-column))))
|
||||||
|
(cond ((eolp) (delete-region (line-beginning-position) (point)))
|
||||||
|
((< ind n) (throw 'exit s))
|
||||||
|
(t (org-indent-line-to (- ind n))))
|
||||||
|
(forward-line)))
|
||||||
|
(buffer-string))))
|
||||||
|
|
||||||
(defun org-element-example-block-parser (limit affiliated)
|
(defun org-element-example-block-parser (limit affiliated)
|
||||||
"Parse an example block.
|
"Parse an example block.
|
||||||
|
|
||||||
|
@ -1669,13 +1698,17 @@ keywords."
|
||||||
(let ((contents-end (match-beginning 0)))
|
(let ((contents-end (match-beginning 0)))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(let* ((switches
|
(let* ((switches
|
||||||
(progn (looking-at "^[ \t]*#\\+BEGIN_EXAMPLE\\(?: +\\(.*\\)\\)?")
|
(progn
|
||||||
(org-match-string-no-properties 1)))
|
(looking-at "^[ \t]*#\\+BEGIN_EXAMPLE\\(?: +\\(.*\\)\\)?")
|
||||||
|
(org-match-string-no-properties 1)))
|
||||||
;; Switches analysis
|
;; Switches analysis
|
||||||
(number-lines (cond ((not switches) nil)
|
(number-lines
|
||||||
((string-match "-n\\>" switches) 'new)
|
(cond ((not switches) nil)
|
||||||
((string-match "+n\\>" switches) 'continued)))
|
((string-match "-n\\>" switches) 'new)
|
||||||
(preserve-indent (and switches (string-match "-i\\>" switches)))
|
((string-match "+n\\>" switches) 'continued)))
|
||||||
|
(preserve-indent
|
||||||
|
(or org-src-preserve-indentation
|
||||||
|
(and switches (string-match "-i\\>" switches))))
|
||||||
;; Should labels be retained in (or stripped from) example
|
;; Should labels be retained in (or stripped from) example
|
||||||
;; blocks?
|
;; blocks?
|
||||||
(retain-labels
|
(retain-labels
|
||||||
|
@ -1686,18 +1719,23 @@ keywords."
|
||||||
;; line-numbers?
|
;; line-numbers?
|
||||||
(use-labels
|
(use-labels
|
||||||
(or (not switches)
|
(or (not switches)
|
||||||
(and retain-labels (not (string-match "-k\\>" switches)))))
|
(and retain-labels
|
||||||
(label-fmt (and switches
|
(not (string-match "-k\\>" switches)))))
|
||||||
(string-match "-l +\"\\([^\"\n]+\\)\"" switches)
|
(label-fmt
|
||||||
(match-string 1 switches)))
|
(and switches
|
||||||
|
(string-match "-l +\"\\([^\"\n]+\\)\"" switches)
|
||||||
|
(match-string 1 switches)))
|
||||||
;; Standard block parsing.
|
;; Standard block parsing.
|
||||||
(begin (car affiliated))
|
(begin (car affiliated))
|
||||||
(post-affiliated (point))
|
(post-affiliated (point))
|
||||||
|
(block-ind (progn (skip-chars-forward " \t") (current-column)))
|
||||||
(contents-begin (progn (forward-line) (point)))
|
(contents-begin (progn (forward-line) (point)))
|
||||||
(hidden (org-invisible-p2))
|
(hidden (org-invisible-p2))
|
||||||
(value (org-unescape-code-in-string
|
(value (org-element--remove-indentation
|
||||||
(buffer-substring-no-properties
|
(org-unescape-code-in-string
|
||||||
contents-begin contents-end)))
|
(buffer-substring-no-properties
|
||||||
|
contents-begin contents-end))
|
||||||
|
(and preserve-indent block-ind)))
|
||||||
(pos-before-blank (progn (goto-char contents-end)
|
(pos-before-blank (progn (goto-char contents-end)
|
||||||
(forward-line)
|
(forward-line)
|
||||||
(point)))
|
(point)))
|
||||||
|
@ -1725,9 +1763,8 @@ keywords."
|
||||||
CONTENTS is nil."
|
CONTENTS is nil."
|
||||||
(let ((switches (org-element-property :switches example-block)))
|
(let ((switches (org-element-property :switches example-block)))
|
||||||
(concat "#+BEGIN_EXAMPLE" (and switches (concat " " switches)) "\n"
|
(concat "#+BEGIN_EXAMPLE" (and switches (concat " " switches)) "\n"
|
||||||
(org-remove-indentation
|
(org-escape-code-in-string
|
||||||
(org-escape-code-in-string
|
(org-element-property :value example-block))
|
||||||
(org-element-property :value example-block)))
|
|
||||||
"#+END_EXAMPLE")))
|
"#+END_EXAMPLE")))
|
||||||
|
|
||||||
|
|
||||||
|
@ -2224,13 +2261,17 @@ Assume point is at the beginning of the block."
|
||||||
;; Get parameters.
|
;; Get parameters.
|
||||||
(parameters (org-match-string-no-properties 3))
|
(parameters (org-match-string-no-properties 3))
|
||||||
;; Switches analysis
|
;; Switches analysis
|
||||||
(number-lines (cond ((not switches) nil)
|
(number-lines
|
||||||
((string-match "-n\\>" switches) 'new)
|
(cond ((not switches) nil)
|
||||||
((string-match "+n\\>" switches) 'continued)))
|
((string-match "-n\\>" switches) 'new)
|
||||||
(preserve-indent (and switches (string-match "-i\\>" switches)))
|
((string-match "+n\\>" switches) 'continued)))
|
||||||
(label-fmt (and switches
|
(preserve-indent (or org-src-preserve-indentation
|
||||||
(string-match "-l +\"\\([^\"\n]+\\)\"" switches)
|
(and switches
|
||||||
(match-string 1 switches)))
|
(string-match "-i\\>" switches))))
|
||||||
|
(label-fmt
|
||||||
|
(and switches
|
||||||
|
(string-match "-l +\"\\([^\"\n]+\\)\"" switches)
|
||||||
|
(match-string 1 switches)))
|
||||||
;; Should labels be retained in (or stripped from)
|
;; Should labels be retained in (or stripped from)
|
||||||
;; src blocks?
|
;; src blocks?
|
||||||
(retain-labels
|
(retain-labels
|
||||||
|
@ -2241,12 +2282,18 @@ Assume point is at the beginning of the block."
|
||||||
;; line-numbers?
|
;; line-numbers?
|
||||||
(use-labels
|
(use-labels
|
||||||
(or (not switches)
|
(or (not switches)
|
||||||
(and retain-labels (not (string-match "-k\\>" switches)))))
|
(and retain-labels
|
||||||
|
(not (string-match "-k\\>" switches)))))
|
||||||
|
;; Indentation.
|
||||||
|
(block-ind (progn (skip-chars-forward " \t") (current-column)))
|
||||||
;; Get visibility status.
|
;; Get visibility status.
|
||||||
(hidden (progn (forward-line) (org-invisible-p2)))
|
(hidden (progn (forward-line) (org-invisible-p2)))
|
||||||
;; Retrieve code.
|
;; Retrieve code.
|
||||||
(value (org-unescape-code-in-string
|
(value (org-element--remove-indentation
|
||||||
(buffer-substring-no-properties (point) contents-end)))
|
(org-unescape-code-in-string
|
||||||
|
(buffer-substring-no-properties
|
||||||
|
(point) contents-end))
|
||||||
|
(and preserve-indent block-ind)))
|
||||||
(pos-before-blank (progn (goto-char contents-end)
|
(pos-before-blank (progn (goto-char contents-end)
|
||||||
(forward-line)
|
(forward-line)
|
||||||
(point)))
|
(point)))
|
||||||
|
@ -2282,15 +2329,13 @@ CONTENTS is nil."
|
||||||
(params (org-element-property :parameters src-block))
|
(params (org-element-property :parameters src-block))
|
||||||
(value (let ((val (org-element-property :value src-block)))
|
(value (let ((val (org-element-property :value src-block)))
|
||||||
(cond
|
(cond
|
||||||
(org-src-preserve-indentation val)
|
((org-element-property :preserve-indent src-block) val)
|
||||||
((zerop org-edit-src-content-indentation)
|
((zerop org-edit-src-content-indentation) val)
|
||||||
(org-remove-indentation val))
|
|
||||||
(t
|
(t
|
||||||
(let ((ind (make-string
|
(let ((ind (make-string
|
||||||
org-edit-src-content-indentation 32)))
|
org-edit-src-content-indentation 32)))
|
||||||
(replace-regexp-in-string
|
(replace-regexp-in-string
|
||||||
"\\(^\\)[ \t]*\\S-" ind
|
"\\(^\\)[ \t]*\\S-" ind val nil nil 1)))))))
|
||||||
(org-remove-indentation val) nil nil 1)))))))
|
|
||||||
(concat (format "#+BEGIN_SRC%s\n"
|
(concat (format "#+BEGIN_SRC%s\n"
|
||||||
(concat (and lang (concat " " lang))
|
(concat (and lang (concat " " lang))
|
||||||
(and switches (concat " " switches))
|
(and switches (concat " " switches))
|
||||||
|
|
15
lisp/ox.el
15
lisp/ox.el
|
@ -4218,16 +4218,11 @@ line (string)."
|
||||||
(let* ((line 0) refs
|
(let* ((line 0) refs
|
||||||
;; Get code and clean it. Remove blank lines at its
|
;; Get code and clean it. Remove blank lines at its
|
||||||
;; beginning and end.
|
;; beginning and end.
|
||||||
(code (let ((c (replace-regexp-in-string
|
(code (replace-regexp-in-string
|
||||||
"\\`\\([ \t]*\n\\)+" ""
|
"\\`\\([ \t]*\n\\)+" ""
|
||||||
(replace-regexp-in-string
|
(replace-regexp-in-string
|
||||||
"\\([ \t]*\n\\)*[ \t]*\\'" "\n"
|
"\\([ \t]*\n\\)*[ \t]*\\'" "\n"
|
||||||
(org-element-property :value element)))))
|
(org-element-property :value element))))
|
||||||
;; If appropriate, remove global indentation.
|
|
||||||
(if (or org-src-preserve-indentation
|
|
||||||
(org-element-property :preserve-indent element))
|
|
||||||
c
|
|
||||||
(org-remove-indentation c))))
|
|
||||||
;; Get format used for references.
|
;; Get format used for references.
|
||||||
(label-fmt (regexp-quote
|
(label-fmt (regexp-quote
|
||||||
(or (org-element-property :label-fmt element)
|
(or (org-element-property :label-fmt element)
|
||||||
|
|
|
@ -513,121 +513,155 @@ Some other text
|
||||||
(org-test-with-temp-text "#+BEGIN_EXAMPLE\nText\n#+END_EXAMPLE"
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE\nText\n#+END_EXAMPLE"
|
||||||
(org-element-map (org-element-parse-buffer) 'example-block 'identity)))
|
(org-element-map (org-element-parse-buffer) 'example-block 'identity)))
|
||||||
;; Test folded block.
|
;; Test folded block.
|
||||||
(org-test-with-temp-text "#+BEGIN_EXAMPLE\nText\n#+END_EXAMPLE"
|
(should
|
||||||
(org-cycle)
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE\nText\n#+END_EXAMPLE"
|
||||||
(should
|
(org-cycle)
|
||||||
(org-element-property
|
(org-element-property :hiddenp (org-element-at-point))))
|
||||||
:hiddenp
|
|
||||||
(org-element-map
|
|
||||||
(org-element-parse-buffer) 'example-block 'identity nil t))))
|
|
||||||
;; Ignore incomplete block.
|
;; Ignore incomplete block.
|
||||||
(should-not
|
(should-not
|
||||||
(org-test-with-temp-text "#+BEGIN_EXAMPLE"
|
(eq 'example-block
|
||||||
(org-element-map
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE"
|
||||||
(org-element-parse-buffer) 'example-block 'identity nil t)))
|
(org-element-type (org-element-at-point)))))
|
||||||
;; Properly un-escape code.
|
;; Properly un-escape code.
|
||||||
(should
|
(should
|
||||||
(equal "* Headline\n #+keyword\nText\n"
|
(equal "* Headline\n #+keyword\nText\n"
|
||||||
(org-test-with-temp-text
|
(org-test-with-temp-text
|
||||||
"#+BEGIN_EXAMPLE\n,* Headline\n ,#+keyword\nText\n#+END_EXAMPLE"
|
"#+BEGIN_EXAMPLE\n,* Headline\n ,#+keyword\nText\n#+END_EXAMPLE"
|
||||||
(org-element-property :value (org-element-at-point))))))
|
(org-element-property :value (org-element-at-point)))))
|
||||||
|
;; Nil `org-src-preserve-indentation': Remove maximum common
|
||||||
|
;; indentation.
|
||||||
|
(should
|
||||||
|
(equal " L1\nL2\n"
|
||||||
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE\n L1\n L2\n#+END_EXAMPLE"
|
||||||
|
(let ((org-src-preserve-indentation nil))
|
||||||
|
(org-element-property :value (org-element-at-point))))))
|
||||||
|
;; Non-nil `org-src-preserve-indentation': Remove block indentation
|
||||||
|
;; only, unless block contents are less indented than block
|
||||||
|
;; boundaries.
|
||||||
|
(should
|
||||||
|
(equal " L1\nL2\n"
|
||||||
|
(org-test-with-temp-text " #+BEGIN_EXAMPLE\n L1\n L2\n #+END_EXAMPLE"
|
||||||
|
(let ((org-src-preserve-indentation t))
|
||||||
|
(org-element-property :value (org-element-at-point))))))
|
||||||
|
(should
|
||||||
|
(equal
|
||||||
|
" L1\n L2\n"
|
||||||
|
(org-test-with-temp-text " #+BEGIN_EXAMPLE\n L1\n L2\n #+END_EXAMPLE"
|
||||||
|
(let ((org-src-preserve-indentation t))
|
||||||
|
(org-element-property :value (org-element-at-point)))))))
|
||||||
|
|
||||||
(ert-deftest test-org-element/block-switches ()
|
(ert-deftest test-org-element/block-switches ()
|
||||||
"Test `example-block' and `src-block' switches parsing."
|
"Test `example-block' and `src-block' switches parsing."
|
||||||
(let ((org-coderef-label-format "(ref:%s)"))
|
(let ((org-coderef-label-format "(ref:%s)"))
|
||||||
;; 1. Test "-i" switch.
|
;; 1. Test "-i" switch.
|
||||||
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
|
(should-not
|
||||||
(should-not
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
|
||||||
(org-element-property :preserve-indent (org-element-at-point))))
|
(org-element-property :preserve-indent (org-element-at-point))))
|
||||||
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
|
(should
|
||||||
(should (org-element-property :preserve-indent (org-element-at-point))))
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
|
||||||
(org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
|
(org-element-property :preserve-indent (org-element-at-point))))
|
||||||
(should-not
|
(should-not
|
||||||
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
|
||||||
|
(org-element-property :preserve-indent (org-element-at-point))))
|
||||||
|
(should
|
||||||
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE -i\nText.\n#+END_EXAMPLE"
|
||||||
(org-element-property :preserve-indent (org-element-at-point))))
|
(org-element-property :preserve-indent (org-element-at-point))))
|
||||||
(org-test-with-temp-text "#+BEGIN_EXAMPLE -i\nText.\n#+END_EXAMPLE"
|
|
||||||
(should (org-element-property :preserve-indent (org-element-at-point))))
|
|
||||||
;; 2. "-n -r -k" combination should number lines, retain labels but
|
;; 2. "-n -r -k" combination should number lines, retain labels but
|
||||||
;; not use them in coderefs.
|
;; not use them in coderefs.
|
||||||
(org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r -k\nText.\n#+END_EXAMPLE"
|
(should
|
||||||
(let ((element (org-element-at-point)))
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r -k\nText.\n#+END_EXAMPLE"
|
||||||
(should (and (org-element-property :number-lines element)
|
(let ((element (org-element-at-point)))
|
||||||
(org-element-property :retain-labels element)
|
(and (org-element-property :number-lines element)
|
||||||
(not (org-element-property :use-labels element))))))
|
(org-element-property :retain-labels element)
|
||||||
(org-test-with-temp-text
|
(not (org-element-property :use-labels element))))))
|
||||||
"#+BEGIN_SRC emacs-lisp -n -r -k\n(+ 1 1)\n#+END_SRC"
|
(should
|
||||||
(let ((element (org-element-at-point)))
|
(org-test-with-temp-text
|
||||||
(should (and (org-element-property :number-lines element)
|
"#+BEGIN_SRC emacs-lisp -n -r -k\n(+ 1 1)\n#+END_SRC"
|
||||||
(org-element-property :retain-labels element)
|
(let ((element (org-element-at-point)))
|
||||||
(not (org-element-property :use-labels element))))))
|
(and (org-element-property :number-lines element)
|
||||||
|
(org-element-property :retain-labels element)
|
||||||
|
(not (org-element-property :use-labels element))))))
|
||||||
;; 3. "-n -r" combination should number-lines remove labels and not
|
;; 3. "-n -r" combination should number-lines remove labels and not
|
||||||
;; use them in coderefs.
|
;; use them in coderefs.
|
||||||
(org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r\nText.\n#+END_EXAMPLE"
|
(should
|
||||||
(let ((element (org-element-at-point)))
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r\nText.\n#+END_EXAMPLE"
|
||||||
(should (and (org-element-property :number-lines element)
|
(let ((element (org-element-at-point)))
|
||||||
(not (org-element-property :retain-labels element))
|
(and (org-element-property :number-lines element)
|
||||||
(not (org-element-property :use-labels element))))))
|
(not (org-element-property :retain-labels element))
|
||||||
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1)\n#+END_SRC"
|
(not (org-element-property :use-labels element))))))
|
||||||
(let ((element (org-element-at-point)))
|
(should
|
||||||
(should (and (org-element-property :number-lines element)
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1)\n#+END_SRC"
|
||||||
(not (org-element-property :retain-labels element))
|
(let ((element (org-element-at-point)))
|
||||||
(not (org-element-property :use-labels element))))))
|
(and (org-element-property :number-lines element)
|
||||||
|
(not (org-element-property :retain-labels element))
|
||||||
|
(not (org-element-property :use-labels element))))))
|
||||||
;; 4. "-n" or "+n" should number lines, retain labels and use them
|
;; 4. "-n" or "+n" should number lines, retain labels and use them
|
||||||
;; in coderefs.
|
;; in coderefs.
|
||||||
(org-test-with-temp-text "#+BEGIN_EXAMPLE -n\nText.\n#+END_EXAMPLE"
|
(should
|
||||||
(let ((element (org-element-at-point)))
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE -n\nText.\n#+END_EXAMPLE"
|
||||||
(should (and (org-element-property :number-lines element)
|
(let ((element (org-element-at-point)))
|
||||||
(org-element-property :retain-labels element)
|
(and (org-element-property :number-lines element)
|
||||||
(org-element-property :use-labels element)))))
|
(org-element-property :retain-labels element)
|
||||||
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1)\n#+END_SRC"
|
(org-element-property :use-labels element)))))
|
||||||
(let ((element (org-element-at-point)))
|
(should
|
||||||
(should (and (org-element-property :number-lines element)
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1)\n#+END_SRC"
|
||||||
(org-element-property :retain-labels element)
|
(let ((element (org-element-at-point)))
|
||||||
(org-element-property :use-labels element)))))
|
(and (org-element-property :number-lines element)
|
||||||
(org-test-with-temp-text "#+BEGIN_EXAMPLE +n\nText.\n#+END_EXAMPLE"
|
(org-element-property :retain-labels element)
|
||||||
(let ((element (org-element-at-point)))
|
(org-element-property :use-labels element)))))
|
||||||
(should (and (org-element-property :number-lines element)
|
(should
|
||||||
(org-element-property :retain-labels element)
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE +n\nText.\n#+END_EXAMPLE"
|
||||||
(org-element-property :use-labels element)))))
|
(let ((element (org-element-at-point)))
|
||||||
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp +n\n(+ 1 1)\n#+END_SRC"
|
(and (org-element-property :number-lines element)
|
||||||
(let ((element (org-element-at-point)))
|
(org-element-property :retain-labels element)
|
||||||
(should (and (org-element-property :number-lines element)
|
(org-element-property :use-labels element)))))
|
||||||
(org-element-property :retain-labels element)
|
(should
|
||||||
(org-element-property :use-labels element)))))
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp +n\n(+ 1 1)\n#+END_SRC"
|
||||||
|
(let ((element (org-element-at-point)))
|
||||||
|
(and (org-element-property :number-lines element)
|
||||||
|
(org-element-property :retain-labels element)
|
||||||
|
(org-element-property :use-labels element)))))
|
||||||
;; 5. No switch should not number lines, but retain labels and use
|
;; 5. No switch should not number lines, but retain labels and use
|
||||||
;; them in coderefs.
|
;; them in coderefs.
|
||||||
(org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
|
(should
|
||||||
(let ((element (org-element-at-point)))
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
|
||||||
(should (and (not (org-element-property :number-lines element))
|
(let ((element (org-element-at-point)))
|
||||||
(org-element-property :retain-labels element)
|
(and (not (org-element-property :number-lines element))
|
||||||
(org-element-property :use-labels element)))))
|
(org-element-property :retain-labels element)
|
||||||
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
|
(org-element-property :use-labels element)))))
|
||||||
(let ((element (org-element-at-point)))
|
(should
|
||||||
(should (and (not (org-element-property :number-lines element))
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
|
||||||
(org-element-property :retain-labels element)
|
(let ((element (org-element-at-point)))
|
||||||
(org-element-property :use-labels element)))))
|
(and (not (org-element-property :number-lines element))
|
||||||
|
(org-element-property :retain-labels element)
|
||||||
|
(org-element-property :use-labels element)))))
|
||||||
;; 6. "-r" switch only: do not number lines, remove labels, and
|
;; 6. "-r" switch only: do not number lines, remove labels, and
|
||||||
;; don't use labels in coderefs.
|
;; don't use labels in coderefs.
|
||||||
(org-test-with-temp-text "#+BEGIN_EXAMPLE -r\nText.\n#+END_EXAMPLE"
|
(should
|
||||||
(let ((element (org-element-at-point)))
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE -r\nText.\n#+END_EXAMPLE"
|
||||||
(should (and (not (org-element-property :number-lines element))
|
(let ((element (org-element-at-point)))
|
||||||
(not (org-element-property :retain-labels element))
|
(and (not (org-element-property :number-lines element))
|
||||||
(not (org-element-property :use-labels element))))))
|
(not (org-element-property :retain-labels element))
|
||||||
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1)\n#+END_SRC"
|
(not (org-element-property :use-labels element))))))
|
||||||
(let ((element (org-element-at-point)))
|
(should
|
||||||
(should (and (not (org-element-property :number-lines element))
|
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1)\n#+END_SRC"
|
||||||
(not (org-element-property :retain-labels element))
|
(let ((element (org-element-at-point)))
|
||||||
(not (org-element-property :use-labels element))))))
|
(and (not (org-element-property :number-lines element))
|
||||||
|
(not (org-element-property :retain-labels element))
|
||||||
|
(not (org-element-property :use-labels element))))))
|
||||||
;; 7. Recognize coderefs with user-defined syntax.
|
;; 7. Recognize coderefs with user-defined syntax.
|
||||||
(org-test-with-temp-text
|
(should
|
||||||
"#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText [ref:text]\n#+END_EXAMPLE"
|
(equal
|
||||||
(let ((element (org-element-at-point)))
|
"[ref:%s]"
|
||||||
(should
|
(org-test-with-temp-text
|
||||||
(equal (org-element-property :label-fmt element) "[ref:%s]"))))
|
"#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText [ref:text]\n#+END_EXAMPLE"
|
||||||
(org-test-with-temp-text
|
(org-element-property :label-fmt (org-element-at-point)))))
|
||||||
"#+BEGIN_SRC emacs-lisp -l \"[ref:%s]\"\n(+ 1 1) [ref:text]\n#+END_SRC"
|
(should
|
||||||
(let ((element (org-element-at-point)))
|
(equal
|
||||||
(should
|
"[ref:%s]"
|
||||||
(equal (org-element-property :label-fmt element) "[ref:%s]"))))))
|
(org-test-with-temp-text
|
||||||
|
"#+BEGIN_SRC emacs-lisp -l \"[ref:%s]\"\n(+ 1 1) [ref:text]\n#+END_SRC"
|
||||||
|
(org-element-property :label-fmt (org-element-at-point)))))))
|
||||||
|
|
||||||
|
|
||||||
;;;; Export Block
|
;;;; Export Block
|
||||||
|
@ -1641,16 +1675,13 @@ Outside list"
|
||||||
"Test `src-block' parser."
|
"Test `src-block' parser."
|
||||||
;; Regular tests.
|
;; Regular tests.
|
||||||
(should
|
(should
|
||||||
(org-test-with-temp-text "#+BEGIN_SRC\nText\n#+END_SRC"
|
(org-test-with-temp-text "#+BEGIN_SRC org\nText\n#+END_SRC"
|
||||||
(org-element-map (org-element-parse-buffer) 'src-block 'identity)))
|
(org-element-map (org-element-parse-buffer) 'src-block 'identity)))
|
||||||
;; Test folded block.
|
;; Test folded block.
|
||||||
(org-test-with-temp-text "#+BEGIN_SRC\nText\n#+END_SRC"
|
(should
|
||||||
(org-cycle)
|
(org-test-with-temp-text "#+BEGIN_SRC org\nText\n#+END_SRC"
|
||||||
(should
|
(org-cycle)
|
||||||
(org-element-property
|
(org-element-property :hiddenp (org-element-at-point))))
|
||||||
:hiddenp
|
|
||||||
(org-element-map
|
|
||||||
(org-element-parse-buffer) 'src-block 'identity nil t))))
|
|
||||||
;; Ignore incomplete block.
|
;; Ignore incomplete block.
|
||||||
(should-not
|
(should-not
|
||||||
(org-test-with-temp-text "#+BEGIN_SRC"
|
(org-test-with-temp-text "#+BEGIN_SRC"
|
||||||
|
@ -1660,7 +1691,28 @@ Outside list"
|
||||||
(equal "* Headline\n #+keyword\nText\n"
|
(equal "* Headline\n #+keyword\nText\n"
|
||||||
(org-test-with-temp-text
|
(org-test-with-temp-text
|
||||||
"#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText\n#+END_SRC"
|
"#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText\n#+END_SRC"
|
||||||
(org-element-property :value (org-element-at-point))))))
|
(org-element-property :value (org-element-at-point)))))
|
||||||
|
;; Nil `org-src-preserve-indentation': Remove maximum common
|
||||||
|
;; indentation.
|
||||||
|
(should
|
||||||
|
(equal " L1\nL2\n"
|
||||||
|
(org-test-with-temp-text "#+BEGIN_SRC org\n L1\n L2\n#+END_SRC"
|
||||||
|
(let ((org-src-preserve-indentation nil))
|
||||||
|
(org-element-property :value (org-element-at-point))))))
|
||||||
|
;; Non-nil `org-src-preserve-indentation': Remove block indentation
|
||||||
|
;; only, unless block contents are less indented than block
|
||||||
|
;; boundaries.
|
||||||
|
(should
|
||||||
|
(equal " L1\nL2\n"
|
||||||
|
(org-test-with-temp-text " #+BEGIN_SRC org\n L1\n L2\n #+END_SRC"
|
||||||
|
(let ((org-src-preserve-indentation t))
|
||||||
|
(org-element-property :value (org-element-at-point))))))
|
||||||
|
(should
|
||||||
|
(equal
|
||||||
|
" L1\n L2\n"
|
||||||
|
(org-test-with-temp-text " #+BEGIN_SRC org\n L1\n L2\n #+END_SRC"
|
||||||
|
(let ((org-src-preserve-indentation t))
|
||||||
|
(org-element-property :value (org-element-at-point)))))))
|
||||||
|
|
||||||
|
|
||||||
;;;; Statistics Cookie
|
;;;; Statistics Cookie
|
||||||
|
@ -2272,9 +2324,24 @@ DEADLINE: <2012-01-01> SCHEDULED: <2012-01-01> CLOSED: [2012-01-01]\n"))))
|
||||||
"#+BEGIN_SRC emacs-lisp -n -k\n (+ 1 1)\n#+END_SRC\n"))
|
"#+BEGIN_SRC emacs-lisp -n -k\n (+ 1 1)\n#+END_SRC\n"))
|
||||||
;; Preserve code escaping.
|
;; Preserve code escaping.
|
||||||
(should
|
(should
|
||||||
(equal (org-test-parse-and-interpret
|
(equal (let ((org-edit-src-content-indentation 2))
|
||||||
"#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText #+END_SRC")
|
(org-test-parse-and-interpret
|
||||||
"#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText #+END_SRC\n")))
|
"#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText #+END_SRC"))
|
||||||
|
"#+BEGIN_SRC org\n,* Headline\n ,#+keyword\nText #+END_SRC\n"))
|
||||||
|
;; Do not apply `org-edit-src-content-indentation' when preserving
|
||||||
|
;; indentation.
|
||||||
|
(should
|
||||||
|
(equal (let ((org-edit-src-content-indentation 2)
|
||||||
|
(org-src-preserve-indentation t))
|
||||||
|
(org-test-parse-and-interpret
|
||||||
|
"#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"))
|
||||||
|
"#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC\n"))
|
||||||
|
(should
|
||||||
|
(equal (let ((org-edit-src-content-indentation 2)
|
||||||
|
(org-src-preserve-indentation nil))
|
||||||
|
(org-test-parse-and-interpret
|
||||||
|
"#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"))
|
||||||
|
"#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC\n")))
|
||||||
|
|
||||||
(ert-deftest test-org-element/table-interpreter ()
|
(ert-deftest test-org-element/table-interpreter ()
|
||||||
"Test table, table-row and table-cell interpreters."
|
"Test table, table-row and table-cell interpreters."
|
||||||
|
|
|
@ -1739,23 +1739,30 @@ Another text. (ref:text)
|
||||||
|
|
||||||
(ert-deftest test-org-export/unravel-code ()
|
(ert-deftest test-org-export/unravel-code ()
|
||||||
"Test `org-export-unravel-code' function."
|
"Test `org-export-unravel-code' function."
|
||||||
(let ((org-coderef-label-format "(ref:%s)"))
|
;; Code without reference.
|
||||||
;; 1. Code without reference.
|
(should
|
||||||
(org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
|
(equal '("(+ 1 1)\n")
|
||||||
(should (equal (org-export-unravel-code (org-element-at-point))
|
(org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
|
||||||
'("(+ 1 1)\n"))))
|
(org-export-unravel-code (org-element-at-point)))))
|
||||||
;; 2. Code with reference.
|
;; Code with reference.
|
||||||
(org-test-with-temp-text
|
(should
|
||||||
"#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
|
(equal '("(+ 1 1)\n" (1 . "test"))
|
||||||
(should (equal (org-export-unravel-code (org-element-at-point))
|
(org-test-with-temp-text
|
||||||
'("(+ 1 1)\n" (1 . "test")))))
|
"#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
|
||||||
;; 3. Code with user-defined reference.
|
(let ((org-coderef-label-format "(ref:%s)"))
|
||||||
|
(org-export-unravel-code (org-element-at-point))))))
|
||||||
|
;; Code with user-defined reference.
|
||||||
|
(should
|
||||||
|
(equal
|
||||||
|
'("(+ 1 1)\n" (1 . "test"))
|
||||||
(org-test-with-temp-text
|
(org-test-with-temp-text
|
||||||
"#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
|
"#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
|
||||||
(should (equal (org-export-unravel-code (org-element-at-point))
|
(let ((org-coderef-label-format "(ref:%s)"))
|
||||||
'("(+ 1 1)\n" (1 . "test")))))
|
(org-export-unravel-code (org-element-at-point))))))
|
||||||
;; 4. Code references keys are relative to the current block.
|
;; Code references keys are relative to the current block.
|
||||||
(org-test-with-temp-text "
|
(should
|
||||||
|
(equal '("(+ 2 2)\n(+ 3 3)\n" (2 . "one"))
|
||||||
|
(org-test-with-temp-text "
|
||||||
#+BEGIN_EXAMPLE -n
|
#+BEGIN_EXAMPLE -n
|
||||||
\(+ 1 1)
|
\(+ 1 1)
|
||||||
#+END_EXAMPLE
|
#+END_EXAMPLE
|
||||||
|
@ -1763,9 +1770,9 @@ Another text. (ref:text)
|
||||||
\(+ 2 2)
|
\(+ 2 2)
|
||||||
\(+ 3 3) (ref:one)
|
\(+ 3 3) (ref:one)
|
||||||
#+END_EXAMPLE"
|
#+END_EXAMPLE"
|
||||||
(goto-line 5)
|
(goto-line 5)
|
||||||
(should (equal (org-export-unravel-code (org-element-at-point))
|
(let ((org-coderef-label-format "(ref:%s)"))
|
||||||
'("(+ 2 2)\n(+ 3 3)\n" (2 . "one")))))))
|
(org-export-unravel-code (org-element-at-point)))))))
|
||||||
|
|
||||||
(ert-deftest test-org-export/format-code-default ()
|
(ert-deftest test-org-export/format-code-default ()
|
||||||
"Test `org-export-format-code-default' specifications."
|
"Test `org-export-format-code-default' specifications."
|
||||||
|
|
Loading…
Reference in New Issue