From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alexis Newsgroups: gmane.emacs.help Subject: Re: function to copy org buffer substring with link description only Date: Wed, 09 Dec 2015 18:25:56 +1100 Message-ID: <87fuzcqe0r.fsf@gmail.com> References: <56671464.7070707@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-Trace: ger.gmane.org 1449645993 8825 80.91.229.3 (9 Dec 2015 07:26:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 9 Dec 2015 07:26:33 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Paul Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 09 08:26:28 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1a6Z8m-0006V1-3f for geh-help-gnu-emacs@m.gmane.org; Wed, 09 Dec 2015 08:26:20 +0100 Original-Received: from localhost ([::1]:34951 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6Z8k-00057l-Vi for geh-help-gnu-emacs@m.gmane.org; Wed, 09 Dec 2015 02:26:18 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47200) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6Z8Z-00057f-RT for help-gnu-emacs@gnu.org; Wed, 09 Dec 2015 02:26:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a6Z8U-0003BD-N2 for help-gnu-emacs@gnu.org; Wed, 09 Dec 2015 02:26:07 -0500 Original-Received: from mail-pf0-x22c.google.com ([2607:f8b0:400e:c00::22c]:35168) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6Z8U-0003B1-Ho for help-gnu-emacs@gnu.org; Wed, 09 Dec 2015 02:26:02 -0500 Original-Received: by pfu207 with SMTP id 207so25712869pfu.2 for ; Tue, 08 Dec 2015 23:26:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=references:from:to:cc:subject:in-reply-to:date:message-id :mime-version:content-type; bh=46z5rvhCwECIa86lnuegDF/lIkBObhvWw054LMdIGas=; b=Jr8PDo0EKwW+hMrTjktc+rhJaRUIOjjHMWyKzoM6cBLNZI1OezcyFGnUgpIOqR5MIs zuOa9Q7ZPvwP4xOGFlOcUNBZCluZmpxev6Pj7WBigP7ClO2EYTM1EDtMHBnYo8t6KHOS HtdqxZftCLrJLnJ2Eiq6D0HbQltz08dL9Scl7Eu1Dl0GIZ985Nle2sS/h73/Zzvo3bLr KqN24eiR5l/Fv5gJdVRrWX+iakWNtaO8P/l8JtFmNc6Xxg8YVrJ5vtsVg/G/XalMS7t4 1gtvtYq6b3v+HDOM1LapeDTuBX2fUiDmfkfXziPcIS2mRd9ZMeTrKtGf3ZGu4BV/o4PQ txKQ== X-Received: by 10.98.12.205 with SMTP id 74mr10739587pfm.53.1449645961699; Tue, 08 Dec 2015 23:26:01 -0800 (PST) Original-Received: from localhost (ppp118-209-101-190.lns20.mel4.internode.on.net. [118.209.101.190]) by smtp.gmail.com with ESMTPSA id sv8sm9330539pab.13.2015.12.08.23.25.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Dec 2015 23:26:00 -0800 (PST) In-reply-to: <56671464.7070707@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::22c X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:108345 Archived-At: Paul 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.