From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <emacs-orgmode-bounces+larch=yhetil.org@gnu.org>
Received: from mp10.migadu.com ([2001:41d0:2:bcc0::])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	by ms5.migadu.com with LMTPS
	id gKplAZ5e5mNbtwAAbAwnHQ
	(envelope-from <emacs-orgmode-bounces+larch=yhetil.org@gnu.org>)
	for <larch@yhetil.org>; Fri, 10 Feb 2023 16:11:26 +0100
Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	by mp10.migadu.com with LMTPS
	id wPNkAJ5e5mPmhQEAG6o9tA
	(envelope-from <emacs-orgmode-bounces+larch=yhetil.org@gnu.org>)
	for <larch@yhetil.org>; Fri, 10 Feb 2023 16:11:26 +0100
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 874D212FFC
	for <larch@yhetil.org>; Fri, 10 Feb 2023 16:11:25 +0100 (CET)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <emacs-orgmode-bounces@gnu.org>)
	id 1pQV34-00046W-1v; Fri, 10 Feb 2023 10:10:50 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <arthur.miller@live.com>)
 id 1pQV31-00046C-GX
 for emacs-orgmode@gnu.org; Fri, 10 Feb 2023 10:10:47 -0500
Received: from mail-am0eur02acsn20806.outbound.protection.outlook.com
 ([2a01:111:f400:fe13::806]
 helo=EUR02-AM0-obe.outbound.protection.outlook.com)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <arthur.miller@live.com>)
 id 1pQV2z-0000CU-82
 for emacs-orgmode@gnu.org; Fri, 10 Feb 2023 10:10:47 -0500
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=VE4zuEnACp6tYMFheP0MOcakAxkMBIRmdkgPHzp1RtJuaPZ1FIK7cDKEW5YVguB5F44ElRkPWboodzf55jHgTnckzwgrivLjtSUhZt4PI9LN9aeqQbgo04ye2Xzcc6NCmDWrgnEo9PjMPaPa4myCovr+7Ga2XTv5uEoODgpAXLwM9gsNTat/rCCHLkppn0Zb3nDQNnAbZnfpPyoA7qxbQotbdu5ZwaD4XZeyTBGjpOnKsM36icrm/iTXAuwbJnSd08x4Q9hyJcyG5zzqqFjK5HpGHUwFw2szOFWpjqB/gPPlncSUiEqSh85AFHTUGX5Y9TF678aiwNhtswiFYgKWCA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
 bh=knF442DspDgeRXrcdXZ3H2U0QlZFprugpxriwIjSoHo=;
 b=nhMVxSuEotayWSYkAzhiJ8q7OtNBpVRVLv8i8Sq6ZHTPGDmxXb5GJ0wbSJTOc7UC07TE3AKqDTmGy/6RqRTu0YCv/QgCiuhRKg4meSFkYrnBAHbyfj3f5GKw73z3VgaxLd+GG3k69+We6kgVaKVsNxeZGtJ3pjC++dUuwD6QQHLkiv2hrAQ9cNoRanClbA0PE4xzvljlorGsgvK52ozV92j0YpwPkAeq1QzZSS9jKgZrQeIT0PgWYQZcXO96K1h0eghoAK6aapp+YjUx3LyueAg+cWhtQ3ip3bT6CErYmovrOP4hj6AtYw/S+H1t5WRGUXTYgQuo1E8yG3/6SWWJzw==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none;
 dkim=none; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; 
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=knF442DspDgeRXrcdXZ3H2U0QlZFprugpxriwIjSoHo=;
 b=PX99wbd8QSoQokMOWrN9ZiyE/g0cad8Ra6WD77kSO1kfIjhdPrjM7Q+kQzvgeXuEhGPGi5LqI+5q3texJZIz4n6BHO/s3jnj5tSv+ZWUvHl4hGNk1W85+auOnlMdFXAz48SYH6BrXXOtVvRwsNxsqiy29klBuSDMcfMKYcceam+wo5v7FHRyeggtcD4Fn8ynv6AdlBGIyOGjl/xFUlo9bGXhUSNPpKFXrF45o50+TOEm4PFFJWTwBZfjTW7MSLsaqm3GFXUY9h5s7V8QJrrtRXcXa0rtPFVTckrq4WdVunlzPQ9S096vJIYgCAT0v5QTt1PhxA/8TdFt1DUnuRwO0g==
Received: from AM9PR09MB4977.eurprd09.prod.outlook.com (2603:10a6:20b:304::20)
 by PAWPR09MB6272.eurprd09.prod.outlook.com (2603:10a6:102:340::13)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6086.17; Fri, 10 Feb
 2023 15:05:39 +0000
Received: from AM9PR09MB4977.eurprd09.prod.outlook.com
 ([fe80::f2af:9752:58df:ad9]) by AM9PR09MB4977.eurprd09.prod.outlook.com
 ([fe80::f2af:9752:58df:ad9%7]) with mapi id 15.20.6086.021; Fri, 10 Feb 2023
 15:05:39 +0000
From: Arthur Miller <arthur.miller@live.com>
To: emacs-orgmode@gnu.org
Subject: Problem with let/cl-letf binding stuff with org-capture
Date: Fri, 10 Feb 2023 16:05:37 +0100
Message-ID: <AM9PR09MB4977E7E66F2E6BD0345DF46496DE9@AM9PR09MB4977.eurprd09.prod.outlook.com>
User-Agent: Gnus/5.13 (Gnus v5.13)
Content-Type: text/plain
X-TMN: [RtmF4ON2qudd3aV5LVrGfa+Sxfh8k0Uy]
X-ClientProxiedBy: MM0P280CA0117.SWEP280.PROD.OUTLOOK.COM
 (2603:10a6:190:9::32) To AM9PR09MB4977.eurprd09.prod.outlook.com
 (2603:10a6:20b:304::20)
X-Microsoft-Original-Message-ID: <878rh5mugu.fsf@live.com>
MIME-Version: 1.0
X-MS-Exchange-MessageSentRepresentingType: 1
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: AM9PR09MB4977:EE_|PAWPR09MB6272:EE_
X-MS-Office365-Filtering-Correlation-Id: c3a4a3a1-bbc0-4eb7-15d4-08db0b7844f9
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info: ZPSmVNu9+bmux8UKNjDa1wZtiHhNlNYpsnkKfc+cQ4NhNMCjDNr8QvYfv5DoQNwahOGDQS9xP8qHru2XnTrzW5qnIewJM5EiMiC8d7Ptffn13rZBgnd6YcZ04GervPG/8SfxtYNikVs8lk/7XiqAeA70InOO/Hv3iWZbZijU2hoMazpX6kcRenTu5cYIzxkkhmC/l6ZmsWH8Ctfqsk7bQMOxY+N9V4cHG5lHTcHN/4yOD4jLbklE5WCSYRM5SR+3RnqHyqZFitrtCWkTI+KfEThEAbBFIRITTUAdaWQmjeIg3HQn0I5d/SIIH8NR2dcqDPMFTJTtjvVET9LK3KvRYdFBHPqyMLX6au9U/63/yA8O2NnxcH2TvSohwBffBJmx6bb/RCuYfyr23zSy8vkppwiSF18CqlNOFVjwjBddDhGpNilgAapzC6p3kPpnCjgoSC1oF3Oc5aQNXQ6/Noc0lTvi1rGJdUsSMI02hNAeRA0PhNtegjsk9C5y3oA16Vn397+5cfb+J1AtH1m8R/Fnr4bBNlJTw0MpR7F7DRTVgNu6HNXmgpsuOJckdtYhRZELj6sPVMsrHUziP3TRbVEqnA==
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-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mvpXHzZK?=
 =?us-ascii?Q?pMjgk0z4uk+sMEuKGnCVj3GlouzM01A/e32UlZ1yFAnkJ0Z3KAz92aw8DDSO?=
 =?us-ascii?Q?E/N8DyBuncP1ij9C+vlZgmo6EMIYRwmReN2TJRXE+dnq7Nd3WPjlKNHRglJv?=
 =?us-ascii?Q?sIzRgK1zMAxPDAFg23ELmHF0Wtuju5tT973JAwdBl5oQFblZhqzN+8u2Shj1?=
 =?us-ascii?Q?aiTKZV1clhirKv2SCG4S053q7PXYt7LZ0WAEnbQRRdaiUgfNIHlFR5mVPXQV?=
 =?us-ascii?Q?PkwBh53wf7X0c8kqdzx4E88eE4UNBd2qH9UgstIU+kK6XqNBFsIlTwKQVbER?=
 =?us-ascii?Q?KNpBldO0nYNa1HGXcM0xibZPsG6J0ujKb7/1zEtGOarz8uQojjHGJUjHac0L?=
 =?us-ascii?Q?yl4VY/Dr02+s+ENb0wFrMzQrWN8QxFJf3sEdx+zZ/R8wwMcQxpv2TFbPNyK0?=
 =?us-ascii?Q?DD3Wtn8o863tjMKT27As/WJyNSTUQ+wJxt3FqqrTqA=3D=3D?=
X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-64da6.templateTenant
X-MS-Exchange-CrossTenant-Network-Message-Id: c3a4a3a1-bbc0-4eb7-15d4-08db0b7844f9
X-MS-Exchange-CrossTenant-AuthSource: AM9PR09MB4977.eurprd09.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2023 15:05:39.2974 (UTC)
X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted
X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa
X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000
X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR09MB6272
Received-SPF: pass client-ip=2a01:111:f400:fe13::806;
 envelope-from=arthur.miller@live.com;
 helo=EUR02-AM0-obe.outbound.protection.outlook.com
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,
 SPF_HELO_PASS=-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.29
Precedence: list
List-Id: "General discussions about Org-mode." <emacs-orgmode.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-orgmode>,
 <mailto:emacs-orgmode-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/emacs-orgmode>
List-Post: <mailto:emacs-orgmode@gnu.org>
List-Help: <mailto:emacs-orgmode-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-orgmode>,
 <mailto:emacs-orgmode-request@gnu.org?subject=subscribe>
Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org
Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org
X-Migadu-Country: US
X-Migadu-Flow: FLOW_IN
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org;
	s=key1; t=1676041885;
	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=knF442DspDgeRXrcdXZ3H2U0QlZFprugpxriwIjSoHo=;
	b=pqjjlkW2bts5AFNNllVZwW4kkTzTnocV0y+gxsjC37/vENPxDhyoUlex6okJgBIl8YvJ7y
	y+3ZclRAAjrPZ7+FfGkuLavViUHDWNwjjDw/HsYrVSIefEfLj1YVOAIJ5is6bAnXMGsPdX
	4LUJ/oDqb+WoyWF36hT8axBsbNFGcjuz8hAofSj4V5nCYqzcTqTi2tihhZPiDq41+VVaGb
	5wHXC9FqSXGuA1vF9LXmsDcZAp/83B4Fe50HCWmGD2gxB5gQ5xcfvjlh/7TNX9TWWXXw36
	ReYkXdubsl5cbKs62MYRmMw4bj0OVJVmkEt9JLI+Bf6oqWkZhJkRuHJQBLnm8g==
ARC-Authentication-Results: i=2;
	aspmx1.migadu.com;
	dkim=pass header.d=live.com header.s=selector1 header.b=PX99wbd8;
	dmarc=pass (policy=none) header.from=live.com;
	arc=pass ("microsoft.com:s=arcselector9901:i=1");
	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"
ARC-Seal: i=2; s=key1; d=yhetil.org; t=1676041885; a=rsa-sha256; cv=pass;
	b=WS26JQLUpruAb6lWV/KwPqyfiUDOFz6emomiG2ajJkmH/4hOsgSkKfMtSzN8rhHmYtp+pa
	hc28JsvXOwx9zlpbmnDvBlXY+MLsUwT6jzPtbpY0B569GTcFFrE5S6sMIIXwEpKFEo/sxF
	Vm20ZYcAzrpuPQRSK+yKKMm2Gy3YtHdyrqQ2cDom2Pdd7ZURw0b3ubO/ivKAunlFaqz0jv
	7158M6p1/WK/mE/QiBd+p/RPERA8ynQXFXKS5X/X7L83fHqVuh3SJs/JSL51OYrszZBckw
	KXVrsNs85a1x3deqURZSVNGgcZWNPnZxPnA7RsSphC3keqgIs/fKn0h8McNXhw==
Authentication-Results: aspmx1.migadu.com;
	dkim=pass header.d=live.com header.s=selector1 header.b=PX99wbd8;
	dmarc=pass (policy=none) header.from=live.com;
	arc=pass ("microsoft.com:s=arcselector9901:i=1");
	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: -7.37
X-Spam-Score: -7.37
X-Migadu-Queue-Id: 874D212FFC
X-Migadu-Scanner: scn1.migadu.com
X-TUID: r3MA0btWH35r


Based on a Reddit thread:

https://www.reddit.com/r/emacs/comments/10xhvd8/a_little_readstring_utility_using_an_org_mode/j7xziao/?context=3

I did a small experiment to see if I can re-use org-capture, to just capture a
string from a buffer, without actually writing to any file.

My plan was to just let-bind org-capture-finalize with cl-letf:

#+begin_src emacs-lisp
(defun my-read-string ()
  (cl-letf (((symbol-function 'org-capture-finalize) ;; C-c C-c
             (lambda (&optional _) (interactive "P") (buffer-string)))
            ((symbol-function 'org-kill-note-or-show-branches) #'kill-buffer)) ;; C-c C-k
    (let ((org-capture-templates '(("s" "string" plain (function ignore)))))
      (org-capture nil "s"))))
#+end_src

Unfortunately, that does not work. Regardless of binding, and if I used cl-letf
or cl-flet or cl-labels, or old let, or something brewed on the internet, the
binding org-capture see for org-capture-finalize, is the original one from
org-capture.el.

My second experiment was to abstract the finalize function into a funcallable
fariable in org-capture.el (I have patched org-capture.el with this):

#+begin_src emacs-lisp
(defvar org-capture-finalizer #'org-capture--default-finalize)

(defun org-capture-finalize (&optional stay-with-capture)
  "Finalize the capture process.
With prefix argument STAY-WITH-CAPTURE, jump to the location of the
captured item after finalizing."
  (interactive "P")
  (funcall org-capture-finalizer stay-with-capture))


(defun org-capture--default-finalize (&optional stay-with-capture)
  "Default implementation for org-capture finalizer function."

;; this is the original org-capture-finalize just renamed to "default-finalize"
)
#+end_src

So I could then have something like this (never mind C-c C-k function being
removed):

#+begin_src emacs-lisp
(defun my-read-string ()
  (let ((org-capture-templates '(("s" "string" plain (function ignore))))
        (org-capture-finalizer
         (lambda (&optional _) (interactive "P") (buffer-string))))
    (org-capture nil "s")))
#+end_src

However I see that the binding for the org-capture-finalizer, in capture buffer,
is still the default 'org-capture--default-finalize' and not my lambda.

I am really not an expert on emacs lisp; and I do understand that this is
somewhat "creative" use of org-capture (to put it nicely :-)), but I would like
to understand what is going on here.

I don't understand why let-binding here does not work? If I take (symbol-functon
'org-capture) I see it is a closure. I am not sure if it has something with the
problem to do? I have tested to disable lexical binding, re-eval things, but
the let-binding seems rock stable :). Nothing makes org-capture to reconsider
using my local let-binding.

I would really like to understand this, so please if someone can explain it, I
will appreciate to hear.

Thanks in advance
/arthur