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,33 +1506,32 @@ Return a list whose CAR is `src-block' and CDR is a plist
|
|||
containing `:language', `:switches', `:parameters', `:begin',
|
||||
`:end', `:hiddenp', `:contents-begin', `:contents-end',
|
||||
`: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
|
||||
(end-of-line)
|
||||
(looking-at
|
||||
(concat
|
||||
"^[ \t]*#\\+BEGIN_SRC"
|
||||
"\\(?: +\\(\\S-+\\)\\)?" ; language
|
||||
"\\(\\(?: +\\(?:-l \".*?\"\\|[-+][A-Za-z]\\)\\)+\\)?" ; switches
|
||||
"\\(.*\\)[ \t]*$")) ; parameters
|
||||
(let* ((case-fold-search t)
|
||||
;; Get position at beginning of block.
|
||||
(contents-begin
|
||||
(re-search-backward
|
||||
(concat
|
||||
"^[ \t]*#\\+BEGIN_SRC"
|
||||
"\\(?: +\\(\\S-+\\)\\)?" ; language
|
||||
"\\(\\(?: +\\(?:-l \".*?\"\\|[-+][A-Za-z]\\)\\)*\\)" ; switches
|
||||
"\\(.*\\)[ \t]*$") ; parameters
|
||||
nil t))
|
||||
(contents-begin (point))
|
||||
;; Get language as a string.
|
||||
(language (org-match-string-no-properties 1))
|
||||
;; Get parameters.
|
||||
(parameters (org-trim (org-match-string-no-properties 3)))
|
||||
;; Get switches.
|
||||
(switches (org-match-string-no-properties 2))
|
||||
;; Get parameters.
|
||||
(parameters (org-match-string-no-properties 3))
|
||||
;; Switches analysis
|
||||
(number-lines (cond ((not switches) nil)
|
||||
((string-match "-n\\>" switches) 'new)
|
||||
((string-match "+n\\>" switches) 'continued)))
|
||||
(preserve-indent (and switches (string-match "-i\\>" switches)))
|
||||
(label-fmt (and switches
|
||||
(string-match "-l +\"\\([^\"\n]+\\)\"" switches)
|
||||
(match-string 1 switches)))
|
||||
(string-match "-l +\"\\([^\"\n]+\\)\"" switches)
|
||||
(match-string 1 switches)))
|
||||
;; Should labels be retained in (or stripped from) src
|
||||
;; blocks?
|
||||
(retain-labels
|
||||
|
@ -1567,8 +1566,10 @@ containing `:language', `:switches', `:parameters', `:begin',
|
|||
(org-truely-invisible-p))))
|
||||
`(src-block
|
||||
(:language ,language
|
||||
:switches ,switches
|
||||
:parameters ,parameters
|
||||
:switches ,(and (org-string-nw-p switches)
|
||||
(org-trim switches))
|
||||
:parameters ,(and (org-string-nw-p parameters)
|
||||
(org-trim parameters))
|
||||
:begin ,begin
|
||||
:end ,end
|
||||
: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 ()
|
||||
"Test src block interpreter."
|
||||
;; With arguments.
|
||||
(should
|
||||
(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\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 ()
|
||||
"Test table, table-row and table-cell interpreters."
|
||||
|
|
Loading…
Reference in New Issue