From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id eOH8JgsRml9xcgAA0tVLHw (envelope-from ) for ; Thu, 29 Oct 2020 00:47:07 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id uqK6IgsRml+nOgAAB5/wlQ (envelope-from ) for ; Thu, 29 Oct 2020 00:47:07 +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 E28FA940215 for ; Thu, 29 Oct 2020 00:47:06 +0000 (UTC) Received: from localhost ([::1]:47146 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXw5p-0002p6-HD for larch@yhetil.org; Wed, 28 Oct 2020 20:47:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXw51-0002oy-Kj for emacs-orgmode@gnu.org; Wed, 28 Oct 2020 20:46:15 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]:38638) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kXw4t-00027J-TI for emacs-orgmode@gnu.org; Wed, 28 Oct 2020 20:46:15 -0400 Received: by mail-pf1-x42e.google.com with SMTP id 10so906182pfp.5 for ; Wed, 28 Oct 2020 17:46:07 -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=zwfxmijlVzH6xmH3ZKJwUmSSftycC6xho45MLHVDJes=; b=hEuwpibKlDJrY1qMtlXhovOazGHZ+Vovifhe/wercVvCNiAJU8tLcaQBpsI4UEn7D2 iTNLqpdoOROZ2MKI9EKxxVoLvUoMtecjjtuaoLUC4f2Orxq4b248RJVfBrP09L8x95sY AKx0+5ZBKWcebgdloAiXEdqQWfBeNexLF/hqunHei27Dq6V2Im9v2W8dW52DTwAgsbCh bCTu+Zxlv7Vgv42OlopXvNYQgROI1+YDtaOtDanPuBl6SRQjj6dtW243B/7a17PA9WTL 8r6JAoh+HWWbN2w1GSFyurLQGYFg4Q6aHRavJUrqjAVZWgiCFM39UODr/0Iy18uQ4LZf AvXA== 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=zwfxmijlVzH6xmH3ZKJwUmSSftycC6xho45MLHVDJes=; b=Bthl/puuaI/fZpwPZIYZuSdwXCzPddlFsYrM/fDujPfElAcbct+y361j00FOTWlhXh 3mHsatEsz5RrGH+AWWjN6PancW6JtvdmckrLdlH7+uTMfHY+Jr4/qYAoK3cX8138vD0W 6Bf6yaIaMIrzay4U4I00d727ketnWAb8zflSaiYWgmL73hEwAckXAQa/SAXG+fqi0eLt 4i+PpDiz6tEWUZ6zE4ZS8Gfvb5G3XsSqObg2v9lluv/i27vGZgIKwzuud8aVmpSg9De3 NLWxpU0fmYGoFonGDClisYOD4hZRnMlfhq3RNb6Zjn4kODgtWoMfzikRnmc4y9EyseC7 Sm2A== X-Gm-Message-State: AOAM533rb/1cpj3/wY3+OjI1gqtY1aCS2Xh93lkBAbASTsV74SSMKbxI GrYFybcZXfGq/5Drus5jCybrfJrCq+w= X-Google-Smtp-Source: ABdhPJxrBN4rMbPee0DxfO09dg574gC1t1V9iJnqhlvvgkGFs6eIx8DYLOkVJDnQd45wfEuI4A3bPg== X-Received: by 2002:a17:90a:db55:: with SMTP id u21mr1444282pjx.235.1603932365929; Wed, 28 Oct 2020 17:46:05 -0700 (PDT) Received: from localhost (199-83-220-90.PUBLIC.monkeybrains.net. [199.83.220.90]) by smtp.gmail.com with ESMTPSA id n6sm572335pjo.31.2020.10.28.17.46.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:46:04 -0700 (PDT) From: Jack Kamm To: emacs-orgmode@gnu.org Subject: [PATCH] New "project" option for org-link-file-path-type Date: Wed, 28 Oct 2020 17:46:03 -0700 Message-ID: <87v9etq2pg.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=jackkamm@gmail.com; helo=mail-pf1-x42e.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=hEuwpibK; 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-Spam-Score: -1.71 X-TUID: wXIkbKNgQ0Je --=-=-= Content-Type: text/plain The attached patch adds a "project" option for org-link-file-path-type. When this is set, links to files under the current project root will be relative, while links elsewhere are absolute. It relies on project.el, which appears to have been added in emacs 25. I used fboundp to check whether the functionality is available, and to silence compiler warnings. I'm not sure if this is the correct way to do it. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-ol.el-New-option-project-for-org-link-file-path-type.patch >From c5f9d4043a6cf6a325d122be24214356f36446f1 Mon Sep 17 00:00:00 2001 From: Jack Kamm Date: Wed, 28 Oct 2020 17:29:04 -0700 Subject: [PATCH] ol.el: New option "project" for org-link-file-path-type * lisp/ol.el (org-link-file-path-type): Add new option. (org-insert-link): Handle project option for org-link-file-path-type. --- etc/ORG-NEWS | 8 ++++++++ lisp/ol.el | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 7f935bf52..b9adc9089 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -88,6 +88,14 @@ package, to convert pandas Dataframes into orgmode tables: | 2 | 3 | 6 | #+end_src +*** New option to use relative paths for links in same project + +If =org-link-file-path-type= is =project=, inserted links under the +current project root will use relative paths. + +If not in a project, or if =project.el= is not available (as in older +versions of Emacs), links behave as default (=adaptive=). + * Version 9.4 ** Incompatible changes *** Possibly broken internal file links: please check and fix diff --git a/lisp/ol.el b/lisp/ol.el index 951bb74e7..9c48bd9b5 100644 --- a/lisp/ol.el +++ b/lisp/ol.el @@ -212,13 +212,17 @@ (defcustom org-link-file-path-type 'adaptive absolute Absolute path, if possible with ~ for home directory. noabbrev Absolute path, no abbreviation of home directory. adaptive Use relative path for files in the current directory and sub- - directories of it. For other files, use an absolute path." + directories of it. For other files, use an absolute path. +project Use relative path for files in the current project and sub- + directories of it. For other files, usue an absolute path. + If project.el is not available, behave as adaptive." :group 'org-link :type '(choice (const relative) (const absolute) (const noabbrev) - (const adaptive)) + (const adaptive) + (const project)) :safe #'symbolp) (defcustom org-link-abbrev-alist nil @@ -1876,6 +1880,15 @@ (defun org-insert-link (&optional complete-file link-location description) (setq path (expand-file-name path))) ((eq org-link-file-path-type 'relative) (setq path (file-relative-name path))) + ((and (fboundp 'project-current) + (fboundp 'project-root) + (project-current) + (eq org-link-file-path-type 'project)) + (if (string-prefix-p (expand-file-name (project-root + (project-current))) + (expand-file-name path)) + (setq path (file-relative-name path)) + (setq path (abbreviate-file-name (expand-file-name path))))) (t (save-match-data (if (string-match (concat "^" (regexp-quote -- 2.29.1 --=-=-=--