From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 2HyQKfSv6GNUSwEAbAwnHQ (envelope-from ) for ; Sun, 12 Feb 2023 10:23:00 +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 gDCzKPSv6GPIWQAAG6o9tA (envelope-from ) for ; Sun, 12 Feb 2023 10:23:00 +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 BD1DE40696 for ; Sun, 12 Feb 2023 10:22:59 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pR8Ys-0005Hb-DF; Sun, 12 Feb 2023 04:22:18 -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 1pR8Yq-0005HS-T4 for emacs-orgmode@gnu.org; Sun, 12 Feb 2023 04:22:16 -0500 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pR8Yo-0003dM-S8 for emacs-orgmode@gnu.org; Sun, 12 Feb 2023 04:22:16 -0500 Received: by mail-wr1-x430.google.com with SMTP id by3so8107790wrb.10 for ; Sun, 12 Feb 2023 01:22:14 -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=sWpPHe/XcUVxg/yVOR7LbWvLreBZfL+az5ItX8/fiy8=; b=p0vtHdtsr0/D19PdC52YfS/aZ6cqsy/5fwBjPRp8Cq1Xa7fJyga4h5LfPBwansKgb/ tPCCu00YF1Rrg0eocrFD1dpbTBmrKF2H62u64gSH303umEralFgmNZPyz8X0t9tA+huj VCJm/vdr7Jlm6M0VXiURcqIqbOrApjf8rdiHcKUF9EksKWxA55wH8zqERIW+z3sBUWls PSrUST3MGJM0yUSgqoajBMWO/VWailzaLa2zDQdfyhEcAl62mCgDp/wBgFktDXEH8YZn TRKY1KM0XHAq/nRSFY2R/IJaj2fOJXGDCUur0oT3tCXTEJsE2nKENxMM1eZIIVIVEc21 +rbg== 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=sWpPHe/XcUVxg/yVOR7LbWvLreBZfL+az5ItX8/fiy8=; b=GgHiMzafbuseWFxYs+bm3HCHi9JY1Eq9mzZR3XQZfrO/c0a1XHEnbDPqUtEYWQJTxT HaDkQDMJggTfedxanSIvaoEqhKOKVcj3y8dJEZqIcHDfhpI0pLJ+ASWsh5PkDGieuyBJ hgoyrnaP8nn1j/EON2HGlMUAdD/4jku7PZEmzb6RvD1TvVCOGAQ7Ky53YL2eAdH4mMFA e9eFYwvMfcJYdWluA5794AT9Nn8WKb9bXF9lsiY/OGxCXpzM7TqBXSRvJYV9WOE55Xst 7XBHGoeQnn/3ih4FWlyURWVCeOKwwpKrCMmU4r1wyixrbl5JlU5IjtdzTOfk69/7bIZn FP6Q== X-Gm-Message-State: AO0yUKWjp8K/4teP/OtdEzxyzYyt7GVSwxrKTBdBosJJEe5tdsbyevpx 8WayXdjRgWKya+MSGxUAOBaRHrF7tvk= X-Google-Smtp-Source: AK7set+MZMTsaaV0kNHuIYoHbE0AhTRmTO6NSzHMv4vumhakjIPTy+O4m2NNPbY8aqfLNyzU3w70sQ== X-Received: by 2002:adf:fad1:0:b0:2c5:518a:f6e0 with SMTP id a17-20020adffad1000000b002c5518af6e0mr2323933wrs.6.1676193733277; Sun, 12 Feb 2023 01:22:13 -0800 (PST) Received: from keynux ([2a01:e0a:505:3460:169:7511:f49a:58eb]) by smtp.gmail.com with ESMTPSA id v2-20020a5d6102000000b002be5bdbe40csm7826693wrt.27.2023.02.12.01.22.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Feb 2023 01:22:12 -0800 (PST) Message-ID: <63e8afc4.5d0a0220.969b4.d166@mx.google.com> Received: by keynux (sSMTP sendmail emulation); Sun, 12 Feb 2023 10:22:10 +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> <63e7eb19.050a0220.56539.6aa7@mx.google.com> Date: Sun, 12 Feb 2023 10:22:10 +0100 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=brubar.cs@gmail.com; helo=mail-wr1-x430.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-Seal: i=1; s=key1; d=yhetil.org; t=1676193780; a=rsa-sha256; cv=none; b=aJs5+AzD59Bqxv9Rl82KoxgQelW85jGi7dwCXDtdGYFhD9Rl8v+RzDiCCXv/dmPOvYlV3j lB4HuCrdYxRmlXISmZB4VZPUL5oHqhvchvol9qoa5a/ZrwbIuZx8B/dZ4roLtKhKul0G3/ Hq4jRSJYERac0mSj6hze3xPnHI063WZKclG4EXgratHrfYBaRLiunD3cMa1R1h9ycfytxO QLkJOvyUBUBHKEYoH9Ij0Ox9yoCxL6iKdoa+3tsXxuKuPpMASv/6bCSoZgwIZOX03nIiA+ /XuOQX/IdDHHfI0fwXyPlR7KY1pd4ECnBLICCkoStT3ypdW9ut0RivJ8zYaaeg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=p0vtHdts; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1676193780; 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=sWpPHe/XcUVxg/yVOR7LbWvLreBZfL+az5ItX8/fiy8=; b=QaCw+aP27/FQYN5VVg1e3Ppe2dfJ257L5nCYlJ4W8yEQrbici0I+cGmLqOCtczu8kTEoX6 Y2i9TMhOfG1gQQNdXzagpX8FymWTz1w3VoU0SYdy81zUnBhj4JYw2Ee0t9dZhq4wxCGJea jW2/jyvC+9rTY3HR+zIziqnUNsDbZnc8PIC0laY64MsK6e5rnqPs8xnJoXoqRnEfrXdGZ6 f2ox0XV/01P/1Y6QtEVvybbnNyaJ12Wqhh9ow5VKa6tEVcvJHK3J9Q+DJzCmQIiKsZFsDd uuNU98w4tAAphKaBls2FIMaElWpZ/toG36sxx8U/HRoSBAuNseco/EMKE0kHCA== X-Migadu-Queue-Id: BD1DE40696 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=p0vtHdts; 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-Scanner: scn0.migadu.com X-Migadu-Spam-Score: -12.37 X-Spam-Score: -12.37 X-TUID: ACs7vuvI7kg8 --=-=-= Content-Type: text/plain Hi Arthur, Arthur Miller writes: > Bruno Barbier writes: > > ... but I feel a > bit of passive aggressivity here, for no good reason tbh. I'm just trying to help, giving some valid or invalid advices. I'm sorry that what I wrote, and how I wrote it, made you feel that way. >> >> Yes, let binding is fundamental. But I think it's the first time I see >> 'cl-letf' with the 'symbol-function' place. > > https://nullprogram.com/blog/2017/10/27/ > https://endlessparentheses.com/understanding-letf-and-how-it-replaces-flet.html > https://stackoverflow.com/questions/39550578/in-emacs-what-is-the-difference-between-cl-flet-and-cl-letf > Thanks for these links. I like cl-flet and cl-labels :-) >>> 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. > > Isn't that what I wrote: introducing an extra keymap? > Of course I can solve the problem differently, but that was not what question > was about :). Right. Even when inheriting from the old keymap, it's still building a new keymap. Sorry :-) > Well, I definitely understand you, and agree that overwriting function for > everyone and everything is not the best idea, but unfortunately bindings work as > they do in Emacs. I would prefer to have a local binding, with cl-flet, but this > does not work in Emacs: > > (defun my-read-string (prompt) > (let ((delta 20 ) > (minibuffer-mode-map org-mode-map)) > (window-resize (minibuffer-window) delta) > (cl-flet ((org-ctrl-c-ctrl-c () > (interactive) > (let ((s (buffer-string))) > (exit-minibuffer) s)) > (minibuffer-mode () #'org-mode) > (minibuffer-complete-and-exit () #'org-return) > (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"))))) Yes. cl-flet looks safe to me :-) > > Hooks serve a different purpose. Advice can serve same purpose with exactly > same side effect, and some other limitations. With some care, let-binding is > still more "local" then advice. With other words, I agree with you about the > problems, but not with dogmatic approach that it should never be done, and > that hooks and advices are the replacement. Sorry if my words sounding dogmatic. Else, I agree too :-) >> >>> 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 > > I have never heard before that functions are not designed to be overriden. I > think of them as two slots in a symbol structure; let creates bindings for value > slot, and flet for function slot. Functions are just objects or data as any > other value in lisp. > >> (as there is only one binding at any given time). > > Yes, unfortunately, in Emacs it is so; ok. We do really agree then :-) > but I don't think it should be > :). ... oh no ! ;-) > > There is an interesting package by Nick Ferrier > > https://github.com/nicferrier/emacs-noflet > but it does not seem to work, at least not for me. It's almost like a temporary advice ;-) About your use case, if what you need is asynchronous editing, maybe the with-editor package will be of interest to you: https://github.com/magit/with-editor/blob/main/lisp/with-editor.el It allows sub-processes to call Emacs for editing tasks. It's used by magit. It's easy enough to reuse. I've attached my attempt at it if you're interested. best, Bruno --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=draft.el Content-Description: my-edit-async draft (cl-defun my-edit-async (finish &key mode buffer-name setup cancel) "Open a buffer, let the user edit its content. Return the editing buffer. Call FINISH in the editing buffer if the user validates his edit (C-c C-c). When CANCEL is non-nil, call CANCEL in the editing buffer if the user cancels his edit (C-c C-k). When done, delete the buffer and its content. When MODE is non-nil, use it as the major-mode. When BUFFER-NAME is non-nil, use it to generate a new unique name of the editing buffer. When SETUP is non-nil, call it in the edit buffer to setup the buffer before starting the edit." (unless buffer-name (setq buffer-name "@Async edit")) (let ((buf (generate-new-buffer buffer-name))) (with-current-buffer buf (when mode (funcall mode)) (when setup (funcall setup)) (with-editor-mode 1) (setq with-editor-previous-winconf (current-window-configuration)) (add-hook 'with-editor-pre-finish-hook (lambda () (funcall finish) (set-buffer-modified-p nil)) nil :local) (add-hook 'with-editor-pre-cancel-hook (lambda () (when cancel (funcall cancel)) (set-buffer-modified-p nil)) nil :local) (switch-to-buffer buf)) buf)) (my-edit-async (lambda () (message "My edit:\n%S" (buffer-string))) :cancel (lambda () (message "Canceled (discarded: %s)" (buffer-string))) :setup (lambda () (insert "initial content") (goto-char (point-min)))) --=-=-= Content-Type: text/plain > regards > /a --=-=-=--