From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id OImYGb72yGLjBAAAbAwnHQ (envelope-from ) for ; Sat, 09 Jul 2022 05:32:14 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id kJiaGb72yGIimgAA9RJhRA (envelope-from ) for ; Sat, 09 Jul 2022 05:32:14 +0200 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 E8A20A9C7 for ; Sat, 9 Jul 2022 05:32:13 +0200 (CEST) Received: from localhost ([::1]:52406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oA1CX-0003dg-2X for larch@yhetil.org; Fri, 08 Jul 2022 23:32:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52540) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oA1AN-0003ao-Sg for emacs-orgmode@gnu.org; Fri, 08 Jul 2022 23:30:01 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]:42604) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oA1AM-0002hi-6B for emacs-orgmode@gnu.org; Fri, 08 Jul 2022 23:29:59 -0400 Received: by mail-pl1-x636.google.com with SMTP id 5so310028plk.9 for ; Fri, 08 Jul 2022 20:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=Meefkh6o0Tu3QfLKSBKgD3zpg4w/AHaanYMzJYZxFZY=; b=SVjH4NMmC+2KIEE0NRJEbjomSN5AGwZiaWtuMYUAqoEuFO+Gh4+Zz/4NlsBpalBCfB wEUUYiIPkzqqnleTSrOkqxk4DMLa3nNMxs7l9WjwBtyQKUHAWePrkymDn9gHOdIqyUE9 EDDc0o0M3X3i0d4y24dgTz36MDS61B5ewtBnGz+nMaptT1yEPq0vun+Ja7nGcBqontBp 01nxTGpL/aGMLcBw1ROogqTwmhv3EvfcaABOlqc95539SL1LpgRrL4t4Kvcovc8SDm3b nvKck0GSkLOGYruHLNaVIPqOUW5CGHTpGBPDgMWhFdZrvX7QVPw8VMHjVbJ7Bq7610vo jNWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=Meefkh6o0Tu3QfLKSBKgD3zpg4w/AHaanYMzJYZxFZY=; b=oIIhqiOEyqZwaPsX7TFhzeaF2T+W8RN31dHWy/qp9InbJV5sBowzKGTyfJacV4ubTJ JLrivhoCLe3yU1SOtZbVeBua4hpKFt/v+XBTcE5CJgTML22aTfcPDwfsTHIdtYRYBe7h CjsuOs3KJBjMH91O7QywZlbs6OvHq/4KvytBnEBRdcYf4XvzL51EjqlQvCa8WPmZNcDX 5Z8DuzROqW+pGm3kx8Vnk/wiosNyKTiovvxDCthj1RjTYZ6QWu81bYilYgtmxOMXMeAv QPDVD07FF2zPzPIS/ri94HKYcRZ074D27TdkWYw59B4hcbY7yjJKSvJYjCyb/mlpRUzi EDRw== X-Gm-Message-State: AJIora9cjfL6KV+rfP/V0zE2QqkroZHzLuz/8AuplZIPyI2B/HG/RiLu 6ZxPYghKSnsUwrLu2+BMWG2SYpjUdPWcQMCC X-Google-Smtp-Source: AGRyM1v4VlEbxTXBbqDyPm6zFlumLG4tIOsjdOFSS+LIR48161/2DDqBJ+0eMpSrc7cExiizuiP+Zw== X-Received: by 2002:a17:90b:682:b0:1e3:142:a562 with SMTP id m2-20020a17090b068200b001e30142a562mr3622886pjz.91.1657337396758; Fri, 08 Jul 2022 20:29:56 -0700 (PDT) Received: from localhost ([23.228.121.194]) by smtp.gmail.com with ESMTPSA id 67-20020a621446000000b0052a53f8ece3sm347516pfu.42.2022.07.08.20.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jul 2022 20:29:56 -0700 (PDT) From: Ihor Radchenko To: Hugo Heagren Cc: emacs-orgmode@gnu.org Subject: Re: [PATCH v4] ol.el: add description format parameter to org-link-parameters In-Reply-To: <87v8s8n1bm.fsf@heagren.com> References: <87zgl1npow.fsf@localhost> <20220405192931.6747-1-hugo@heagren.com> <87a6cx79xn.fsf@localhost> <87zgi6fckr.fsf@heagren.com> <871qvixhfw.fsf@gmail.com> <87v8s8n1bm.fsf@heagren.com> Date: Sat, 09 Jul 2022 11:31:03 +0800 Message-ID: <87let39d3c.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=yantar92@gmail.com; helo=mail-pl1-x636.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 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 X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1657337534; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=Meefkh6o0Tu3QfLKSBKgD3zpg4w/AHaanYMzJYZxFZY=; b=IQx4cXAnv6v9+rB/W+Gr2TjpezU/esfmWdtmr3vpIhv7dvlGYM09Irm7uh69hjz46yfuGo wARSKf8nRMig20OzC+cfQaGelSxxK7/IK4771QhEhQOLQbpntbx+603r6RsiGycVxSB4Ms phovUG+sPOOMjvlA8lpEDPS0exWttRqhIDqTgB7RCm+QndkPlMO84ld+MD78dzeDSS0kRu g7ugntZiboSKMvP2QOetKqktQvBLL1+ZAiSiZi5ltPLjEhxJoDcjNBb+UaEz+W6AKwdTZK okKJeU13q1Td6xFub7mMX3mrKEX5w7Ao6TS2kPZWSnXfVGaL//S5I+1XqxTr8A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1657337534; a=rsa-sha256; cv=none; b=X6hnEVRlj6ut8nPX4dI3Yuru+WWkONCzGuq5hSc0y6GGUfTKBfR2axcC1XWhl1DIdkCfqk EUwoZpMzhar5wR7rbh/xFk8Z0dL8CayEtcQy0brpr0STMPnkJ0qVReECSuBwhZBR4Gqu/V 26u4XttIbc2HE8zh9ZRWFGQTK7vxXKZebC6l6j3/+gv9YKzZTnBGnSyh9QoQyRfhk8sVgY kjjj4XhRgphYParzuz7ZROT6Z0Cw3yxcuMBWzlrEno6WIc8nUOxBBJFRobQYzfZMlFk7Os LlWUM7r+jBVQwOag5LE027HoNhSlHNZe+qq+TlAdqezlTLri6838YZ8/sIlnXA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=SVjH4NMm; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -5.25 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=SVjH4NMm; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: E8A20A9C7 X-Spam-Score: -5.25 X-Migadu-Scanner: scn0.migadu.com X-TUID: OJ+ztL9m5MBw Hugo Heagren writes: > Since the last version of this patch, I have: > - moved the code which sets `type' in `org-insert-link' to a position > where it covers more cases > - rewritten the macros used in the tests, so that always (and > correctly) restore the original state after running, even after > errors. Thanks to Max Nikulin for suggesting using `condition-case' Thanks! > tl;dr The question is: what is the Good Behaviour when > :default-description is set to something, which is meant to return a > string and returns 'nil instead? Should it be treated like an empty > string, or as an error? Currently, the internal implementation will treat nil return value as if there was no :default-description and org-link-make-description-function were set to nil. We may probably document this. It sounds like a useful behavior. If the :default-description function returns non-string and not nil, the behavior is simply undefined. It was also the case for org-link-make-description-function. Though we might add a cl-assert somewhere near the end of org-insert-link to deliberately throw an error. > Subject: [PATCH 2/2] test-ol: tests for default-description param when > inserting links > Add tests for various values of `:default-description' in > `org-link-parameters'. Could you also add the proper changelog entry for the test-ol.el file? > +;;; Insert Links > + > +(defmacro test-ol-with-link-parameters-as (type parameters &rest body) > + "Pass TYPE/PARAMETERS to `org-link-parameters' and execute BODY. > + > +Save the original value of `org-link-parameters', execute > +`org-link-set-parameters' with the relevant args, execute BODY > +and restore `org-link-parameters'. > + > +TYPE is as in `org-link-set-parameters'. PARAMETERS is a plist to > +be passed to `org-link-set-parameters'." > + ;; Copy all keys in `parameters' and their original values to > + ;; `orig-parameters'. For `parity': nil = odd, non-nill = even *non-nil Also, please end each sentence in the comment with ".". > + `(let (parity orig-parameters) > + (dolist (p ',parameters) > + (unless parity > + (setq orig-parameters > + (plist-put orig-parameters p (org-link-get-parameter ,type p)))) > + (setq parity (not parity))) This is a bit awkward code. You can instead use cl-loop by 'cddr or a simple while loop with two (pop parameters) statements inside. Also, ',parameters will fail if PARAMETERS argument is a variable name. > + ;; Set `parameters' values > + (condition-case err > + (let ((_ (org-link-set-parameters ,type ,@parameters)) > + ;; Do body > + (rtn (progn ,@body))) > + ;; Restore original values > + (apply 'org-link-set-parameters ,type orig-parameters) > + ;; Return whatever the body returned > + rtn) > + ;; In case of error, restore state anyway AND really error > + (error > + (apply 'org-link-set-parameters ,type orig-parameters) > + (signal (car err) (cdr err)))))) unwind-protect is more suitable here and will lead to more concise code. > Subject: [PATCH 1/2] ol.el: add description format parameter to > org-link-parameters > > * ol.el (org-link-parameters): add parameter `:default-description', a > string or a function. > * (org-insert-link): if no description is provided (pre-existing or as > an argument), next option is to use the `:default-description' (if > non-nil) parameter to generate one. > > Default descriptions are predictable within a link type, but because > link types are quite diverse, are NOT predictable across many types. A > type-parameter is thus a good place to store information on the > default description. Please start sentences after ":" with capital letter. Also, you missed double space between sentences. > +`:default-description' > + > + String or function used as a default when prompting users for a > + link's description. A string is used as-is, a function is > + called with two arguments: the full link text, and the > + description generated by `org-insert-link'. It should return > + the description to use (this reflects the behaviour of > + `org-link-make-description-function'). > + > `:display' I think that we should also document the new parameter in ORG-NEWS. Best, Ihor