help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: function to copy org buffer substring with link description only


From: Alexis
Subject: Re: function to copy org buffer substring with link description only
Date: Wed, 09 Dec 2015 18:25:56 +1100


Paul <mafeuser@gmail.com> writes:

thank YOu for the function

I believe that there must be something ready to be used, because org-mode does provide function that is able to export document or its part as text file. Of course such function probably removes more elements than link only, but that would be no harm.

Oh, well, if you're not worried about affecting other elements, then you could wrap the `org-export-as` function like so:

#+BEGIN_SRC emacs-lisp

(defun org-delinkify-region-2 () "Replace all Org-style links within the region with only the link description text, and return the result." (interactive) (org-export-as 'ascii nil t t)) #+END_SRC
The four arguments to `org-export-as` mean:

- Use the 'ascii export backend;
- Don't transcode the sub-tree at point; we're relying on `org-export-as` working on the region if the region is active.
- Don't export the contents of hidden elements.
- Don't add a surrounding template.

Note that `ox-ascii.el`, which defines the 'ascii export backend, /does/ have an `ox-ascii-link` function, but that function needs to be /passed/ the 'description' part of the link, the very thing we want to extract. In usual usage, this extraction is done by building a parse tree of an Org buffer, then calling `ox-ascii-link` with the relevant parse tree data for all links in the parse tree. So if i understand correctly, my code above is probably as simple as one can get for your use-case.

Hope that helps!


Alexis.



reply via email to

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