From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 8GcsDQ5x5mNrEQAAbAwnHQ (envelope-from ) for ; Fri, 10 Feb 2023 17:30:06 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 2DPiDA5x5mPYHAEAauVa8A (envelope-from ) for ; Fri, 10 Feb 2023 17:30:06 +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 CEBC22DE2E for ; Fri, 10 Feb 2023 17:30:05 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQWH6-0004Zu-IP; Fri, 10 Feb 2023 11:29:24 -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 ) id 1pQWH2-0004Zf-12 for emacs-orgmode@gnu.org; Fri, 10 Feb 2023 11:29:20 -0500 Received: from mail-am6eur05olkn2081.outbound.protection.outlook.com ([40.92.91.81] helo=EUR05-AM6-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 ) id 1pQWGz-0006dG-My for emacs-orgmode@gnu.org; Fri, 10 Feb 2023 11:29:19 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FsH4NbQ4kIwSjfnK5pKLyAnbvbRdoayQpGsJVPEi8OJzhNY1lD9FOr4d84WeAecvZbsFnAVmrp52BCZ5kkaUl5Dxs24GOaX/hnKWpyUIr5/yHq2wSX3OLKKLWkFcDxdEdJ3rtOZZ7UUBDw0rHhMIu3n9S844PTF3tGI2iUXoeZkYmy4nE8pddkZOLfeQ8mqCYvzF6Ymxyn3WL/YyeTEaqy4yADWKKTVx1W/ANTm2jmssZO9GJwM4A/DDvLAKF+Ws9C65xaWCI2eeWlMvpCVueSrpgwoyTGvOM52M3QAPI/3CU7pDh6+f6op/ooAr06toQt95+Dcu1npyf7lBxICgVA== 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=/uWG/tTIncQjD+DEbzn+oWekgLjx68U3iqqVm1apY0Q=; b=kNd5ozi14eifGfZ7EkGTZLpWEMM5bMnmZGaCw3+y5+1Xl/uhp5BqwqDbSSOQNPdM0H6YLgtHx/VBYIFJPZ2gHzEt57P6QmCMVz/FAgLfDtNIJC5ciXtSdGQPAWyOHbqvm24ooXpxOXvBce50tA5QKRPR2kvQTqZwwjtxkYwolqbjLFVVgXNNDZrv5b4DVFe8Ce1VcW/2FSBKpdRZdI7l1TS1WY1wEgwUWWEN5RBFVJZmD5pS/CPHnmpcLPpt6tL6WLwkyd2XYyN2FhUpkQy+f2qUZvsdjN2sYmBwoBeZYdQWV5JQCDQAdQ2LBfh/o58EG/+WEBqSnG8exjqH5G0ghA== 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=/uWG/tTIncQjD+DEbzn+oWekgLjx68U3iqqVm1apY0Q=; b=L1QDmSTrK4kmE2uS6jy4ZqoponvIVhPMBhK3nOnVh+CVu03iSkfdykI0yLodK+8+aqgTPtwLc3Ezc/d8hnPvno9UqwvnckuBiZDt7vEXV5T1pAsmmghHACBDiDlfr/XQ1+hWX3GDhcldKiAk11i9gkp9EvCn5pdO0wP7XOIIZVEimXgiwqzCR3gJonAQ3XkE25fAj7wP+8kD9DK7RdnLTd5v5yRhExZsqoV1sT4gLgPKgmOu/444REKJ0Uya6t0G9tVsoYZjjxH5cPi+J2omn0xsIuAiJa7ftjjh1uaWAc7UihUu5Jvhlp9auj2poJUk16xXZ0HFSq3LBh9VY4qmaQ== Received: from AM9PR09MB4977.eurprd09.prod.outlook.com (2603:10a6:20b:304::20) by AM7PR09MB3720.eurprd09.prod.outlook.com (2603:10a6:20b:10d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6086.20; Fri, 10 Feb 2023 16:29:14 +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 16:29:14 +0000 From: Arthur Miller To: Ruijie Yu Cc: emacs-orgmode@gnu.org Subject: Re: Problem with let/cl-letf binding stuff with org-capture In-Reply-To: (Ruijie Yu's message of "Fri, 10 Feb 2023 23:38:51 +0800") References: Date: Fri, 10 Feb 2023 17:29:12 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-TMN: [q9ZcjQvOnrTbd3v0X9fszgt2DIO7v2dc] X-ClientProxiedBy: FR0P281CA0127.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:97::8) To AM9PR09MB4977.eurprd09.prod.outlook.com (2603:10a6:20b:304::20) X-Microsoft-Original-Message-ID: <87ilg95vs7.fsf@live.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR09MB4977:EE_|AM7PR09MB3720:EE_ X-MS-Office365-Filtering-Correlation-Id: c321ec55-b4f7-483e-6f0b-08db0b83f281 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aTz/2bKergpGvk+oZUG1yCqqy/vYEGPoS+Wqzp/j0hqJOwfuYhuGLsb3E6GegQC+thr0RTYbjE5dz8MvCswVn5FENvaz1JtUARCx1XFHpw2JOdEAtuGhFTjdeIAO6MBG/5WUyd3RVBHecpae51THepkSiZsqNTuaA0dnCz8MrVGfvLEB8jIPk6qFLwZE/ZntPWr57kEzHsndzZ+BPRPWjkTmK0FjeZ219ee9/41PnHN6yKk1yIECDotV/MF1tnFgNkt93wSAWXEs/R7oNYxas93hPt5jV0QCWw4ddOciUFs5WTXPlJ+xUAfBvg+OBAhR5VzuQw5Myp1tM71BcAW1OL/eBOlwY0ZnmYOj7XLcleKN5PbN4xlD9VQWZ6oo6B9XrgTqaubHwJC4pfHE0lOGoy3uDTKZ0CPgJEijA6J5cPmK0HLdqr+j3+2+wTTmiJp+SsF3PGT4zmaZxW33ahXcgdEf4yuVHGDblnUMWL74NfN/MUq5oeMyoaqyZ4Hl+QuTJCfEtraPizTZx5wFcxnaDSCUABB97k6kxZjb3GH1HaKSem0HbOC4UaOYLDj9aIdSVTaUvxNLEQuZgdqRzLs59UK9+E9rOadZJE+o76HwHjQ2NU0bzBLDO4w44WHwXA+0/a+Nf4Rw4iaHP6X8xTQthB9yBvQAHkrbisQ6Q+B5LihRGtDA1dm+xc+sNlBSmviz X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?K0VuM2pjUFNmSUhRT3hYZ2NINUJMbTFzM3FEMDlFb0dzcGdpRU0vMUlvVlFo?= =?utf-8?B?QXo3N2ZyOHkyQzhlOHVyZUdoNUd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RmN3QVIyNTFkSVp3ckxkOUlBV2ZuTjdXRWd5di85VlVJWkdDUHkxdzQ3?= =?utf-8?B?Y3hXb2c2VDJmd054UDk4RmFmTWZ3SklDak9ELzJtVGVsUkp2M0pZU2JYZVRW?= =?utf-8?B?VS9TeCt1R0huQ3JWSXlrQTV6MklESW5YWUN5T05PbDNNYjZEYjAzNUhTZ01o?= =?utf-8?B?NnVGSW9YV2JVbFhUdGZjWVhKQnBONVB3aEFiK1ROSVFhakhONmtuZS85bStp?= =?utf-8?B?dlhMSHcwZWh2cExJQ0tBN0p1eVQ2a0NSb1p0S2tSNzR0Qjh3SXFmN1Zaczh3?= =?utf-8?B?bm4wKzhOMVp3eGxhTTNtQzUySnhhS1NlUlNvbWJOK0NKeVpKTEpPbnFxT1BD?= =?utf-8?B?SzllRE1RM1pVSWdwU2l3cVJ5UktIMm1HRG8xZlE3TzF0V0Z6b3RVWXg1Z3do?= =?utf-8?B?WGlXNStQSE9IZHg4V29mdzl5NmZQMitqU1Zuc3QzaE1rU0M2TnJMOGFRTTNE?= =?utf-8?B?ZzZIVGV4cjZvbWdRMlV3aDRvc2JMUWREWW9zNWhkRmlQb01jbHppSUtGRS9z?= =?utf-8?B?L2NjQVRjMHFNdDNvK29IKzNzeXpnZUNjQXY3ZHhUbzlGeFA3dlU3TE1rV3BO?= =?utf-8?B?RmFaT3dKOFQzYW15QkVJa05Lb2M5RXVidGdlM1NETlZCdllhY1Y0K2FJV3pi?= =?utf-8?B?cTkxYmtSNDlqTnpkaklNVGQ5RDk1Q0FIcXBuTDRpbzBjTnZYT2d3MkZoMGlz?= =?utf-8?B?UUNiNXl4OG9iOE9HenlpMUZ5Z0Y1NG5uOFY3dkpOaU5DVkFLM3FKa2FBPT0=?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-64da6.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: c321ec55-b4f7-483e-6f0b-08db0b83f281 X-MS-Exchange-CrossTenant-AuthSource: AM9PR09MB4977.eurprd09.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2023 16:29:14.7445 (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: AM7PR09MB3720 Received-SPF: pass client-ip=40.92.91.81; envelope-from=arthur.miller@live.com; helo=EUR05-AM6-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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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-Seal: i=2; s=key1; d=yhetil.org; t=1676046605; a=rsa-sha256; cv=pass; b=Xuv83+CBJDHzvGCIUqZB9/3k9gWDHgNvV9E1Igd3VD9j52vM2sBe6IQcSdei/ff1FLotQa QM9+XqA6QAYY+znMRbrMs8JpdsVvpWsAQdYws0XSL991m07YdbhcfcIqLjkjig2dnaV65M 68AyeBqiojYShZKMmycWtTeGFzqA2Epuhh4rIR3xuiHaUqFeW/rYsPgQWpTJ0Psres2bjT 74ebPk2vwsRhbfDemxkQ6Z7uw6zkEo36o8vSciJOzZ642hLxzEOWNrZGHnf25kZXnIgRPW njYztXT6BwzZOZLtblhEa5QhhJrgHnylNCYjuKpJOL7j+ssTtnUZ98x3lD5VKw== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=live.com header.s=selector1 header.b=L1QDmSTr; 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"; dmarc=pass (policy=none) header.from=live.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1676046605; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=/uWG/tTIncQjD+DEbzn+oWekgLjx68U3iqqVm1apY0Q=; b=Yz+5e7lhZ8riBjU5RFCawmekU4/GGp+0CCuRoK5KfRfSBs41r5qLqGgWngLDFeDtVdAdGH Vo4L9a0tol7Rmm31JVda7OsFddW4UsN7ZzU49pqD7RaE7xqNrfUjyujGLvHD20B90Y45XL gLD8dF0ewenQnTwEeowtJMNkU1XzU5AF886ggKyTGfZRhhlCnBTB8rD/xgjLrgZjET+3Vm cGQXC1J4R6g6MpOfe8N3+octjzD/JqqtUnd/zKpD8cEOJF2stbGqJyRm+53Hq7MKQG4uVl 5ibCQeqtx9En604POC5fMvnW6OJH5/UKFKKRbkuru6zvvi6ltMcloA3bnTeK1Q== X-Migadu-Scanner: scn0.migadu.com X-Spam-Score: -7.37 X-Migadu-Queue-Id: CEBC22DE2E X-Migadu-Spam-Score: -7.37 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=live.com header.s=selector1 header.b=L1QDmSTr; 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"; dmarc=pass (policy=none) header.from=live.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-TUID: aMzXpgn1Fp06 Ruijie Yu writes: > Hi Arthur, > > Please excuse my brevity and semi-random line of thought, as I=E2=80=99m = replying on mobile right now. See below.=20 > >> On Feb 10, 2023, at 23:11, Arthur Miller wrote: >>=20 >> =EF=BB=BF >> Based on a Reddit thread: >>=20 >> https://www.reddit.com/r/emacs/comments/10xhvd8/a_little_readstring_util= ity_using_an_org_mode/j7xziao/?context=3D3 >>=20 >> I did a small experiment to see if I can re-use org-capture, to just cap= ture a >> string from a buffer, without actually writing to any file. >>=20 >> My plan was to just let-bind org-capture-finalize with cl-letf: >>=20 >> #+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-buffe= r)) ;; C-c C-k >> (let ((org-capture-templates '(("s" "string" plain (function ignore))))= ) >> (org-capture nil "s")))) >> #+end_src > > Based on my somewhat-limited experience with CL (and elisp), I have never= seen > this particular type of letf structure. What I am used to seeing and wri= ting is > the following: It uses "place" or "field" to set the symbol binding, as in setf or incf. You can read more on SX: https://stackoverflow.com/questions/39550578/in-emacs-what-is-the-differenc= e-between-cl-flet-and-cl-letf > (cl-letf ((f (x) (1+ x)) > (1+ (f 2))) > ; =3D> 4 > > In particular, IIUC, I don=E2=80=99t think you would need symbol-function= here. Maybe > you can learn more from the docstring of cl-letf than me trying to drain = my > memory on this topic without reference. > > Also, in the code snippet you provided, what *should* org-capture-finaliz= e be? A function that can be called like this: > > (org-capture-finalize arg1 arg2) > > ? Or a variable containing a function (reference) that can be called like= this: > > (funcall org-capture-finalize arg1 arg2) > > ? In the former case you might be able to use cl-letf, and in the latter= case you should use let with a lambda value.=20 > >> 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 fr= om >> org-capture.el. >>=20 >> My second experiment was to abstract the finalize function into a funcal= lable >> fariable in org-capture.el (I have patched org-capture.el with this): >>=20 >> #+begin_src emacs-lisp >> (defvar org-capture-finalizer #'org-capture--default-finalize) >>=20 >> (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)) >>=20 >>=20 >> (defun org-capture--default-finalize (&optional stay-with-capture) >> "Default implementation for org-capture finalizer function." >>=20 >> ;; this is the original org-capture-finalize just renamed to "default-fi= nalize" >> ) >> #+end_src >>=20 >> So I could then have something like this (never mind C-c C-k function be= ing >> removed): >>=20 >> #+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 >>=20 >> 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 guess this answers part of my question in my previous paragraph. Is > org-capture-finalizer defined via defvar? If so, does it help if you put= an > empty defvar before the let binding? If not, maybe someone actually usin= g Emacs > right now can be of more help here. These were two different examples; one that let-binds the function 'org-caputre-finalize', via cl-letf and the latter one that was completely different in which I have defvared a symbol so I can let-bind it as a varia= ble. > If not, maybe someone actually usin= g Emacs > right now can be of more help here. Don't worry; thanks for the help anyway! /a