From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kaushal Modi Subject: Re: Unable to retrieve :parameters for src-block [org-element] Date: Wed, 18 Oct 2017 21:20:04 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="f4030437f31045fa3c055bd8ce8b" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53876) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4vlC-0006Ky-P0 for emacs-orgmode@gnu.org; Wed, 18 Oct 2017 17:20:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4vlB-00083N-HY for emacs-orgmode@gnu.org; Wed, 18 Oct 2017 17:20:18 -0400 Received: from mail-yw0-x236.google.com ([2607:f8b0:4002:c05::236]:56743) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4vlB-00080k-6z for emacs-orgmode@gnu.org; Wed, 18 Oct 2017 17:20:17 -0400 Received: by mail-yw0-x236.google.com with SMTP id l32so1796939ywh.13 for ; Wed, 18 Oct 2017 14:20:15 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: "Berry, Charles" Cc: emacs-org list --f4030437f31045fa3c055bd8ce8b Content-Type: text/plain; charset="UTF-8" On Tue, Oct 17, 2017 at 5:39 PM Berry, Charles 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)))) ret) (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))) ret)) (advice-add 'org-babel-exp-code :around #'org-babel-exp-code--retain) ===== Test: ===== #+BEGIN_SRC emacs-lisp :eval no-export :results output silent :hl_lines 1,3-4 :foo bar (message "foo") #+END_SRC ===== 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 --f4030437f31045fa3c055bd8ce8b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue, Oct 17= , 2017 at 5:39 PM Berry, Charles <cc= berry@ucsd.edu> wrote:
I thi= nk 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 wi= th them to the string returned by org-babel-exp-code.=C2=A0 Then your src-b= lock transcoder can find them.

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

Thanks for the instr= uctions, below works perfectly!

=3D=3D=3D=3D=3D
(defun org-babel-exp-code--retain (orig-fun &rest args)
=C2=A0 "Return the original code block formatted for export."<= /div>
=C2=A0 (let* ((param-keys-to-be-retained '(:hl_lines :foo)) ;= Example of keys whose conses need to be retained
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(info (car args))
=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0(parameters (nth 2 info))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0(ox-hugo-params-str (let ((str ""))
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0(dolist (param parameters)
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(dolist (retain-key param-keys-to-be-retaine= d)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(when (equal= retain-key (car param))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(setq str (concat str " "
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(symbol-name retain-key) " &q= uot;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(cdr param)))= )))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-string-nw-p (org-t= rim str))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret)
=C2= =A0 =C2=A0 (setq ret (apply orig-fun args))=C2=A0 =C2=A0 ;Original return v= alue
=C2=A0 =C2=A0 (when ox-hugo-params-str
=C2=A0 =C2= =A0 =C2=A0 (setq ret (replace-regexp-in-string "\\`#\\+BEGIN_SRC .*&qu= ot; (format "\\& %s" ox-hugo-params-str) ret)))
=C2= =A0 =C2=A0 ret))
(advice-add 'org-babel-exp-code :around #= 9;org-babel-exp-code--retain)
=3D=3D=3D=3D=3D

Test:

=3D=3D=3D=3D=3D
#+BEGIN= _SRC emacs-lisp :eval no-export :results output silent :hl_lines 1,3-4 :foo= bar
(message "foo")
#+END_SRC
=3D=3D=3D=3D=3D
=C2=A0
The messages based on the debu= g code I pasted earlier in this thread now look like:

<= div>=3D=3D=3D=3D=3D
[src-block dbg] number-lines: nil
<= div>[src-block dbg] switches: nil
[src-block dbg] parameters: &qu= ot;:foo bar :hl_lines 1,3-4"
=3D=3D=3D=3D=3D

--

Kaushal Modi

--f4030437f31045fa3c055bd8ce8b--