From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tomas Nordin Newsgroups: gmane.emacs.bugs Subject: bug#72915: Docstrings of add-hook and remove-hook improvement? Date: Sat, 31 Aug 2024 12:36:22 +0000 Message-ID: <87v7zgrhrt.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21531"; mail-complaints-to="usenet@ciao.gmane.io" To: 72915@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 31 14:37:24 2024 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 1skNM2-0005Q0-8k for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 31 Aug 2024 14:37:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1skNLq-0000Od-ON; Sat, 31 Aug 2024 08:37:10 -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 1skNLk-0000O3-CU for bug-gnu-emacs@gnu.org; Sat, 31 Aug 2024 08:37:04 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1skNLk-0007rL-2q for bug-gnu-emacs@gnu.org; Sat, 31 Aug 2024 08:37:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=OPGLG47rkf5rhjOFBsBxrtN3kA2l1gucWzIkjya00TI=; b=kOgtb5o0YAOjrQAxRFCj98d6ClwtNGEB5+wGstu9Y6XcXg++WfysarnULAr/U7hD8wuPjBnTFt1CvRXQE1UV6Cec3Wk25YCV+sE6kxSiD+BMPADM6DvH7rC+EXC6QyJL/yFv6qG5tDDyCVi7oyKKEWxGAtwZ2wf2C+q4IOp2Wm652Wxjs5Qv1xuM0qDqYEa3GPDfxIl2ZpMx+AxsSSJg3QAsozB+89qakQYgbihKgjPrF8dVb0c1ZekWTzQeQBs8XJegtrDHm79+BfhReHatsSf7f98rw84fUT3HJyNSzDUq7iZa0pf+mf8fwViNa1Ur8n0bLd2N1d10ncBOrX9KVA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1skNMf-0005r8-T7 for bug-gnu-emacs@gnu.org; Sat, 31 Aug 2024 08:38:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tomas Nordin Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 31 Aug 2024 12:38:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 72915 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.172510785022431 (code B ref -1); Sat, 31 Aug 2024 12:38:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 31 Aug 2024 12:37:30 +0000 Original-Received: from localhost ([127.0.0.1]:54233 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1skNM9-0005pj-R2 for submit@debbugs.gnu.org; Sat, 31 Aug 2024 08:37:30 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:45596) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1skNM7-0005pb-KT for submit@debbugs.gnu.org; Sat, 31 Aug 2024 08:37:28 -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 1skNLB-0000MK-3h for bug-gnu-emacs@gnu.org; Sat, 31 Aug 2024 08:36:29 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1skNL8-0007p5-WC for bug-gnu-emacs@gnu.org; Sat, 31 Aug 2024 08:36:28 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 70D5E240027 for ; Sat, 31 Aug 2024 14:36:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1725107783; bh=MAw1T9lsuc2m3zR4Jw3CNgEnlFKW5Ow+VtP/O2a8coA=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=AMT+nK7wCPk6b7xAzrvcM3USi6nefONtkEdWgl1Lzw7AZmq0Vx0yZst/dt/IBEQiD ZBWLQ6KWgzlfW4SuFyjjsRWhWhlpeHfQlFvheZJDxxtWqOwo2EekKmmdSNJhn0fjxj WVw3VVsGfvTEAEOZXiJ+HickxOPldtrM/uJZOWY45ozUG5wLD7gQJ6+IrwBNwdugow EHj/bBdhvzLnsqdMCk0UyAlbNtOww7ZMaTRbFOGWX88TahtxE2V2fchAgmSbqXkOBL QF08wpkjNoeqqS4snjh2dnY8hSBDP4vnMDIjMUMbHkemlV1ayGYtOXicNBCK0KOQ5U v976jIi2iRY1w== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Wwvdg0gLfz9rxF for ; Sat, 31 Aug 2024 14:36:22 +0200 (CEST) Received-SPF: pass client-ip=185.67.36.65; envelope-from=tomasn@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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:291013 Archived-At: Hello List In bug#70820 August 14, Stefan mentions that it is a common confusion to think of the functions in a hook as hooks. It got my attention because I belong to the confused ones every second year or so adding or removing functions from a hook. I suggest the provided patch as a small improvement of the function documentation of add-hook and remove-hook. Maybe it doesn't mitigate the confusion mentioned that much, but it seem to align better with the manual as I read it. What do you think? In add-hook doc, lift up the paragraph about HOOK and FUNCTION and remove the mention about first setting the HOOK to nil. I think that is something internal to the add-hook function and not relevant to the programmer calling the add-hook function? And then say that the resulting hook will be a list both when the HOOK symbol is void or a single function. In remove-hook, stick to the notion that a hook contain functions to run, not hooks. This notion though is a bit confusing in relation to the names of those functions, but that's another story I guess. The following on top of emacs-30. diff --git a/lisp/subr.el b/lisp/subr.el index 28ba30f584e..e60c4119c60 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2090,6 +2090,10 @@ add-hook "Add to the value of HOOK the function FUNCTION. FUNCTION is not added if already present. +HOOK should be a symbol. If HOOK is void, or if HOOK's value is a +single function, it is changed to a list of functions (containing only +FUNCTION in the void case). + The place where the function is added depends on the DEPTH parameter. DEPTH defaults to 0. By convention, it should be a number between -100 and 100 where 100 means that the function @@ -2108,10 +2112,6 @@ add-hook buffer-local value. That acts as a flag to run the hook functions of the global value as well as in the local value. -HOOK should be a symbol. If HOOK is void, it is first set to -nil. If HOOK's value is a single function, it is changed to a -list of functions. - FUNCTION may be any valid function, but it's recommended to use a function symbol and not a lambda form. Using a symbol will ensure that the function is not re-added if the function is @@ -2179,7 +2179,7 @@ remove-hook "Remove from the value of HOOK the function FUNCTION. HOOK should be a symbol, and FUNCTION may be any valid function. If FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the -list of hooks to run in HOOK, then nothing is done. See `add-hook'. +list of functions to run in HOOK, then nothing is done. See `add-hook'. The optional third argument, LOCAL, if non-nil, says to modify the hook's buffer-local value rather than its default value.