From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: phillip.lord@russet.org.uk (Phillip Lord) Newsgroups: gmane.emacs.help Subject: autoloading entire function Date: Mon, 13 Jun 2016 16:43:08 +0100 Message-ID: <87mvmpf62b.fsf@russet.org.uk> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1465832641 16158 80.91.229.3 (13 Jun 2016 15:44:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 13 Jun 2016 15:44:01 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jun 13 17:43:47 2016 Return-path: Envelope-to: geh-help-gnu-emacs@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 1bCU1e-00006K-1k for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Jun 2016 17:43:42 +0200 Original-Received: from localhost ([::1]:57299 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCU1d-0001iM-7P for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Jun 2016 11:43:41 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCU1D-0001gs-Q4 for help-gnu-emacs@gnu.org; Mon, 13 Jun 2016 11:43:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCU18-0006m6-Q2 for help-gnu-emacs@gnu.org; Mon, 13 Jun 2016 11:43:14 -0400 Original-Received: from cloud103.planethippo.com ([31.216.48.48]:57325) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCU18-0006lh-Eg for help-gnu-emacs@gnu.org; Mon, 13 Jun 2016 11:43:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=russet.org.uk; s=default; h=Content-Type:MIME-Version:Message-ID:Date: Subject:To:From; bh=7G7beHGQPL39wEJAbC6w6LCyJqId3eunMNZUDsQj+Ak=; b=PtWiJ2WJ4 cTjI805D9awQzYwaxi3ROntD7c9eV+GgB0sft0JPjaj2FsGj2CWh3G+I/rrTqxRW9q0voM52lX01R SpPmQ0VklK7A6ngyxtn/6kVIJhH7CjmuAi2kw/xgIzDa3eL3JkdaxUnXMC4aZ3hadcM+DRvRCFhed 0B/60IJWRcqwvAbdyrUsDiqbc3okhxUw7yeW6MxsrdYN/VVUnG78J4H1HQapbprKpciJWdIDEWuoG uuCmctUOLuJm7mn8YaufdF5JAeqfxSqifnKj144Gh+YP0weie0zLhA4UOapU1aBzhBtAg7ly4aHuq /ojxGbN60AdkCjI5NofoXSOHQ==; Original-Received: from cpc1-benw10-2-0-cust373.gate.cable.virginm.net ([77.98.219.118]:60349 helo=russet.org.uk) by cloud103.planethippo.com with esmtpsa (TLSv1.2:DHE-RSA-AES128-SHA:128) (Exim 4.86_1) (envelope-from ) id 1bCU17-001ULg-FL for help-gnu-emacs@gnu.org; Mon, 13 Jun 2016 16:43:09 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.95 (gnu/linux) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cloud103.planethippo.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - russet.org.uk X-Get-Message-Sender-Via: cloud103.planethippo.com: authenticated_id: phillip.lord@russet.org.uk X-Authenticated-Sender: cloud103.planethippo.com: phillip.lord@russet.org.uk X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 31.216.48.48 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:110432 Archived-At: I have written a function in my package which looks like this... (defun lentic-script-hook (mode-hook init) (add-to-list 'lentic-init-functions init) (add-hook mode-hook (lambda () (unless lentic-init (setq lentic-init init))))) It then gets used like this: (lentic-script-hook 'python-mode-hook 'lentic-python-script-init) Essentially, it makes writing a set of stereotyped "add-hook" calls a bit easier. But I now have an autoload problem. If I want to do this: ;;;###autoload (lentic-script-hook 'python-mode-hook 'lentic-python-script-init) My code will now break since `lentic-script-hook' is not defined. I could, of course, add an autoload cookie to `lentic-script-hook'. But now, when the autoload file is loaded, lentic-script-hook is called, so loading will be forced which defeats the point of autoloading. So, I need to put the entirely of `lentic-script-hook' into the autoload files. Of course, it will itself not be autoloaded, but that's not a huge problem. How to achieve this? The only solutions I have so far are this: ;;;###autoload (defun lentic-script-hook (mode-hook init) (add-to-list 'lentic-init-functions init) (add-hook mode-hook (lambda nil (unless lentic-init (setq lentic-init init)))))) putting everything on oneline does the trick. But it's ugly to read, and, if I evaluate the source file manually (i.e. I don't use autoloads), the form is commented so does not get evaluated. Another options is not use defun but it's expansion and autoload this: ;;;###autoload (defalias 'lentic-script-hook #'(lambda (mode-hook init) (add-to-list 'lentic-init-functions init) (add-hook mode-hook (lambda nil (unless lentic-init (setq lentic-init init)))))) which works but, also, is not ideal. The defun macro is there for a reason, and it would be nice to use it. Any other options I have missed? Phil