From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eduardo Ochs Newsgroups: gmane.emacs.help Subject: Re: How do I wait, or sit-for, until a hook is run? Date: Fri, 30 Dec 2022 19:43:11 -0300 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26281"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 30 23:43:53 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pBO6T-0006f9-6v for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 30 Dec 2022 23:43:53 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pBO64-00058a-AO; Fri, 30 Dec 2022 17:43:28 -0500 Original-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 1pBO63-00058R-KP for help-gnu-emacs@gnu.org; Fri, 30 Dec 2022 17:43:27 -0500 Original-Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pBO61-0004Et-Uf for help-gnu-emacs@gnu.org; Fri, 30 Dec 2022 17:43:27 -0500 Original-Received: by mail-il1-x130.google.com with SMTP id d14so12025638ilq.11 for ; Fri, 30 Dec 2022 14:43:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=BKcqNHLLnH0I7kegDtFreoELHxOqKjvljlLxlK+zv9c=; b=VWs96MHTv4BuMxq6+mt7yiP6Aq4TzGdliSu4Qj5GCUZI0QRlTHkxf+/po4P+a8Sz0C VlcY7vwy9aHcOPZKUKUJ14ptxJrNpJQFOz/LflkjpZ6RvO+V6DAFIQibcad6IzFRXSJn x4BeRuyAc4SbdlC+PIjNlis+7miNrU8RkT2ZHF+8ZqziwlKulwPUQnuHFPIEYEI2+E9L 6eKPjjcuI71jInYsTtCI9RV1WDNj2tyWRcnQLrM1IGB1btIrlKGuGqhyXykf5ZbvQUzH xSMf9YAyGzJT0FkinNRGSKQkGy042NmVPArl8ZA5LgGU0lWR6LGZzN8CVBo5GxeTPJfL 44pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BKcqNHLLnH0I7kegDtFreoELHxOqKjvljlLxlK+zv9c=; b=oiU/t0c/WM0VMfYQLRHiblaFcUkZ2TvJiaDu6GG9E65a+buf5Qj50wSlNlYjJmjLdN 7S7a1zxFcobyXVKKmbbIM+6nsum7tev7IZX3RQFrC1fGa7nwxyNI5RpRiLvLlUhvXCp7 7N2BT8jm7/z9Qu5x4dd/2SaH8lgz5h88ff4+Oqsr8qRSFCwDH9sLpCXib9UPke9EZL2U 52brAQyNgVKoQsVDU9/Wt/hQqenaVrK79KoBJz02Y7q5iBZyNTDrrJpb7q4MBDKc4Srs 1WWeVLyOm6MhnYK6PJpds5urvWnfYwgcJObp4xIC3w2cicHzzpQgT84EA/XYFHw9rkIJ bHcQ== X-Gm-Message-State: AFqh2kp0zAedxKpKeiiYMJbxs08SgkLfyytbDks/0yEX3BMUqI1sERk9 NDR3BjpQaXk1MIsRsxFYxFhOOf+/QDHN8XeDJFRIbq1c2Og= X-Google-Smtp-Source: AMrXdXv5wZh2WeB9yEGMA2SR4j/fPO0099MDa3VzQjdD+RDF4KSDTbcBiK2T4f7B3IzGJY9H9I5oyBkCOw8YES8asis= X-Received: by 2002:a92:b742:0:b0:30c:2b07:ba75 with SMTP id c2-20020a92b742000000b0030c2b07ba75mr504428ilm.39.1672440203713; Fri, 30 Dec 2022 14:43:23 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::130; envelope-from=eduardoochs@gmail.com; helo=mail-il1-x130.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, 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: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:142058 Archived-At: On Thu, 29 Dec 2022 at 18:41, Eduardo Ochs wrote: > I am trying to write a function (my-sly-wait) that can be put here, > > (save-window-excursion (sly) (my-sly-wait)) > > and that only returns when the hook `sly-mrepl-hook' is run... Hi list, I found a solution that is not too ugly and that apparently works well. The main part of the code is below: (defvar ee-wait-status nil) (defun ee-wait-repl-started () (setq ee-wait-status 'repl-started)) (defun ee-wait (ntimes time) "Run NTIMES (sit-for TIME); aborts in some conditions." (catch 'stop (dotimes (i ntimes) (if (not (sit-for time)) (throw 'stop 'got-input)) (if ee-wait-status (throw 'stop 'ee-wait-status-not-nil))) 'timeout)) (defun find-slyprocess-reuse () "Go to a Sly REPL buffer (when we want to reuse an old one). This is an internal function used by `find-slyprocess'." (find-ebuffer (sly-mrepl--find-buffer) :end)) (defun find-slyprocess-create00 () "Go to a Sly REPL buffer (when we want to create a new one). This is an internal function used by `find-slyprocess-create0'." (let ((sly-command-switch-to-existing-lisp 'never) (sly-auto-select-connection 'never) (sly-lisp-implementations '((sbcl ("sbcl")))) (sly-default-lisp 'sbcl)) (sly))) (defun find-slyprocess-create0 () "Like `find-slyprocess-create0', but only returns when the mrepl starts. If the mrepl doesn't start in 30 seconds this function yields an error." (interactive) (unwind-protect (progn (setq ee-wait-status nil) (add-hook 'sly-mrepl-hook 'ee-wait-repl-started) (find-slyprocess-create00) (ee-wait 60 0.5)) (remove-hook 'sly-mrepl-hook 'ee-wait-repl-started)) (if (eq ee-wait-status 'repl-started) "Repl started!" (error "ee-sly: Sly timed out"))) The rest of the code - with context and comments - is here: http://angg.twu.net/eev-current/eepitch.el.html#wait-for-hooks http://angg.twu.net/eev-current/eepitch.el.html#ee-wait http://angg.twu.net/eev-current/eepitch.el.html#eepitch-sly (find-eev "eepitch.el" "wait-for-hooks") (find-eev "eepitch.el" "ee-wait") (find-eev "eepitch.el" "eepitch-sly") Links and suggestions are still welcome! =) Cheers & HNY =), Eduardo Ochs http://angg.twu.net/eepitch.html