* Calling function as if it had a C-u prefix
@ 2015-02-27 21:24 Tory S. Anderson
2015-02-27 21:34 ` Drew Adams
0 siblings, 1 reply; 6+ messages in thread
From: Tory S. Anderson @ 2015-02-27 21:24 UTC (permalink / raw)
To: Emacs Help List
I'm playing around with hydra and am trying to bind a key to do the equivalent of `C-u org-clock-in`. I've tried following a related question on SO[1] but it doesn't seem to be working. Can anyone tell me where I'm off?
--8<---------------cut here---------------start------------->8---
(global-set-key
(kbd "C-c o")
(defhydra hydra-org-time-management (:color blue)
"Org"
("w" (let ((current-prefix-arg 4)) (org-clock-in)) "clock-in")))
--8<---------------cut here---------------end--------------->8---
Footnotes:
[1] http://stackoverflow.com/questions/12827887/emacs-universal-argument-c-u-in-a-function
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: Calling function as if it had a C-u prefix
2015-02-27 21:24 Calling function as if it had a C-u prefix Tory S. Anderson
@ 2015-02-27 21:34 ` Drew Adams
2015-02-27 21:44 ` Michael Heerdegen
0 siblings, 1 reply; 6+ messages in thread
From: Drew Adams @ 2015-02-27 21:34 UTC (permalink / raw)
To: torys.anderson, Emacs Help List
> I'm playing around with hydra and am trying to bind a key to do the
> equivalent of `C-u org-clock-in`. I've tried following a related question on
> SO[1] but it doesn't seem to be working. Can anyone tell me where I'm off?
Call `org-clock-in' passing it an explicit argument that corresponds to
the prefix arg value. (I don't have the function info, but if you do
`C-h f' you should see what the signature is.)
Sometimes a function does not pass the prefix arg as a parameter, but
typically functions do, and the advice above should be sufficient.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Calling function as if it had a C-u prefix
2015-02-27 21:34 ` Drew Adams
@ 2015-02-27 21:44 ` Michael Heerdegen
2015-02-27 21:54 ` Tory S. Anderson
0 siblings, 1 reply; 6+ messages in thread
From: Michael Heerdegen @ 2015-02-27 21:44 UTC (permalink / raw)
To: help-gnu-emacs
Drew Adams <drew.adams@oracle.com> writes:
> Sometimes a function does not pass the prefix arg as a parameter, but
> typically functions do, and the advice above should be sufficient.
Should work. `org-clock-in' uses (interactive "P"), so
(org-clock-in '(4))
should do it.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Calling function as if it had a C-u prefix
2015-02-27 21:44 ` Michael Heerdegen
@ 2015-02-27 21:54 ` Tory S. Anderson
2015-02-27 22:09 ` Michael Heerdegen
0 siblings, 1 reply; 6+ messages in thread
From: Tory S. Anderson @ 2015-02-27 21:54 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
Ah, that did it! I had already tried both
(org-clock-in t)
and
(org-clock-in 4)
And they didn't do the trick. For whatever reason, the quote and the parentheses did the trick. Thanks!
Michael Heerdegen <michael_heerdegen@web.de> writes:
> Drew Adams <drew.adams@oracle.com> writes:
>
>> Sometimes a function does not pass the prefix arg as a parameter, but
>> typically functions do, and the advice above should be sufficient.
>
> Should work. `org-clock-in' uses (interactive "P"), so
>
> (org-clock-in '(4))
>
> should do it.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Calling function as if it had a C-u prefix
2015-02-27 21:54 ` Tory S. Anderson
@ 2015-02-27 22:09 ` Michael Heerdegen
0 siblings, 0 replies; 6+ messages in thread
From: Michael Heerdegen @ 2015-02-27 22:09 UTC (permalink / raw)
To: Tory S. Anderson; +Cc: help-gnu-emacs
torys.anderson@gmail.com (Tory S. Anderson) writes:
> For whatever reason, the quote and the
> parentheses did the trick. Thanks!
See (info "(elisp) Prefix Command Arguments").
One has to look at the interactive spec of the defun in the source to
see whether a numeric or raw prefix arg is used and expected in the
body.
When `org-clock-in' had used (interactive "p") instead, your version
(org-clock-in 4)
would have worked. But the function wants to treat a C-u prefix
specially, so it uses "P".
^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <mailman.961.1425072293.31049.help-gnu-emacs@gnu.org>]
* Re: Calling function as if it had a C-u prefix
[not found] <mailman.961.1425072293.31049.help-gnu-emacs@gnu.org>
@ 2015-02-27 21:51 ` Emanuel Berg
0 siblings, 0 replies; 6+ messages in thread
From: Emanuel Berg @ 2015-02-27 21:51 UTC (permalink / raw)
To: help-gnu-emacs
torys.anderson@gmail.com (Tory S. Anderson) writes:
> I'm playing around with hydra and am trying to bind
> a key to do the equivalent of `C-u org-clock-in`.
> I've tried following a related question on SO[1] but
> it doesn't seem to be working. Can anyone tell me
> where I'm off?
I don't have hydra (?) or `org-clock-in' but usually
those functions have an optional argument. For
example, the docstring of `forward-char':
(forward-char &optional N)
In such a case, simply put an invocation with an
explicit argument in a wrapper (an interactive defun)
and bind that to the desired command (shortcut).
If you cannot use the optional argument try this:
(defun forward-fourteen ()
(interactive)
(let ((current-prefix-arg 14))
(call-interactively 'forward-char) ))
(forward-fourteen) ; evaluate me and see how far
(global-set-key "\C-x\M-o" 'forward-fourteen)
--
underground experts united
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-02-27 22:09 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-27 21:24 Calling function as if it had a C-u prefix Tory S. Anderson
2015-02-27 21:34 ` Drew Adams
2015-02-27 21:44 ` Michael Heerdegen
2015-02-27 21:54 ` Tory S. Anderson
2015-02-27 22:09 ` Michael Heerdegen
[not found] <mailman.961.1425072293.31049.help-gnu-emacs@gnu.org>
2015-02-27 21:51 ` Emanuel Berg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).