Re: [STUMP] define run-or-raise keybinding with anonymous function

Joram Schrijver <[email protected]>
Newsgroups gmane.comp.window-managers.stumpwm.devel
Message-ID <1448820218.3007899.452796009.1949B1D6@webmail.messagingengine.com>
Hi,

Note that StumpWM supplies a macro called DEFPROGRAM-SHORTCUT that
handles
creating a run-or-raise command and binding it to a key. It won't be an
anonymous command, because such a thing doesn't exist, but there's no
real harm
in having a command like "calibre" or "iceweasel".

-- 
  Joram

On Sat, Nov 28, 2015, at 07:25 PM, Tamas Papp wrote:
> I found a workaround:
> 
> (define-key *root-map* (kbd "c")
>   "eval-line (run-or-raise \"calibre\" '(:title \"calibre\"))")
> 
> I can of course write a macro for all of this:
> 
> (defmacro define-key-run-or-raise (map key command
>                                    &optional (props `(:title ,command)))
>   `(define-key ,map (kbd ,key)
>      ,(with-output-to-string (str)
>         (princ "eval-line " str)
>         (write `(run-or-raise ,command ',props) :stream str))))
> 
> and apply it as
> 
> (define-key-run-or-raise *root-map* "c" "calibre")
> (define-key-run-or-raise *root-map* "b" "iceweasel" (:title "Iceweasel"))
> 
> but this is as unlispy as it gets so please help me find a more elegant
> and idiomatic solution if there is one.
> 
> Best,
> 
> Tamas
> 
> 
> On Sat, Nov 28 2015, Tamas Papp <[email protected]> wrote:
> 
> > Hi,
> >
> > I am new to stumpwm and find it amazing, but I need to wrap my head
> > around a few things.
> >
> > One of them is "commands", in particular, I am looking for an equivalent
> > of (lambda ...) when I don't want to name a command that I would just
> > use once. Eg instead of
> >
> > (defcommand ensure-calibre () ()
> >   "raise calibre if there is a running instance, otherwise start it"
> >   (run-or-raise "calibre" '(:title "calibre")))
> > (define-key *root-map* (kbd "c") "ensure-calibre")
> >
> > I am looking for something like
> >
> > (define-key *root-map* (kbd "c")
> >             (lambda ()
> >               (run-or-raise "calibre" '(:title "calibre"))))
> >
> > which of course does not work. Is there a way around this?
> >
> > Thanks,
> >
> > Tamas
> 
> _______________________________________________
> Stumpwm-devel mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.