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: Re: using use-package Date: Wed, 29 Jun 2016 18:02:16 +0100 Message-ID: <87furwvsh3.fsf@russet.org.uk> References: <20150805055619.13567.17B26335@ahiker.mooo.com> <17131863-cbb8-4a85-8470-490fe9a0c0d4@googlegroups.com> <66dceb24-5fef-4316-8c8b-e9a3e62b0fb8@googlegroups.com> <3594e2c6-bd02-412f-98df-9dd0f145277a@googlegroups.com> <01b4d996-aad3-44ff-a580-7950b25b7dc8@googlegroups.com> <87r3nbh3n3.fsf@russet.org.uk> <0566e644-b87b-46f9-91a5-b9c38befd55e@googlegroups.com> <18cc3e7d62270dbe3e40bb2b73087b60.squirrel@cloud103.planethippo.com> <4deb171d07e312f6e3cd3bae4317ac40.squirrel@cloud103.planethippo.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1467219788 7533 80.91.229.3 (29 Jun 2016 17:03:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 29 Jun 2016 17:03:08 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jun 29 19:02:58 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 1bIIt7-00044k-KP for geh-help-gnu-emacs@m.gmane.org; Wed, 29 Jun 2016 19:02:57 +0200 Original-Received: from localhost ([::1]:45067 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIIt6-0003TT-Vn for geh-help-gnu-emacs@m.gmane.org; Wed, 29 Jun 2016 13:02:57 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53546) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIIsg-0003RT-W0 for help-gnu-emacs@gnu.org; Wed, 29 Jun 2016 13:02:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bIIsb-0008Oy-O2 for help-gnu-emacs@gnu.org; Wed, 29 Jun 2016 13:02:29 -0400 Original-Received: from cloud103.planethippo.com ([31.216.48.48]:47381) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIIsb-0008Oo-EY for help-gnu-emacs@gnu.org; Wed, 29 Jun 2016 13:02:25 -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:References:Message-ID :Date:In-Reply-To:Subject:Cc:To:From; bh=Udr4EEaB2ddkOtu3W7gmo9vCdxhO3xvB8J7KuTsciIc=; b=NoFP10I+dCeZFsmTGLKy2KEzzV WyLWRUdsNObtvsv2u3y5Z4Df9DzBEQKVpU79idtmXVQ8/P4jdVYWn3SQGDaYnYbp2FEUcCr/4iP68 c/DKo0GdhsxbUtRrHqiNDvfNIpGpre8bOdcxIlvWSYxaQEMWwqeAGEx08GDxxhjcQburX+utcbJiC 92/c+1Lsu7y5qDmJFk+BKrtqSDMcSbEPohs1TnBU1JVtz8pnd6qyfyI0dLXdL8tj3xnb26+SYW/a0 fXtoq1l/gYNOdb+m5JPV/W7+qW+kqtCiCHpAlaJUk5SZZHVK5WoDnMHbWV87m7h0mSs8MvKcQz0Ka 7fJAyAIQ==; Original-Received: from cpc1-benw10-2-0-cust373.gate.cable.virginm.net ([77.98.219.118]:59399 helo=russet.org.uk) by cloud103.planethippo.com with esmtpsa (TLSv1.2:DHE-RSA-AES128-SHA:128) (Exim 4.86_1) (envelope-from ) id 1bIIsa-001L8u-2k; Wed, 29 Jun 2016 18:02:24 +0100 In-Reply-To: (Stefan Monnier's message of "Wed, 29 Jun 2016 03:38:50 -0400") 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:110661 Archived-At: Stefan Monnier writes: >>>>> Well I would have thought that needing eval-after-load and relatives >>>>> is evidence of a badly written (in Stefan's sense) package >> Yeah, I missed the "not" in this paragraph. >>> I do think it's a problem, but admittedly, the way keymaps are normally >>> setup there's no standard&easy way for the package to "do the right >>> thing". >> But not evidence of a badly written package:-) > > Not until "the right thing to do" is designed and implemented, no. What about something like this below? We can now do something like: (extend-key 'fake-feature-map "\C-f" 'foward-char) It has the same syntax as define-key but works whether fake-feature-map has been defined or not. Could be macro'd to remove the quote, of course. Phil (defvar extend-key--pending-definitions nil "Key definitions to occur on load") (defun extend-key--define-now (keymap-symbol key def) "In KEYMAP-SYMBOL define KEY with definition DEF." (define-key (symbol-value keymap-symbol) key def)) (defun extend-key--define-later (keymap-symbol key def) "In KEYMAP-SYMBOL define KEY with definition DEF, once KEYMAP-SYMBOL has been defined." (setq extend-key--pending-definitions (cons (list keymap-symbol key def) extend-key--pending-definitions))) (defun extend-key--after-load-function (_) (setq extend-key--pending-definitions (seq-filter (lambda (n) (seq-let [keymap-symbol key def] n (when (extend-key--boundp keymap-symbol) (extend-key--define-now keymap-symbol key def)))) extend-key--pending-definitions))) (add-hook 'after-load-functions 'extend-key--after-load-function) (defun extend-key--boundp (keymap-symbol) (or (boundp keymap-symbol) (fboundp keymap-symbol))) (defun extend-key (keymap-symbol key def) "When KEYMAP-SYMBOL is defined, define key sequence KEY as DEF." (if (extend-key--boundp keymap-symbol) (extend-key--define-now keymap-symbol key def) (extend-key--define-later keymap-symbol key def)))