diff --git a/contrib/lisp/org-element.el b/contrib/lisp/org-element.el index 45215894e..c49f4d4d6 100644 --- a/contrib/lisp/org-element.el +++ b/contrib/lisp/org-element.el @@ -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 diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index b3133504a..94c17b700 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -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."