org-element: Fix src-block switches parsing
* contrib/lisp/org-element.el (org-element-src-block-parser): Fix switches parsing. * testing/lisp/test-org-element.el: Add test.
This commit is contained in:
parent
99a5d6bea8
commit
15315c5cc6
|
@ -1506,25 +1506,24 @@ Return a list whose CAR is `src-block' and CDR is a plist
|
||||||
containing `:language', `:switches', `:parameters', `:begin',
|
containing `:language', `:switches', `:parameters', `:begin',
|
||||||
`:end', `:hiddenp', `:contents-begin', `:contents-end',
|
`:end', `:hiddenp', `:contents-begin', `:contents-end',
|
||||||
`:number-lines', `:retain-labels', `:use-labels', `:label-fmt',
|
`:number-lines', `:retain-labels', `:use-labels', `:label-fmt',
|
||||||
`:preserve-indent', `:value' and `:post-blank' keywords."
|
`:preserve-indent', `:value' and `:post-blank' keywords.
|
||||||
|
|
||||||
|
Assume point is at the beginning of the block."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(end-of-line)
|
(looking-at
|
||||||
(let* ((case-fold-search t)
|
|
||||||
;; Get position at beginning of block.
|
|
||||||
(contents-begin
|
|
||||||
(re-search-backward
|
|
||||||
(concat
|
(concat
|
||||||
"^[ \t]*#\\+BEGIN_SRC"
|
"^[ \t]*#\\+BEGIN_SRC"
|
||||||
"\\(?: +\\(\\S-+\\)\\)?" ; language
|
"\\(?: +\\(\\S-+\\)\\)?" ; language
|
||||||
"\\(\\(?: +\\(?:-l \".*?\"\\|[-+][A-Za-z]\\)\\)*\\)" ; switches
|
"\\(\\(?: +\\(?:-l \".*?\"\\|[-+][A-Za-z]\\)\\)+\\)?" ; switches
|
||||||
"\\(.*\\)[ \t]*$") ; parameters
|
"\\(.*\\)[ \t]*$")) ; parameters
|
||||||
nil t))
|
(let* ((case-fold-search t)
|
||||||
|
(contents-begin (point))
|
||||||
;; Get language as a string.
|
;; Get language as a string.
|
||||||
(language (org-match-string-no-properties 1))
|
(language (org-match-string-no-properties 1))
|
||||||
;; Get parameters.
|
|
||||||
(parameters (org-trim (org-match-string-no-properties 3)))
|
|
||||||
;; Get switches.
|
;; Get switches.
|
||||||
(switches (org-match-string-no-properties 2))
|
(switches (org-match-string-no-properties 2))
|
||||||
|
;; Get parameters.
|
||||||
|
(parameters (org-match-string-no-properties 3))
|
||||||
;; Switches analysis
|
;; Switches analysis
|
||||||
(number-lines (cond ((not switches) nil)
|
(number-lines (cond ((not switches) nil)
|
||||||
((string-match "-n\\>" switches) 'new)
|
((string-match "-n\\>" switches) 'new)
|
||||||
|
@ -1567,8 +1566,10 @@ containing `:language', `:switches', `:parameters', `:begin',
|
||||||
(org-truely-invisible-p))))
|
(org-truely-invisible-p))))
|
||||||
`(src-block
|
`(src-block
|
||||||
(:language ,language
|
(:language ,language
|
||||||
:switches ,switches
|
:switches ,(and (org-string-nw-p switches)
|
||||||
:parameters ,parameters
|
(org-trim switches))
|
||||||
|
:parameters ,(and (org-string-nw-p parameters)
|
||||||
|
(org-trim parameters))
|
||||||
:begin ,begin
|
:begin ,begin
|
||||||
:end ,end
|
:end ,end
|
||||||
:number-lines ,number-lines
|
:number-lines ,number-lines
|
||||||
|
|
|
@ -587,10 +587,16 @@ CLOSED: <2012-01-01> DEADLINE: <2012-01-01> SCHEDULED: <2012-01-01>\n"))))
|
||||||
|
|
||||||
(ert-deftest test-org-element/src-block-interpreter ()
|
(ert-deftest test-org-element/src-block-interpreter ()
|
||||||
"Test src block interpreter."
|
"Test src block interpreter."
|
||||||
|
;; With arguments.
|
||||||
(should
|
(should
|
||||||
(equal (org-test-parse-and-interpret
|
(equal (org-test-parse-and-interpret
|
||||||
"#+BEGIN_SRC emacs-lisp :results silent\n(+ 1 1)\n#+END_SRC")
|
"#+BEGIN_SRC emacs-lisp :results silent\n(+ 1 1)\n#+END_SRC")
|
||||||
"#+BEGIN_SRC emacs-lisp :results silent\n(+ 1 1)\n#+END_SRC\n")))
|
"#+BEGIN_SRC emacs-lisp :results silent\n(+ 1 1)\n#+END_SRC\n"))
|
||||||
|
;; With switches.
|
||||||
|
(should
|
||||||
|
(equal (org-test-parse-and-interpret
|
||||||
|
"#+BEGIN_SRC emacs-lisp -n -k\n(+ 1 1)\n#+END_SRC")
|
||||||
|
"#+BEGIN_SRC emacs-lisp -n -k\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."
|
||||||
|
|
Loading…
Reference in New Issue