From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id +ADuGFUZF2EhXwEAgWs5BA (envelope-from ) for ; Sat, 14 Aug 2021 03:16:05 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id yAKKFFUZF2ELFgAAB5/wlQ (envelope-from ) for ; Sat, 14 Aug 2021 01:16:05 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B3B9E2C244 for ; Sat, 14 Aug 2021 03:16:04 +0200 (CEST) Received: from localhost ([::1]:34144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mEiHL-0004Go-Bg for larch@yhetil.org; Fri, 13 Aug 2021 21:16:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEiGt-0004FQ-ON for emacs-orgmode@gnu.org; Fri, 13 Aug 2021 21:15:35 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:44018) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mEiGs-0007co-A4 for emacs-orgmode@gnu.org; Fri, 13 Aug 2021 21:15:35 -0400 Received: by mail-pj1-x102c.google.com with SMTP id qe12-20020a17090b4f8c00b00179321cbae7so7869098pjb.2 for ; Fri, 13 Aug 2021 18:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=V+yE3SwX4XHq0FISXDzsa6irp6XkYJVNPFVlErks+EQ=; b=d4BsJdL8GnmTd/t74trE2SZ/YPfzFDswSP7e2L0ci4WJ7arUqp9zfqbTofEjRSDFS7 46aYkMDmrRrcBqzL4ttspUEVAogLVjgrJdULfu7z40QlObw/Ud4x6393YUh5j5S+BOX4 e0QE+/RLflYb910GYmbFvI9emRbhxBRaqVbGgRuV5/cGcWnVLiWI1Twp+ejL9DQE8/nU ccA/6nK/bA3r7B0NU0FZCsT3jXIZY8nnQBWDhiGVQAJB6jalaJiIdtL3WojoUkZdHVVi ogXhoJ92my3SkdhG5w+mOJNiF46JL8P7Gci0d3dR6b627SZv16wOrkaK4yJltm0xBIij x2UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=V+yE3SwX4XHq0FISXDzsa6irp6XkYJVNPFVlErks+EQ=; b=JSij9hmzWovxGkTPOJ9ZbuG+vh74QmTwt8eYw+ApE00YG9wPy4hMeHznK7drm4JUFn IHUWsSG63X5K1zAAUIeqz8h16gg1IHT58HwhVijS5BOP7cUbkYVWpN3JmcjlDRhwFsot WaulzaxDI5eIGp0PtcFbYEBY16yvcWTg4ah+s9Y95MbP1PszlKJJ5gKXeqkY8VLji30B b2H1Rp0K4aHFpaDgEvAmm3BewBKh6doEPyWKxQLFVaMwexcXdGROlRU9iww/S0RVUpQw +9FY874MVzZIBdiOwLmIOmiPWXMRoYdNlxbjVLgYCph2WnK4rdiV1+q7fwXHBtXq4N2P vwdg== X-Gm-Message-State: AOAM532p5ad1Voy7yrn9mybpFRp984HQeVPrry52Go2oYLnXXT9Kw8kS Lfz1bZGvHuug8kAmSYRkme+nrBdc/7/Ftw== X-Google-Smtp-Source: ABdhPJzS2DSuqkO6TVZXkcxKrTCWkGJ2sONaf6jm6EGenZEhStqHugcNAApQ1Q0rZqQNNNZcYyKl8w== X-Received: by 2002:a65:4486:: with SMTP id l6mr4689872pgq.145.1628903732179; Fri, 13 Aug 2021 18:15:32 -0700 (PDT) Received: from r1 ([190.239.232.245]) by smtp.gmail.com with ESMTPSA id u6sm4189727pgr.3.2021.08.13.18.15.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Aug 2021 18:15:31 -0700 (PDT) From: Rodrigo Morales To: emacs-orgmode@gnu.org Subject: Function for retrieving the link of an Org Mode buffer Date: Fri, 13 Aug 2021 20:14:34 -0500 Message-ID: <87y2943k05.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=moralesrodrigo1100@gmail.com; helo=mail-pj1-x102c.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1628903765; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=V+yE3SwX4XHq0FISXDzsa6irp6XkYJVNPFVlErks+EQ=; b=H84cCuS20vfB4olFzL8SSCS7wsArOjWoYTh+aAM0XfitNBE65v7mN18y2wkjoeGWNC1Rcp DTdGZBamWu7h7FT7qwTWqa02j4/9gs6N+sMNU9jbPKvq3NGirJGaCMUYfz0WWSE8za/RWv LF4dp/8HF9GV+LtF9vH6OvBxMTGJE5ZmwFAVPZwoliIDYg9bQ9E6fKuIXdxDMLGgwywJTB XD92m6ZP8Zs5yRghXfnYorBWAwTGxUyGHd3Bl/nCfW6aUTO9Ybc8HdWq797N2yc2doQkZ4 dKu19Lq7/C2/LBYoorrly8WeQKHi6wAnqOOWVpLmoyK+RBBpuZOy1IrobDUSyQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1628903765; a=rsa-sha256; cv=none; b=szPnUFrXhnR9LlHgqvciB4c+tyv4zRMuA7wBxGPgDNvemSorBi6DV1esrdM9dxT/Td+9gb qRinehVKvYhvleESN1YaQPF7qn37Te7nL9slzErRupn9nqupOPujeJB6YZVTX7pBMl7mqt kIgcLXglOSetz97YeaisanopTpMvTk0AhY1kn49TsV9E8TQ6+XOHJjJ+pb+5PM7l/zEz2i UnpQCeAVc2oWI6xLMBLH1fJ8/cQzhTN1/iEzUrtKpdE8XDqEZ1A3HzM93wAzGE+CcpMQAF n2mKJuVyS1q0AxW9wDlfva+Nc68fSb/fyU/h2hz46ISBXTUs+2RIy3jYhkLDvA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=d4BsJdL8; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -3.11 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=d4BsJdL8; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: B3B9E2C244 X-Spam-Score: -3.11 X-Migadu-Scanner: scn0.migadu.com X-TUID: eQokAE+wZfvQ I've written the following function for retrieving the links from a given Org Mode buffer. #+BEGIN_SRC elisp (defun my/org-collect-links-in-buffer (buffer) "Collect all the links in the current buffer. If the link has a description, then it is also collected. Returns a list of PLISTS of the form: ((:link LINK) (:link LINK :desc DESC) (:link LINK))" (with-current-buffer buffer (save-excursion (beginning-of-buffer) (let (links) (while (re-search-forward org-any-link-re nil t) (catch 'done (let* ((element (org-element-context)) (type (org-element-type element))) (unless (eq type 'link) (throw 'done t)) (let (obj (link (org-element-property :raw-link element)) desc) (push link obj) (push :link obj) (when (and (org-element-property :contents-begin element) (org-element-property :contents-end element)) (setq desc (buffer-substring-no-properties (org-element-property :contents-begin element) (org-element-property :contents-end element))) (push desc obj) (push :desc obj)) (push obj links))))) links)))) #+END_SRC I would really appreciate any feedback.