From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id SOh9FZKcn19JHAAA0tVLHw (envelope-from ) for ; Mon, 02 Nov 2020 05:43:46 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id CBNgEZKcn1+3bAAAbx9fmQ (envelope-from ) for ; Mon, 02 Nov 2020 05:43:46 +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 77FA69401CD for ; Mon, 2 Nov 2020 05:43:45 +0000 (UTC) Received: from localhost ([::1]:59966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZSd6-0001IM-AV for larch@yhetil.org; Mon, 02 Nov 2020 00:43:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZSbP-0000mv-Uq for emacs-orgmode@gnu.org; Mon, 02 Nov 2020 00:42:00 -0500 Received: from pb-smtp20.pobox.com ([173.228.157.52]:56669) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZSbN-0000aX-9s for emacs-orgmode@gnu.org; Mon, 02 Nov 2020 00:41:59 -0500 Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 20A4AFAFA7; Mon, 2 Nov 2020 00:41:54 -0500 (EST) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:in-reply-to:references:date:message-id:mime-version :content-type; s=sasl; bh=lHUafDDuH/cwthBx6CV09Egw6V4=; b=rzKIB9 rjd4tWQP+SIq1IXc0TyzJQgLRkU72u6iHaRoTeoMVELNnbqz51xra4Rcv4mLA+il EO0L4gat+nWMypNY8/dZ0Xjz/K0r9RWrezuukcRVtoA+mM9Bhg+hY2Fklw3G8aQG 1Sui+AZDdS7cEh5Ef1BplcMkPmJfz6eLDB5sg= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 19A9BFAFA6; Mon, 2 Nov 2020 00:41:54 -0500 (EST) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:cc:subject:in-reply-to:references:date:message-id:mime-version:content-type; s=mesmtp; bh=oIjRZLEFK2L+ypkx/sPOJlJ8Mece+SOndQ7vw7sj2Bc=; b=xoQ8a0tuT+GGTj0KPMmH6m+HJYgzA2CYHGPaw5vIcXycKzQB/RqkBAHMR/IH1PR6c0dsJYHHFaMpp2vRX212VoExpXMbSFEbKZGoL8MqKss9llTJ5oNzMF4xFctU1qhjUUJygKS1NAL4PdddQ6QxljsAcua98XgtqciwHnA5NU8= Received: from localhost (unknown [45.33.91.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 852C9FAFA4; Mon, 2 Nov 2020 00:41:51 -0500 (EST) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: Jack Kamm Subject: Re: [PATCH] New "project" option for org-link-file-path-type In-Reply-To: <87v9etq2pg.fsf@gmail.com> References: <87v9etq2pg.fsf@gmail.com> Date: Mon, 02 Nov 2020 00:41:49 -0500 Message-ID: <874km89uxu.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 1B86E2B2-1CCE-11EB-B6EB-E43E2BB96649-24757444!pb-smtp20.pobox.com Received-SPF: pass client-ip=173.228.157.52; envelope-from=kyle@kyleam.com; helo=pb-smtp20.pobox.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 00:41:54 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, 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=pobox.com header.s=sasl header.b=rzKIB9 r; dkim=pass header.d=kyleam.com header.s=mesmtp header.b=xoQ8a0tu; dmarc=none; 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.21 X-TUID: LatiCVdnKHZM Jack Kamm writes: > 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. Thanks, that sounds useful. > 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. 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. > Subject: [PATCH] ol.el: New option "project" for org-link-file-path-type [...] > @@ -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. s/usue/use/ > + 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) The :package-version keyword should be added to signal the change in value. > (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)) Minor: the org-link-file-path-type check would be better positioned at the top, or at least before the project-current call, to avoid needlessly finding the project when the option is at its default value of adaptive. Also, I think it'd be good to let-bind the project-current result to avoid a repeated call. > + (if (string-prefix-p (expand-file-name (project-root > + (project-current))) > + (expand-file-name path)) It looks like project-root isn't available until 5044c19001 (project.el: A project has only one main root now, 2020-05-23), which isn't yet part of an Emacs release. Before that, it'd be (car (project-roots ...), I think. Do you think it's worth adding a compatibility kludge here? 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. > + (setq path (file-relative-name path)) > + (setq path (abbreviate-file-name (expand-file-name path))))) A cosmetic preference that you can take or leave: the condition can be moved inside the setq form: (setq path (if ...)) And another: let-binding (expand-file-name path) would avoid a repeating the expand-file-name in the abbreviate-file-name case.