From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ian Dunn Newsgroups: gmane.emacs.devel Subject: New Package for GNU ELPA Date: Sun, 22 May 2016 12:45:35 -0400 Message-ID: <87posef3dc.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1463935590 26418 80.91.229.3 (22 May 2016 16:46:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 22 May 2016 16:46:30 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun May 22 18:46:17 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1b4WW7-0004sH-4O for ged-emacs-devel@m.gmane.org; Sun, 22 May 2016 18:46:15 +0200 Original-Received: from localhost ([::1]:43866 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4WW3-00060X-59 for ged-emacs-devel@m.gmane.org; Sun, 22 May 2016 12:46:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58751) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4WVY-00060P-Js for emacs-devel@gnu.org; Sun, 22 May 2016 12:45:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b4WVW-0002X2-Th for emacs-devel@gnu.org; Sun, 22 May 2016 12:45:40 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:51377) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4WVW-0002Wy-Pl for emacs-devel@gnu.org; Sun, 22 May 2016 12:45:38 -0400 Original-Received: from [2604:6000:1010:176:d06f:8928:a420:e516] (port=48288 helo=escafil) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1b4WVV-0001YR-2H for emacs-devel@gnu.org; Sun, 22 May 2016 12:45:37 -0400 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:203940 Archived-At: --=-=-= Content-Type: text/plain I'd like to offer my new package, hook-helpers (https://savannah.nongnu.org/projects/hook-helpers-el/), to GNU ELPA. I've already filled out copyright paperwork for Emacs. --=-=-= Content-Type: text/html; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable

Often times, I see people define a function to be used once in a hook.= If they don=E2=80=99t do this, then it will be an anonymous function. If= the anonymous function is modified, then the function can=E2=80=99t be removed. Wit= h a function outside of the add-hook call, it looks messy.

The define-hook-helper macro is a solution to this. Thin= k of it as an anaphoric add-hook, but one that can be called many times= without risking redundant hook functions. It gives a cleaner look and feel to Emacs configuration files, and could even be used in actual libraries.

The purpose of this package is to build upon add-hook and remove-hook.= When you have something like the following:

(=
defun my/after-init-hook ()
  (set-scroll-bar-mode nil))
	    

You’ve got to remember to actually add this to the after-init-ho= ok variable. Alternatively, you can use a lambda function:

(add-hook 'after-init-hook (lambda () (set-scroll-bar-mode nil)))
	    

But then if you want to modify the function, it’s permanently st= uck on the after-init-hook variable, and you have to deal with it. It&rsqu= o;s not a problem for after-init-hook, which is used once, but would be a p= roblem for a mode hook, like text-mode-hook.

Instead, hook-helpers can do the following:

(define-hook-helper after-init
  (set-scroll-bar-mode nil))
	    

Which handles everything for you.

--=-=-= Content-Type: text/plain -- Ian Dunn --=-=-=--