[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Unable to retrieve :parameters for src-block [org-element]

From: Kaushal Modi
Subject: Re: [O] Unable to retrieve :parameters for src-block [org-element]
Date: Wed, 18 Oct 2017 21:20:04 +0000

On Tue, Oct 17, 2017 at 5:39 PM Berry, Charles <address@hidden> wrote:
I think this might work: Add `after' advice to `org-babel-exp-code' that copies the header args you want to retain and prepends a #+header: line with them to the string returned by org-babel-exp-code.  Then your src-block transcoder can find them.

Thanks, TIL about org-babel-exp-code.

Thanks for the instructions, below works perfectly!

(defun org-babel-exp-code--retain (orig-fun &rest args)
  "Return the original code block formatted for export."
  (let* ((param-keys-to-be-retained '(:hl_lines :foo)) ;Example of keys whose conses need to be retained
         (info (car args))
         (parameters (nth 2 info))
         (ox-hugo-params-str (let ((str ""))
                               (dolist (param parameters)
                                 (dolist (retain-key param-keys-to-be-retained)
                                   (when (equal retain-key (car param))
                                     (setq str (concat str " "
                                                       (symbol-name retain-key) " "
                                                       (cdr param))))))
                               (org-string-nw-p (org-trim str))))
    (setq ret (apply orig-fun args))    ;Original return value
    (when ox-hugo-params-str
      (setq ret (replace-regexp-in-string "\\`#\\+BEGIN_SRC .*" (format "\\& %s" ox-hugo-params-str) ret)))
(advice-add 'org-babel-exp-code :around #'org-babel-exp-code--retain)


#+BEGIN_SRC emacs-lisp :eval no-export :results output silent :hl_lines 1,3-4 :foo bar
(message "foo")
The messages based on the debug code I pasted earlier in this thread now look like:

[src-block dbg] number-lines: nil
[src-block dbg] switches: nil
[src-block dbg] parameters: ":foo bar :hl_lines 1,3-4"


Kaushal Modi

reply via email to

[Prev in Thread] Current Thread [Next in Thread]