From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id WFTzCi3vol8aAgAA0tVLHw (envelope-from ) for ; Wed, 04 Nov 2020 18:13:01 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id qDHeBi3vol8vUQAA1q6Kng (envelope-from ) for ; Wed, 04 Nov 2020 18:13:01 +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 925419402B0 for ; Wed, 4 Nov 2020 18:13:00 +0000 (UTC) Received: from localhost ([::1]:53034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kaNHG-0006gc-St for larch@yhetil.org; Wed, 04 Nov 2020 13:12:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45212) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kaNFv-0006g0-Ut for emacs-orgmode@gnu.org; Wed, 04 Nov 2020 13:11:35 -0500 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:33744) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kaNFu-0005ym-3Q for emacs-orgmode@gnu.org; Wed, 04 Nov 2020 13:11:35 -0500 Received: by mail-pg1-x541.google.com with SMTP id r186so17277146pgr.0 for ; Wed, 04 Nov 2020 10:11:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=9tKIP+nyRUAzxDJ04hutM8f+75xxkWkY/9RB8QcWDZ0=; b=Y6jIkc+LJkTf9QHo6Ifcnj2y8Mf702MVKzCPoitq/ohXQ52sRSyxxuv+hP0eDk4uAV B/2jSAldSRq/jiMtQcIHf8FoLAz8Kft5SdULBDypKrVxIYiecJ0mUb5M8ZygpJJO6KcS OepJHrtkhQ7R6nUwoYJghdcR7+McdiGTT7lKdkIb0E+BQyYHu+X/VLSm1uS8+XXk5cEO Jgo4PCPC7XsW3qkTIhD2BHAPkngAoI7ulSw/hTrr2Qat7RAMaaHiYrN4P4f7EPN3cI1s TxTq6QnjeLcc+R7ZyZsoBDYq6FGUBUH9iSXBXefPsHpb0aIJbmrgwKlb+NuvDoJXRdUW vRrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=9tKIP+nyRUAzxDJ04hutM8f+75xxkWkY/9RB8QcWDZ0=; b=k+kTJde0wkdsFz0W2anmysXcafm67+egGV8AK1XKzJ0a3uZrgt81Jeesp56UqhtKYg xQNuEI1U46uEGJ1/eZu4oyitoZX+gEQ+LgU2rBq4N7zenQcqQDk4XfXZycNWozglW3Nx wsbMOOH9zkluZolNXzv9sIITo4SkZlNrYj4D1yXGm7o9l0rjBpMTwJSrkMLHO2/5zDYS WpNXi2PgOyitT2BJGMcC32nvm3Hm4Q6upKyvOF2a2KqbpzHCUeUCQznlEwN+KFIPtvlk ILVq/CfKRx6kWaf9U00K+4GBnpLsA0MYpSaD4vFRBSkE6UKeMlIUBJKZVIamlHvPND9n Hq8w== X-Gm-Message-State: AOAM533biQXZAsh9pDiAjIbP5LUw3JwuzUl33ND6NVEyYZst6Toaj8bH JVKSExl2rOxntheaAZ65kOA= X-Google-Smtp-Source: ABdhPJxupXKYk5oP1BUFr0nFfoKd4P8bdBPbPHWESuKqR2m+RoFwWjVJyVVI+X1c0N8KIZFTf0uRXg== X-Received: by 2002:a65:4305:: with SMTP id j5mr22015667pgq.249.1604513489665; Wed, 04 Nov 2020 10:11:29 -0800 (PST) Received: from localhost (199-83-220-90.PUBLIC.monkeybrains.net. [199.83.220.90]) by smtp.gmail.com with ESMTPSA id w13sm3059717pfd.49.2020.11.04.10.11.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 10:11:28 -0800 (PST) From: Jack Kamm To: Kyle Meyer Subject: Re: [PATCH] New "project" option for org-link-file-path-type In-Reply-To: <874km89uxu.fsf@kyleam.com> References: <87v9etq2pg.fsf@gmail.com> <874km89uxu.fsf@kyleam.com> Date: Wed, 04 Nov 2020 10:11:27 -0800 Message-ID: <87blgd6lgw.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::541; envelope-from=jackkamm@gmail.com; helo=mail-pg1-x541.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: , Cc: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: ns3122888.ip-94-23-21.eu Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=Y6jIkc+L; 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: -0.21 X-TUID: sL0x4HmRAp9f --=-=-= Content-Type: text/plain Hi Kyle, > As a projectile user, I'm tempted to suggest that, instead of the adding > the `project' value, org-insert-link could learn to call > org-link-file-path-type if it is a function and, if that returns > non-nil, do the prefix check. Then projectile users could set it to > projectile-project-root. It seems project.el doesn't have a similar > function that could be called without any arguments, but I guess we > could add a simple ol- wrapper. I'm not sure that's a good idea, > though. I like the idea of letting org-link-file-path-type be a function. However, it struck me that it might be too limiting to just have the function return the project root. There's a lot more potential for customization here -- for example, a user might want to combine the noabbrev option with the adaptive option. If we could instead pass a function that takes the filename as an argument and returns the path to insert, that would allow for greater flexibility. Other benefits are that the implementation is much simpler, and subjectively I think it's more intuitive to explain the meaning of this option (as opposed to an option where the user passes a function that returns the project root). The downside of this is that the user has to do a bit more work and write some elisp to take advantage of the option. I've attached an updated patch in this direction. What do you think? I think the simplicity and flexibility outweighs the downside, but I'm not sure. > The :package-version keyword should be added to signal the change in > value. Thanks for the tip, I've added this. > Functionally I think your current patch would only support Emacs's > unreleased master, unless the user installed a new project.el via ELPA. > More on that below. Good catch. I didn't realize I was using project.el from ELPA but it turns out I was. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-ol.el-New-option-to-set-org-link-file-path-type-to-a.patch >From d156a9cfcdbfb9be72df39761111e2355f48cf10 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 to set org-link-file-path-type to a function * lisp/ol.el (org-link-file-path-type): Add new option. (org-insert-link): Handle function option for org-link-file-path-type. --- etc/ORG-NEWS | 19 +++++++++++++++++++ lisp/ol.el | 12 ++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 7f935bf52..891a680ae 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -35,6 +35,25 @@ omit a file description was to omit the header argument entirely, which made it difficult/impossible to provide a default value for =file-desc=. +*** New option to set ~org-link-file-path-type~ to a function + +If ~org-link-file-path-type~ can now be set to a function that takes +the full filename as an argument and returns the path to link to. + +For example, if you use ~project.el~, you can set this function to use +relative links within a project as follows: + +#+begin_src emacs-lisp +(setq (org-link-file-path-type + (lambda (path) + (let* ((proj (project-current)) + (root (if proj (project-root proj) default-directory))) + (if (string-prefix-p (expand-file-name root) path) + (progn + (file-relative-name path)) + (abbreviate-file-name path)))))) +#+end_src + ** New features *** =ob-python= improvements to =:return= header argument diff --git a/lisp/ol.el b/lisp/ol.el index 951bb74e7..262a6c5ae 100644 --- a/lisp/ol.el +++ b/lisp/ol.el @@ -212,13 +212,18 @@ (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. + +Alternatively, users may supply a custom function that takes the +full filename as an argument and returns the path." :group 'org-link :type '(choice (const relative) (const absolute) (const noabbrev) - (const adaptive)) + (const adaptive) + (function)) + :package-version '(Org . "9.5") :safe #'symbolp) (defcustom org-link-abbrev-alist nil @@ -1876,6 +1881,9 @@ (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))) + ((functionp org-link-file-path-type) + (setq path (funcall org-link-file-path-type + (expand-file-name path)))) (t (save-match-data (if (string-match (concat "^" (regexp-quote -- 2.29.2 --=-=-=--