From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.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 OAYoF0br52MaPQAAbAwnHQ (envelope-from ) for ; Sat, 11 Feb 2023 20:23:50 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id cI/fFkbr52Po4wAAauVa8A (envelope-from ) for ; Sat, 11 Feb 2023 20:23:50 +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 03AB716EC8 for ; Sat, 11 Feb 2023 20:23:49 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQvSp-00065V-E4; Sat, 11 Feb 2023 14:23:11 -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 1pQvSn-000650-Qp for emacs-orgmode@gnu.org; Sat, 11 Feb 2023 14:23:09 -0500 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pQvSl-0003VV-VS for emacs-orgmode@gnu.org; Sat, 11 Feb 2023 14:23:09 -0500 Received: by mail-wm1-x32c.google.com with SMTP id bg5-20020a05600c3c8500b003e00c739ce4so6259031wmb.5 for ; Sat, 11 Feb 2023 11:23:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:date:references:in-reply-to:subject:cc:to:from :message-id:from:to:cc:subject:date:message-id:reply-to; bh=7g1S+K9UDAOdTU1a/KE+feGu1ioQdT8RTdgWkq4IK7M=; b=Y7Sy20Dwk4EvY9FNLOrvzBBCiMn96OZcJV7m1amPpY4k0VF82HEvPbVnihFI292AKc QW1La7inzE/hRg6uN27caW/pzzaY/+NpZYuZWRx5x+U6Hjw3vN9YiVw8N2uP+pqH41wQ OfazGwQ9hPfDZcQa0WsrrBmB95gc2RgIA7BnQhidAjFvi7Z57c454gBxNc/OBdIlQ9HD A0eFnLzTuo+2FIwbseu6QswY4+TUyaTqeeJwjezTHYKodGYtSaj/ImJ22Qae2xQPCQpr wryQeT+Ry/drRb9Yq88oGM+RymzNklUnLnOSTDEeoLyU9mqzVnuEUk0pDrTBVe9xss+l HlvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:date:references:in-reply-to:subject:cc:to:from :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7g1S+K9UDAOdTU1a/KE+feGu1ioQdT8RTdgWkq4IK7M=; b=kIiOzcxZ/dyjOwvTfA/hNqVubscBwOcGRlgqZSA6t7VZxwHlm7ZKbzaFRQqy49Ktvw 86/GyfVF+wnRvv1iP7QlcTijS/FA9xZhQKm6Eom1dt4brKSW4gpc2Bj/edIOV15LTZvj DnQKgL4/7NHqLffRicXjKHyPE50PHSaXu0wEsWXqBqlFPQuQE388GhxYwW+zpgIYvoOl Koq4tyWlsXSmr8LN2BtpMaAt5/Gz0ZH83FI6vJeuZJ3Cmku+ljQdtSduJZ/v1vHaLnl2 PfsOhjmHZvbLJbliWfhYBIOxKUK8GN7jnt5bNBWK3ydmMroIDjdpFrO3EPYmBU0m7lsn Oknw== X-Gm-Message-State: AO0yUKVaZdqwK7AJawgdWw7/MqMRGzVV1nEmdYMge6e+K+PD+9mvOFrs kKi1rLVaWsLg/o5P16mTXt8= X-Google-Smtp-Source: AK7set90RhiM2S0UZbeElZ10hkVSwsDdvb8X0Pb1I0RUkVuAznqjqv4/fv8uwgLfUOKxrNc7Ckn+oA== X-Received: by 2002:a05:600c:4e90:b0:3e1:df8d:e022 with SMTP id f16-20020a05600c4e9000b003e1df8de022mr1970280wmq.9.1676143386106; Sat, 11 Feb 2023 11:23:06 -0800 (PST) Received: from keynux ([2a01:e0a:505:3460:169:7511:f49a:58eb]) by smtp.gmail.com with ESMTPSA id j40-20020a05600c1c2800b003dc4480df80sm13676062wms.34.2023.02.11.11.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Feb 2023 11:23:05 -0800 (PST) Message-ID: <63e7eb19.050a0220.56539.6aa7@mx.google.com> Received: by keynux (sSMTP sendmail emulation); Sat, 11 Feb 2023 20:23:03 +0100 From: Bruno Barbier To: Arthur Miller Cc: emacs-orgmode@gnu.org Subject: Re: Problem with let/cl-letf binding stuff with org-capture In-Reply-To: References: <63e69450.050a0220.9052f.652e@mx.google.com> <63e74a8b.df0a0220.7f45d.5b05@mx.google.com> Date: Sat, 11 Feb 2023 20:23:03 +0100 MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=brubar.cs@gmail.com; helo=mail-wm1-x32c.google.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, MSGID_FROM_MTA_HEADER=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.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-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1676143430; 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=7g1S+K9UDAOdTU1a/KE+feGu1ioQdT8RTdgWkq4IK7M=; b=KWP9it/K8Y34w1/UqJ07JhUxxpjtnyfZ9DaTqCfgi+gJXmleyZw5EjShKvKqTEuqJsn7XR 7Dp0AmCxJcnO+vkQlWQ5VwXEFY/7mP4TJeccb9UkeB3IMgRgT4kqyX8+XF+OAmWJNkI6hA F33viLom+DVC/YeG1HPKNJVohNaa3sDrY7SheliBhiRxlk3KFYfmcndwUE6WkqhW+o0RkF QBkViTlXOBFQH/rBL2wwMfbF5+SH7eccRMcI/AP1nnuRURUf2fMwCZsZeyRM4ehAD0jlI5 BX4hfCl/V2C+Qz915wzYwxjtpXNxlAybr9DvnnLUW9JOEUihwz4o1LqBwSna5w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Y7Sy20Dw; 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=gmail.com ARC-Seal: i=1; s=key1; d=yhetil.org; t=1676143430; a=rsa-sha256; cv=none; b=Xe3KltvrHnVF74UADtDoZFNsK/Dl4FbvcVxPz3OIhNTVdBFCHSQttdJgVrFiwygcx7CWzP Kpv0qzisW59mvqwn8J7zMee2Iy7Z3Xs8yelQieZmYeou/moLmk31pi/O2XJV83gpp5FXuD OaufUtWMqXZu5atHBfAAwMDtH+giPPCD1lje9m3YOtUypPhYmuDGYGWR8FM/QY4SNUsPl7 1pxQMuprNcw1AiHpL2EaMIoDSdtUvQ5rV3QrKdVe5megQ4XaXL0asj3Dn2gg35IRD4IMlw dA259VZvAzeZlu43tBa1vz1V57N5NCUUdVeiAKK6sNBCNB4bkHxK8Pp3pdcFtg== X-Migadu-Queue-Id: 03AB716EC8 X-Migadu-Scanner: scn1.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Y7Sy20Dw; 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=gmail.com X-Migadu-Spam-Score: -6.31 X-Spam-Score: -6.31 X-TUID: IOZ4ohfewryR Arthur Miller writes: > Bruno Barbier writes: > >> Arthur Miller writes: >> >> The hook `org-capture-mode-hook' will be run in your special >> capture buffer. You can override the "C-c C-c" binding only there. > > Yes and in every other capture buffer No. If you modify the hook only during your call to 'org-capture', it will be called only once in your buffer. >> Even if I could let bind the function at the right time, I would avoid >> that solution, as I can't garantuee that this global hack will not break >> other parts of Emacs (other captures, output filters, threads, timers, >> etc.). > > Why do you think it will break other parts? This is not a global hack, on contrary it > exactly tries to prevent to be "global" in entire Emacs, by let-binding a name > to a local lambda, which becomes "global" only in that buffer. If that > explains. You are assigning a local value to the global binding. Everything in Emacs will use your functions until you exit the cl-letf. It's like if you were using 'fset'. Here is an example that uses cl-letf. Note that the call to async-shell-command is outside the "local" binding, yet, the cl-letf breaks it. You should try this in an other Emacs, just in case. (defun oops () (let ((v (async-shell-command "date" "!sh async"))) (cl-letf (((symbol-function 'comint-output-filter) (lambda (proc string) (message "async-shell-command is using my binding: %s" string) (read-string "What's the password?")))) (read-string "what: ") ))) (oops) > > Here is another version on the same theme, where I don't think you could modify the local > environment without let-binding at all: > > #+begin_src emacs-lisp > (defun my-read-string (prompt) > (let ((delta 20 ) > (minibuffer-mode-map org-mode-map)) > (window-resize (minibuffer-window) delta) > (cl-letf (((symbol-function 'org-ctrl-c-ctrl-c) > (lambda () > (interactive) > (let ((s (buffer-string))) > (exit-minibuffer) s))) > ((symbol-function 'minibuffer-mode) #'org-mode) > ((symbol-function 'minibuffer-complete-and-exit) #'org-return) > ((symbol-function 'org-kill-note-or-show-branches) #'keyboard-escape-quit)) > (read-string (concat "# Press C-c C-c to continue, C-c C-k to cancel\n# " prompt "\n\n"))))) > #+end_src I hope I've convinced you to not do that. I definitely will not try it, as Emacs needs a working minibuffer for plenty of things: debugging, saving, quitting, etc. > read-string is written in C and creates its own minibuffer, which is deleted by > the time read-string exits. I don't know of any other way to cutomize exactly > *that* minibuffer, without installing a hook or advising some functions, which I > think is way less clean and much more "global" than just running the function in > a local environment. As I understand, let binding for this purpose is a normal > technique in lisps, but I am not an expert as said; I am actually experimenting > with this for the purpose of learning and seeing what is possible. Yes, let binding is fundamental. But I think it's the first time I see 'cl-letf' with the 'symbol-function' place. > ... > but I am not sure if I can do anything here without introducing at-least an > extra keymap, to not install into the org-capture-mode-map, so I can as well > create a minor mode, but at this point it is not much different than > re-invinting the read-string, so I'll terminate my experiment here :). You can replace the buffer keymap with a keymap that only contain your custom keys, and inherits everything else from org-capture-mode-map. > > But I wouldn't speak in some generic terms like "use hooks" or "advise" instead > of let-binding. I didn't mean to say to not use let bindings. I'm trying to say that using 'fset' (i.e. cl-letf + the symbol-function place) looks like a really bad idea to me. And, in this case, hooks and adivces are what is usually used. > (defun org-project-new-project () > (interactive) > (let ((org-capture-templates org-project-templates)) > (org-capture))) > > ... > I don't know what would be the alternative, but let-binding on > org-capture-templates, let me clearly re-use the functionality without polluting > the global org-capture-templates variable and without re-implementing pretty > much anything. That looks to me like a perfect use of a let binding. You bind a dynamic *variable* using *let*, and, that variable is rebound, and used, during, and only during 'org-capture'. > I am very interested to hear more on the topic, since I would definitely like to > learn more about different techniques. Variables are designed to be overriden (let bounds). Functions are not (as there is only one binding at any given time). > Hope that explains a bit more on the background of the experiment :). I'm still confused about the idea of making 'read-string' behave like 'org-capture', but, we use Emacs because we can experiment! No need for justification ;-) And, experimenting with the minibuffer, which is one of the fundamental component to control Emacs, that's definitely courageous :-) best, Bruno