all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* use-package: load package on key prefix
@ 2016-05-07 21:04 Joe Riel
  2016-05-09  0:36 ` Emanuel Berg
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Joe Riel @ 2016-05-07 21:04 UTC (permalink / raw
  To: Help GNU Emacs

I use the p4 (perforce) package which uses C-x p as a prefix for its
bound keys.  Can use-package be configured so that it loads the
package (which presumably assigns the key-bindings) when C-x p is pressed?

-- 
Joe Riel




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: use-package: load package on key prefix
  2016-05-07 21:04 use-package: load package on key prefix Joe Riel
@ 2016-05-09  0:36 ` Emanuel Berg
  2016-05-09 12:28 ` Stefan Monnier
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Emanuel Berg @ 2016-05-09  0:36 UTC (permalink / raw
  To: help-gnu-emacs

Joe Riel <joer@san.rr.com> writes:

> I use the p4 (perforce) package which uses C-x p as
> a prefix for its bound keys. Can use-package be
> configured so that it loads the package (which
> presumably assigns the key-bindings) when C-x
> p is pressed?

It can, but unless you load the package somehow else,
the keybinding won't be in effect and if you load it
somehow else, there is no reason for such
a keybinding, is it, as the package is already loaded?

And - why do you want a keyboard shortcut to load
a package anyway? Shortcuts are there to "optimize the
common case", to quote the paleo-sacred scrolls of
techno-techno-science. In this "case" that means you
are benefited from assigning commands to shortcuts,
which are invoked repeatedly and/or frequently!

Perhaps you can describe your situation in human
terms instead?

E.g., do you "refresh" some state associated with the
package by reloading the entire package? If so, in
nine times out of ten, there are better ways to do
that. Take your time to examine the situation and
analyze what part needs to be reset (or set). You are
not on K2 so there is no need to muscle up the
thrice-accursed tent!

But if you still want it, to answer your question, as
you describe the circularity, no, instead you would
want to put the load shortcut in the global keymap:

    (defun load-gnus ()
      "Load probably the best piece of software in the world.
    (But we will have to verify that.)"
      (interactive)
      (load "gnus") )

    (global-set-key "\C-xp" #'load-gnus)

-- 
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
                   - so far: 26 Blogomatic articles -                   




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: use-package: load package on key prefix
  2016-05-07 21:04 use-package: load package on key prefix Joe Riel
  2016-05-09  0:36 ` Emanuel Berg
@ 2016-05-09 12:28 ` Stefan Monnier
  2016-05-09 14:26   ` Marcin Borkowski
  2016-05-10 19:00   ` Joe Riel
       [not found] ` <mailman.2487.1462797966.7477.help-gnu-emacs@gnu.org>
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 9+ messages in thread
From: Stefan Monnier @ 2016-05-09 12:28 UTC (permalink / raw
  To: help-gnu-emacs

> I use the p4 (perforce) package which uses C-x p as a prefix for its
> bound keys.  Can use-package be configured so that it loads the
> package (which presumably assigns the key-bindings) when C-x p is pressed?

I don't know if use-package supports it, but Emacs can definitely do
that (it's called "autoloaded keymaps"), and if it makes sense for
p4.el, than I'd argue that you should report a bug against p4.el saying
that p4.el should do that (rather than dump that responsability on the user).

This said, this feature of Emacs is mostly never used: when a package
has a dedicated prefix key, it typically also has a menu-bar (sub)menu
and that one can't be autoloaded (well, technically it can be
autoloaded, but in practice the automatic load will happen much too
early, i.e. the first time you look at any part of the menu).


        Stefan




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: use-package: load package on key prefix
       [not found] ` <mailman.2487.1462797966.7477.help-gnu-emacs@gnu.org>
@ 2016-05-09 12:53   ` Rusi
  0 siblings, 0 replies; 9+ messages in thread
From: Rusi @ 2016-05-09 12:53 UTC (permalink / raw
  To: help-gnu-emacs

On Monday, May 9, 2016 at 6:16:08 PM UTC+5:30, Stefan Monnier wrote:
> > I use the p4 (perforce) package which uses C-x p as a prefix for its
> > bound keys.  Can use-package be configured so that it loads the
> > package (which presumably assigns the key-bindings) when C-x p is pressed?
> 
> I don't know if use-package supports it, but Emacs can definitely do
> that (it's called "autoloaded keymaps"), and if it makes sense for
> p4.el, than I'd argue that you should report a bug against p4.el saying
> that p4.el should do that (rather than dump that responsability on the user).

Joel did say he *uses* p4. So he is the user!


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: use-package: load package on key prefix
       [not found] <mailman.2408.1462655105.7477.help-gnu-emacs@gnu.org>
@ 2016-05-09 13:03 ` Rusi
  0 siblings, 0 replies; 9+ messages in thread
From: Rusi @ 2016-05-09 13:03 UTC (permalink / raw
  To: help-gnu-emacs

On Sunday, May 8, 2016 at 2:35:08 AM UTC+5:30, Joe Riel wrote:
> I use the p4 (perforce) package which uses C-x p as a prefix for its
> bound keys.  Can use-package be configured so that it loads the
> package (which presumably assigns the key-bindings) when C-x p is pressed?

I do see this para in use-package readme:


Binding to keymaps
-----------------

Normally :bind expects that commands are functions that will be autoloaded from
the given package. However, this does not work if one of those commands is 
actually a keymap, since keymaps are not functions, and cannot be autoloaded 
using Emacs' autoload mechanism.

To handle this case, use-package offers a special, limited variant of :bind 
called :bind-keymap. The only difference is that the "commands" bound to by 
:bind-keymap must be keymaps defined in the package, rather than command 
functions. This is handled behind the scenes by generating custom code that 
loads the package containing the keymap, and then re-executes your keypress 
after the first load, to reinterpret that keypress as a prefix key.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: use-package: load package on key prefix
  2016-05-09 12:28 ` Stefan Monnier
@ 2016-05-09 14:26   ` Marcin Borkowski
  2016-05-10 19:00   ` Joe Riel
  1 sibling, 0 replies; 9+ messages in thread
From: Marcin Borkowski @ 2016-05-09 14:26 UTC (permalink / raw
  To: Stefan Monnier; +Cc: help-gnu-emacs


On 2016-05-09, at 14:28, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

>> I use the p4 (perforce) package which uses C-x p as a prefix for its
>> bound keys.  Can use-package be configured so that it loads the
>> package (which presumably assigns the key-bindings) when C-x p is pressed?
>
> I don't know if use-package supports it, but Emacs can definitely do
> that (it's called "autoloaded keymaps"), and if it makes sense for
> p4.el, than I'd argue that you should report a bug against p4.el saying
> that p4.el should do that (rather than dump that responsability on the user).

Interesting, I didn't know about autoloaded keymaps, thanks!

> This said, this feature of Emacs is mostly never used: when a package
> has a dedicated prefix key, it typically also has a menu-bar (sub)menu
> and that one can't be autoloaded (well, technically it can be
> autoloaded, but in practice the automatic load will happen much too
> early, i.e. the first time you look at any part of the menu).

Not necessarily "much too early": I practically _never_ look at _any_
part of the menu;-).

>         Stefan

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: use-package: load package on key prefix
  2016-05-07 21:04 use-package: load package on key prefix Joe Riel
                   ` (2 preceding siblings ...)
       [not found] ` <mailman.2487.1462797966.7477.help-gnu-emacs@gnu.org>
@ 2016-05-10  9:26 ` Phillip Lord
       [not found] ` <mailman.2627.1462964398.7477.help-gnu-emacs@gnu.org>
  4 siblings, 0 replies; 9+ messages in thread
From: Phillip Lord @ 2016-05-10  9:26 UTC (permalink / raw
  To: Joe Riel; +Cc: Help GNU Emacs

Joe Riel <joer@san.rr.com> writes:

> I use the p4 (perforce) package which uses C-x p as a prefix for its
> bound keys.  Can use-package be configured so that it loads the
> package (which presumably assigns the key-bindings) when C-x p is pressed?

You could bind C-x p to a command that loads p4 when pressed, and then
unbinds itself.

Something like this (untested!)...

(use-package p4
  :defer t
  :ensure t
  :bind ("C-x p" . my-p4-load))

(defun my-p4-load()
   (require 'p4)
   (unbind-keys "C-x p"))





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: use-package: load package on key prefix
  2016-05-09 12:28 ` Stefan Monnier
  2016-05-09 14:26   ` Marcin Borkowski
@ 2016-05-10 19:00   ` Joe Riel
  1 sibling, 0 replies; 9+ messages in thread
From: Joe Riel @ 2016-05-10 19:00 UTC (permalink / raw
  To: Stefan Monnier; +Cc: help-gnu-emacs

On Mon, 09 May 2016 08:28:41 -0400
Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> > I use the p4 (perforce) package which uses C-x p as a prefix for its
> > bound keys.  Can use-package be configured so that it loads the
> > package (which presumably assigns the key-bindings) when C-x p is pressed?
> 
> I don't know if use-package supports it, but Emacs can definitely do
> that (it's called "autoloaded keymaps"), and if it makes sense for
> p4.el, than I'd argue that you should report a bug against p4.el saying
> that p4.el should do that (rather than dump that responsability on the user).
> 
> This said, this feature of Emacs is mostly never used: when a package
> has a dedicated prefix key, it typically also has a menu-bar (sub)menu
> and that one can't be autoloaded (well, technically it can be
> autoloaded, but in practice the automatic load will happen much too
> early, i.e. the first time you look at any part of the menu).

Thanks, that pointed me in the right direction.
The following :bind-keymap assignment solved the problem:

(use-package p4
  :bind-keymap (("C-x p" . p4-prefix-map))
  :config
  (setq p4-use-p4config-exclusively t
	p4-do-find-file nil ))

Now typing, say, "C-x p f" load the p4 minor mode 
and runs p4-mode-filelog, exactly what I wanted.

I don't use a menu, so don't worry about a menu-bar issue.


-- 
Joe Riel




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: use-package: load package on key prefix
       [not found] ` <mailman.2627.1462964398.7477.help-gnu-emacs@gnu.org>
@ 2016-05-11 11:04   ` Rusi
  0 siblings, 0 replies; 9+ messages in thread
From: Rusi @ 2016-05-11 11:04 UTC (permalink / raw
  To: help-gnu-emacs

On Wednesday, May 11, 2016 at 4:30:00 PM UTC+5:30, Phil Lord wrote:
> Joe Riel  writes:
> 
> > I use the p4 (perforce) package which uses C-x p as a prefix for its
> > bound keys.  Can use-package be configured so that it loads the
> > package (which presumably assigns the key-bindings) when C-x p is pressed?
> 
> You could bind C-x p to a command that loads p4 when pressed, and then
> unbinds itself.
> 
> Something like this (untested!)...
> 
> (use-package p4
>   :defer t
>   :ensure t
>   :bind ("C-x p" . my-p4-load))
> 
> (defun my-p4-load()
>    (require 'p4)
>    (unbind-keys "C-x p"))

Why all that when OP finds that following works?

(use-package p4
  :bind-keymap (("C-x p" . p4-prefix-map))
  :config
  (setq p4-use-p4config-exclusively t
        p4-do-find-file nil )
;; and whatever else config is desired
)



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-05-11 11:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-07 21:04 use-package: load package on key prefix Joe Riel
2016-05-09  0:36 ` Emanuel Berg
2016-05-09 12:28 ` Stefan Monnier
2016-05-09 14:26   ` Marcin Borkowski
2016-05-10 19:00   ` Joe Riel
     [not found] ` <mailman.2487.1462797966.7477.help-gnu-emacs@gnu.org>
2016-05-09 12:53   ` Rusi
2016-05-10  9:26 ` Phillip Lord
     [not found] ` <mailman.2627.1462964398.7477.help-gnu-emacs@gnu.org>
2016-05-11 11:04   ` Rusi
     [not found] <mailman.2408.1462655105.7477.help-gnu-emacs@gnu.org>
2016-05-09 13:03 ` Rusi

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.