From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrew Cohen Newsgroups: gmane.emacs.bugs Subject: bug#63620: 30.0.50; [Feature Request] run hooks on sleep/wake Date: Sun, 21 May 2023 07:19:27 +0800 Message-ID: <87fs7qmw00.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="22386"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: 63620@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun May 21 01:25:20 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 1q0Vwt-0005Y2-NE for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 21 May 2023 01:25:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q0Vwe-0001AV-JS; Sat, 20 May 2023 19:25:04 -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 1q0Vwc-0001A7-IT for bug-gnu-emacs@gnu.org; Sat, 20 May 2023 19:25: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 1q0Vwc-0004DL-9Y for bug-gnu-emacs@gnu.org; Sat, 20 May 2023 19:25:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q0Vwc-0003Kl-4S for bug-gnu-emacs@gnu.org; Sat, 20 May 2023 19:25:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andrew Cohen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 20 May 2023 23:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 63620 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.168462508612787 (code B ref -1); Sat, 20 May 2023 23:25:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 May 2023 23:24:46 +0000 Original-Received: from localhost ([127.0.0.1]:59603 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q0VwL-0003KA-Hn for submit@debbugs.gnu.org; Sat, 20 May 2023 19:24:45 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:57678) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q0VwJ-0003K3-Ly for submit@debbugs.gnu.org; Sat, 20 May 2023 19:24:44 -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 1q0VwJ-00017Z-Fb for bug-gnu-emacs@gnu.org; Sat, 20 May 2023 19:24:43 -0400 Original-Received: from mail-tycjpn01on2072a.outbound.protection.outlook.com ([2a01:111:f403:7010::72a] helo=JPN01-TYC-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 1q0VwG-00049d-TQ for bug-gnu-emacs@gnu.org; Sat, 20 May 2023 19:24:43 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HX38iqiWiqFuKIloy5/IXWANRw7zbtlsUqqLCMtthXbI/uM/y+yPOsF5mglOQNzDDMPkYENV+6gePVflFK5mV4Ybh1prb2akOPtaSjX9veZgbKTGAsqGFCe5EUmI1Enl4ABlrx9F8Pavt8DUEIMa+VafJ3SPaUwF9wOCKBgcMR1MnlFWazcDH95CzkzH3hV3HbwGzR5y7m2Rq5SaRF4gZxqrJlVPu6TFO38XTbvqcezyYqnIkwhiUZFLSokClKCQH9IFFDsUKNQckLHo2m4tepICZotUHRj4c87mp+nuYqFH76lzVzT2rcuqJUBF4dT1/W1giTuqX8BT0HXwVpQweA== 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=R/vMerENyhLB6MqkxKTPylMxzGx5V+YRFPXpXZosGoA=; b=adK6UwboLUaGVoeM8mYLft3RV0CiUZmHHHs697qqQg/UXyLH2VzBQ2X06nX23aU+UiDz3OeHCdd4UWjWkkVAVBFWCLElCcuMg4tQIaovkzKb6XPgX+BWZcdZish3DNkgkJE6kX5vfB4Yb5Tb9UY1iqapHVQy4qz46Hsci8o5yLkvxN8HOiSBEb+ZZ+OE7L+DG7SZVbBzf7/PuakjuxB80P4tHB3bt+IPLkek9NTvdrgBKcdokTDaOgbpjvLJKf/i5puuavxyFL7cpXPAl/uCBIpLhB71mvOkCLa9qegkJtmQkP+NHXiMK1GWWWQynAPx7sgig05XHRI1taYlw/AvCg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=ust.hk; dmarc=pass action=none header.from=ust.hk; dkim=pass header.d=ust.hk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ust.hk; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=R/vMerENyhLB6MqkxKTPylMxzGx5V+YRFPXpXZosGoA=; b=bhYFJqm0V/5OOpDLJMAHbw+/4Z9+qsKRUI6hMbN34qsxSbnrUePlzsBMOxqRC1WwADcwiT9qjbq1Ulo1D1xSbNMvrtWuWSDcnjXOoiR+KCD0YEZMlMyrqnXBQtkNitpnpJqTEfBkeC9b0orA0iIlU7y1KNxfhpKDLnThI0WuA5NgMp3MeyZbyytflW7M56eeHz78yoKLe+fh7GwQXFdtIcnsJGmYMj8GNqQc6LRWfV8uP9zzN4ri4mHIRg4YUcIRr13nPk4Hcyw7CdCW/HIeVQMal/X0KGN9Z8CgQ8hv0i038EPPtyFbcKiG7JhOS5gGqbpICt49Sbtd7ewAaIWGEw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=ust.hk; Original-Received: from OS3P286MB1877.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1bf::11) by TYWP286MB1959.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:164::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.27; Sat, 20 May 2023 23:19:32 +0000 Original-Received: from OS3P286MB1877.JPNP286.PROD.OUTLOOK.COM ([fe80::c1ac:edec:7164:36ec]) by OS3P286MB1877.JPNP286.PROD.OUTLOOK.COM ([fe80::c1ac:edec:7164:36ec%7]) with mapi id 15.20.6411.025; Sat, 20 May 2023 23:19:31 +0000 X-ClientProxiedBy: SGAP274CA0022.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b6::34) To OS3P286MB1877.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1bf::11) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS3P286MB1877:EE_|TYWP286MB1959:EE_ X-MS-Office365-Filtering-Correlation-Id: 787eba8d-a9b5-47ad-ac5c-08db5988aa95 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8cPUqa/znd24Sk+T/VAVRciHMy3tNClwNkgRdgt+o6HB8102+ldQWCfPlkZWo8/7AEmib7Tfq5hwDqOGETwU/VMGApPi4xz03/6Tkd+PMANuwd+Yq269v8FGQpgBxLW4iaoUl7Si+kgyszMbyvj/DiXZpcy8sOKqB3zIzkUr/h5alPtokcUu2LFaV+7oLu36H37+dCQEieBrNb/BXAjFdI4jVSMxu3W0yurajkbAEr3Q39FE5mU5DW7qOTfsBpMG+yyYHg2j8wzPyvP84jlL2SNA5ak71xa2k9zLEf/sfIemG4a2DwJE2yfxdbhybsslOOoQXIfWVB+mqvQjTbp2wZIVK1DOSm4CdueXPCfnrSm7yZhWSZaN1HkQ0/xVeMwEr15JhPWDeQiwHFyzSVgrnlUikiixhf8vukm09Pl8FebNy56uaHTBFQ+sw7PEAjk7WaIBkcB0sJJNmoBJkix54J3B+jUJADSijE6b3nxeD7aoFAC6/qYCtHi23bWULLDcYCJMdbVLuxabK9yoEOOml69AAWTCVLqPNLkFStkFy97gZFqkJ84VjFpYpzrreaEW X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:OS3P286MB1877.JPNP286.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230028)(4636009)(396003)(376002)(366004)(346002)(39860400002)(136003)(451199021)(2906002)(41320700001)(38100700002)(2616005)(6506007)(83380400001)(26005)(6512007)(186003)(8676002)(8936002)(36756003)(86362001)(316002)(786003)(41300700001)(5660300002)(6916009)(6486002)(6666004)(66476007)(66556008)(66946007)(478600001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9rq8D0krlsHKM1nDvg3Vuw0QJS5/XvyTFjK55TIcVBvl84zpT5otFlSV/Zfhhq/g9+GkL6Mh37eGS8b/PCEc+Mo8G8L34RsxOaiZACKJHskTFhy9ZSCTmH3HrGoSNQFG+/IbexkgGmv3YvM98LvYVyhhoSuxKiWFi2WaLNKufFyFHkVvvRl0J3fcKVb78VRAcHc2zRXErQxON5tD+LGkr41RIfqP0gyx8LkwFhgX4VNJh4tGWoYYn/ftheSHkx/1qj4tGTC10jnFmve6UgEVxs9K10mElkb/MMNlcz/wCs5cqlZgmCb+6oICtzEc8FcUU/PzBwDJ7cJLqbVx9tCQsWER6sTqAAIC/sGAIGK95wRPQc6AxgeduRZKZOp7X8y9lDAF10fY54Hc+juFQ9+RR8uhSdYMsR5s7UmRhXnTCH7m6mzKNPeHSqpDZvd2eP7TZVSd9oV6roBg+psGECv1hQ3/pwOvMxAktfZxBS0TYAafHp/QP4DssivcAKJjP4FL/aluB9kNlsaJ+jpGZu0gE6dAcA8XV9J0L95bUUFBP23TfBTgF8fDgxoI+BsGqWeiyJ6VVpzMfZ/cukE/jTKrK5uVJKX0Kw27cXDlVfw9qqvaZj0UpOkBicZc2kN9O4jn9paq04ClmclSgsE2ZHWG5Ta74wxuZRjfijUEjZOg9wrRYr04tgz+7KswWHOmRnKXjwFRrNcm1h5j28UnY0iRxENrNdLHQHTW2RehsKnU4/CunKo1JvjlJD8Xr2 ms9O1dQ4qbSVfj7KgHxEQlYJDL5V1Eq+lIYmFzM1B6DUkGgvA49q5Xa5UV3XYNvNhXLqvEj6NJ7QjkALPWvTKzBNTwmUbw+c57 X-OriginatorOrg: ust.hk X-MS-Exchange-CrossTenant-Network-Message-Id: 787eba8d-a9b5-47ad-ac5c-08db5988aa95 X-MS-Exchange-CrossTenant-AuthSource: OS3P286MB1877.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2023 23:19:31.6972 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: c917f3e2-9322-4926-9bb3-daca730413ca X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 41aUxSe+hIcG0QJpbO9vunWkZqHRm366anUzks4wbZgG8z2p2F5IZrbBZCy1Sy7n X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYWP286MB1959 Received-SPF: pass client-ip=2a01:111:f403:7010::72a; envelope-from=acohen@ust.hk; helo=JPN01-TYC-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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:262071 Archived-At: I am playing around with various network things (mostly vpn related) and need Emacs to take certain actions when my laptop sleeps and wakes. This is easy to do using the existing dbus support (the relevant code is below, which runs hooks on sleeping and waking) The question is whether this is useful enough to add to Emacs, and if so the best place to put it. Not too long ago, Eric Abrahamsen added gnus-dbus.el which is similar, although for a single purpose: to close gnus server network connections on sleep. This has a single entry point for the user: set 'gnus-dbus-close-on-sleep to t to enable the feature. Options: 1. Do nothing (this isn't useful enough to change anything, and I can just keep using my own code). 2. Add a small package dbus-sleep.el. I would also remove gnus-dbus.el but leave the variable 'gnus-dbus-close-on-sleep and use it to control the installation of appropriate gnus functions to the new hooks. 3. 2. Add the new code to the existing dbus.el. I would also remove gnus-dbus.el but leave the variable 'gnus-dbus-close-on-sleep and use it to control the installation of appropriate functions to the new hooks. I mostly favor adding it to dbus.el. The argument against: dbus.el is focused on providing language bindings for the D-Bus API rather than a user-feature. The removal of gnus-dbus.el shouldn't cause any problem since I would maintain the same functionality enabled by the same variable, so no user-visible change. Advice? ;;; Code: (require 'dbus) (defcustom dbus-sleep-sleep-hook nil "Hook to run on sleep." :group 'dbus-sleep :type 'hook) (defcustom dbus-sleep-wake-hook nil "Hook to run on wake." :group 'dbus-sleep :type 'hook) (defvar dbus-sleep-registration-object nil "Object returned from `dbus-register-signal'. This is used to unregister the signal.") ;;;###autoload (defun dbus-sleep-enable () "Use `dbus-register-signal' to close servers on sleep." (interactive) ;; Don't enable if it's already enabled. (when (and (featurep 'dbusbind) (not dbus-sleep-registration-object)) (setq dbus-sleep-registration-object (dbus-register-signal :system "org.freedesktop.login1" "/org/freedesktop/login1" "org.freedesktop.login1.Manager" "PrepareForSleep" #'dbus-sleep-handler)))) (defun dbus-sleep-disable () "Unregister sleep signal." (interactive) (condition-case nil (dbus-unregister-object dbus-sleep-registration-object) (setq dbus-sleep-registration-object nil) (wrong-type-argument nil))) (defun dbus-sleep-handler (sleep-wake) "Handler to execute sleep and wake functions. SLEEP-WAKE is t on sleeping and nil on waking." (ignore-errors (if sleep-wake (run-hooks 'dbus-sleep-sleep-hook) (run-hooks 'dbus-sleep-wake-hook)))) -- Andrew Cohen