From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Albinus Newsgroups: gmane.emacs.bugs Subject: bug#63620: 30.0.50; [Feature Request] run hooks on sleep/wake Date: Sat, 10 Jun 2023 12:47:10 +0200 Message-ID: <87legr1tn5.fsf@gmx.de> References: <87fs7qmw00.fsf@ust.hk> <87lehinlvg.fsf@gmx.de> <87y1ky83du.fsf@ust.hk> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14859"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 63620@debbugs.gnu.org To: Andrew Cohen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 10 12:48:21 2023 Return-path: Envelope-to: geb-bug-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 1q7w8q-0003gi-PL for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 10 Jun 2023 12:48:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q7w8Z-0005GJ-ST; Sat, 10 Jun 2023 06:48:03 -0400 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 1q7w8Y-0005Ey-GW for bug-gnu-emacs@gnu.org; Sat, 10 Jun 2023 06:48:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q7w8Y-0001cK-7r for bug-gnu-emacs@gnu.org; Sat, 10 Jun 2023 06:48:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q7w8Y-0005aq-3f for bug-gnu-emacs@gnu.org; Sat, 10 Jun 2023 06:48:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michael Albinus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 Jun 2023 10:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63620 X-GNU-PR-Package: emacs Original-Received: via spool by 63620-submit@debbugs.gnu.org id=B63620.168639404821329 (code B ref 63620); Sat, 10 Jun 2023 10:48:02 +0000 Original-Received: (at 63620) by debbugs.gnu.org; 10 Jun 2023 10:47:28 +0000 Original-Received: from localhost ([127.0.0.1]:33336 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q7w7z-0005Xw-Uu for submit@debbugs.gnu.org; Sat, 10 Jun 2023 06:47:28 -0400 Original-Received: from mout.gmx.net ([212.227.17.22]:46829) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q7w7w-0005Xd-Ef for 63620@debbugs.gnu.org; Sat, 10 Jun 2023 06:47:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1686394032; x=1686998832; i=michael.albinus@gmx.de; bh=58rZXdSF9YrXXbPRgCKavpXrmqBTXpsIVYaiHWeY1As=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date; b=TIO7/BPGTyfNnnTegpwXFv6ndVLJov0Xj2lcdFdXp+pgwTlpNV2fk7eyG2EqgjucvGJZ23Q yv40rkLGMI1vPBxOZTcexNupqM8pfS0KkWtYUC2i3dWY26yvetd9kKnKD8TinlDCSGnP7NBlu hlTtUAUsIOOyBlEV6bJhJ+tmKKNcwHkrGa4L8Q7bn7GfeEZ9pENtIOcq0iuz9knznkfayjPch mGk+w+V8BhcS4n3rnAIIb+Z36r373MW3+Aqc3rGA4cawP+3B2rHGfw5PsvVTPDEZ0VykIzbdC 6j8euDxHqEgimSXuFyzbQmOpujAkVJ6DSn++xtEcib/gyXKGN2IQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from gandalf.gmx.de ([185.89.39.13]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mi2Jt-1pdXBR0L57-00e0sT; Sat, 10 Jun 2023 12:47:12 +0200 In-Reply-To: <87y1ky83du.fsf@ust.hk> (Andrew Cohen's message of "Mon, 05 Jun 2023 21:06:37 +0800") X-Provags-ID: V03:K1:+7Vm+4Gyy1Z9PmskvjTk1LpsZ8UtHELNn1jmoKlnuVNpmdjWAlW sN8fWXRbP/fmna7hzSzNt5GV+9dWyd/nNPq42mhuiRyOqFDwtvKAiF2RI8Q+jtTcKqLnoZl pHp4oy+WHeYLJ1Mk/UPHsnFw/cptxikFAuu/KS/h4YBpwdRhJjDcbx9M3OgE+kDz32SuB81 Wg9J8+EjNZB1EVX0dB6Fw== UI-OutboundReport: notjunk:1;M01:P0:I0NciSjItbM=;IW2RUAF7wLLXOa1ne7Fq3UQZZ47 LGEDGWctDwbIgF0AtwET9HVIEf2OmaUzjbNdPWH0r3v+I3VkNh5lfSlM/QHkaxV+2hkDWmxGE 0ogR8eCrcXGQuR3Y/kL9K57SvevjBUbeyVlIM4WY8Ne6eq5hvuzGJKOtmFuS5DGE7iL6R+8yn BjeHrWgm4h6QawqLoUEdA1vV1vHtOkaJ128ElgVpJycR31LrtNmeCmZMs3hygT/vRuEOJiQmM au4QMVkymtObRv9zIU7mJrka6/LZlYcAVJAkLCXmFnc6TUvu7D8rpoAh05ilOjZXS8jDBT/6b fUkeOv/6h1TLbTqeFyWlkzKI+kqnXkxvym5Vvr19398LHTQscAkv/v1MZ/JFOFXwqR+IKXhlx YJfFAqiHDwr6SXMYuil+MuAGoPse7d6bnHGbJlh8EpIZnbuxCDdjXzwLTpmZDPDQBxIGwFq7X vjBtcdfgfixk55zeloPsUxTL9VDwdz9SnO7s8vDreezs22kt9zzcZ8hvOAG6pSVlWz8TZkZdy F3ol/au9fcrkqZE2b8BzlMoZrc+1VrL8AndS1IOdi6YOe9jtGgVrrt6XEASxc5eNUQNka/Vw+ ziY8kkqqALeOr+uReGH6dXCAoIfn657RQGGtFM+qlSurvv3bqwxFFDpD6oI7YTuga1yFkeDlg 4whweh1LBM5+IZqBER0EwZP7mKvUNTnoCIu8n6THCfGevRyRWjA3g7M+Dfk/psPqiYOrYxaOC rJmwEZy5DhYa/zMZ62r0mQrtfOA98iCAwX4arf5TmqO+mcPDe23QmdepNDihEii6K9tpu3ue X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:263208 Archived-At: Andrew Cohen writes: > Dear Michael Hi Andrew, sorry for the delayed answer, I've been busy ... > I've now put everything together and modified the gnus code to use the > new sleep.el. But I remain unsure if I should remove gnus-dbus.el > entirely (everything remains the same for the user: setting > gnus-dbus-close-on-sleep to a non-nil value will enable the feature > using the global minor mode rather than gnus-dbus). And is sleep.el > something worth adding? It depends whether sleep.el will be added to vanilla Emacs, or as GNU ELPA package. It's not my decision, but I lobby for the former. In this case, it could be used in gnus-dbus.el. Just some few comments on the code > ;;; sleep.el --- run hooks on sleep and wake -*- lexical-binding:t -*- I would be more precise. You don't mean sleeping Emacs or another application, but you mean sleeping the machine on OS level. Say it so. > ;;; This global minor mode enables evaluating code when the device > ;;; running Emacs enters or leaves the sleep state. Two hooks are > ;;; used, sleep-sleep-hook and sleep-wake-hook, run when the system > ;;; detects that it is going to sleep or waking up. Currently only a > ;;; dbus interface to detect sleep state change is implemented. Please quote Lisp objects like `sleep-sleep-hook'. D-Bus is spelled out in commentaries as D-Bus. > (defgroup sleep nil > "Run hooks on entering/leaving the sleep state." > :group 'hardware) > > (defcustom sleep-sleep-hook nil > "Hook to run on entering sleep." > :group 'sleep > :type 'hook) > > (defcustom sleep-wake-hook nil > "Hook to run on leaving sleep." > :group 'sleep > :type 'hook) These are the user visible objects. Please be precise what is going to sleep. The machine or device. > Run sleep-sleep-hook and sleep-wake-hook as appropriate." Please quote sleep-sleep-hook. > (unless sleep-registration-object > (setq sleep-registration-object > (dbus-register-signal :system > "org.freedesktop.login1" > "/org/freedesktop/login1" > "org.freedesktop.login1.Manager" > "PrepareForSleep" > #'sleep-handler)))) I would also protect against D-Bus errors. Like (ignore-error dbus-error (unless sleep-registration-object (setq sleep-registration-object (dbus-register-signal :system "org.freedesktop.login1" "/org/freedesktop/login1" "org.freedesktop.login1.Manager" "PrepareForSleep" #'sleep-handler)))) > (condition-case nil > (progn > (dbus-unregister-object > sleep-registration-object) > (setq sleep-registration-object nil)) > (wrong-type-argument nil))) Aka (ignore-error (dbus-error wrong-type-argument) (dbus-unregister-object sleep-registration-object) (setq sleep-registration-object nil)) > When sleep-wake-mode is enabled, Emacs will execute the hooks Please quote sleep-wake-mode. > support dbus detection of sleep state change." D-Bus is spelled out ... Furthermore, it would be nice if you add - documentation in lispref node "(elisp) System Interface". I'm not sure whether it is good for a new subnode, or whether it shall be documented in "(elisp) System Environment". This documentation should also give a practical example for functions in sleep-sleep-hook and sleep-wake-hook. - adding the functionality to etc/NEWS - if possible, adding tests in test/lisp/sleep-tests.el Best regards, Michael.