From mboxrd@z Thu Jan 1 00:00:00 1970 From: James Harkins Subject: Re: Extract source code /with/ captions Date: Sat, 18 Jan 2014 02:20:27 +0000 (UTC) Message-ID: References: <3cbde2bd-2dba-4c2f-85b7-62fd2a9daffc@dewdrop-world.net> <87ob3fn75e.fsf@alphaville.bos.redhat.com> <87d2jvn4m3.fsf@alphaville.bos.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4LWu-0003NY-Br for emacs-orgmode@gnu.org; Fri, 17 Jan 2014 21:21:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W4LWn-0006xL-1u for emacs-orgmode@gnu.org; Fri, 17 Jan 2014 21:21:00 -0500 Received: from plane.gmane.org ([80.91.229.3]:41111) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4LWm-0006wd-Qu for emacs-orgmode@gnu.org; Fri, 17 Jan 2014 21:20:52 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1W4LWl-0000eW-Iw for emacs-orgmode@gnu.org; Sat, 18 Jan 2014 03:20:51 +0100 Received: from 113.103.24.19 ([113.103.24.19]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 18 Jan 2014 03:20:51 +0100 Received: from jamshark70 by 113.103.24.19 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 18 Jan 2014 03:20:51 +0100 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Nick Dokos gmail.com> writes: > Try: > > --8<---------------cut here---------------start------------->8--- > (defun hjh-print-src-blocks () > "Iterate src blocks from org-element and print them to *Messages*." > (interactive) > (let ((tree (org-element-parse-buffer))) > (org-element-map tree 'src-block > (lambda (element) > (message "\n\n\nELEMENT:") > (print (substring-no-properties (plist-get (car (cdr element)) :caption))))))) > --8<---------------cut here---------------end--------------->8--- Finally coming back to this. It seems that the actual string-with-properties may be nested at different levels within the :caption object. I tried Nick's version with a different test file, and it failed with a wrong type error. The "while" below seems to work, though I suppose it could throw an error under some circumstances. Is there an easier way to locate the real stringy-thingy in the middle of the structure, when you can't predict exactly what the structure will be? (defun hjh-print-src-blocks () "Iterate src blocks from org-element and print them to *Messages*." (interactive) (let ((tree (org-element-parse-buffer))) (org-element-map tree 'src-block (lambda (element) (setq element (car (cdr element))) (let ((caption (plist-get element :caption))) (while (and caption (not (stringp caption))) (setq caption (car caption))) (message "\n\n\nCAPTION:") (print (substring-no-properties caption))))))) hjh