3

I would like to assing the function org-timer-start with a univeral argument (Ctrl-u) to its own key.

I read here, that one should look into the source code of a function to find out how to pass a universal argument.

Where is this part in the following function, that tells me about the universal argument call?

    (defun org-timer-start (&optional offset)
      "Set the starting time for the relative timer to now.
    When called with prefix argument OFFSET, prompt the user for an offset time,
    with the default taken from a timer stamp at point, if any.
    If OFFSET is a string or an integer, it is directly taken to be the offset
    without user interaction.
    When called with a double prefix arg, all timer strings in the active
    region will be shifted by a specific amount.  You will be prompted for
    the amount, with the default to make the first timer string in
    the region 0:00:00."
      (interactive "P")
      (cond
       ((equal offset '(16))
        (call-interactively 'org-timer-change-times-in-region))
       (org-timer-countdown-timer
        (user-error "Countdown timer is running.  Cancel first"))
       (t
        (let (delta def s)
          (if (not offset)
          (setq org-timer-start-time (current-time))
        (cond
         ((integerp offset) (setq delta offset))
         ((stringp offset) (setq delta (org-timer-hms-to-secs offset)))
         (t
          (setq def (if (org-in-regexp org-timer-re)
                (match-string 0)
                  "0:00:00")
            s (read-string
               (format "Restart timer with offset [%s]: " def)))
          (unless (string-match "\\S-" s) (setq s def))
          (setq delta (org-timer-hms-to-secs (org-timer-fix-incomplete s)))))
        (setq org-timer-start-time (org-time-since delta)))
          (setq org-timer-pause-time nil)
          (org-timer-set-mode-line 'on)
          (message "Timer start time set to %s, current value is %s"
               (format-time-string "%T" org-timer-start-time)
               (org-timer-secs-to-hms (or delta 0)))
          (run-hooks 'org-timer-start-hook)))))

Do I need to make a custom fuction to call org-timer-start with a Ctrl-u prefix?

  • 2
  • I wasn't going to take the time to look for the duplicate, but a quick search of [prefix-argument] found it. – Drew Jun 22 at 14:41
  • It's hard to tell if yes or no with my little experience, but I tend to no, because it does not anser Where is this part in the following function, that tells me about the universal argument call? and I think it does not anser Do I need to make a custom fuction to call org-timer-start with a Ctrl-u prefix?. But honestly I don't really understand enough to assert. – breathe_in_breathe_out Jun 22 at 17:33
5

The part you need to look at is the interactive declaration which in this case is (interactive "P"). This means that C-u is passing the argument (4) to org-timer-start. So you need to assign the lambda

(lambda ()
  (interactive)
  (org-timer-start '(4)))

to a key in whatever keymap you want that will be active when you want to use it. The keymap you should probably choose is the one where org-timer-start is bound. You also need to make this binding after the keymap has been defined as a variable.

It seems that org-timer-start is not bound to any key by default and that the function is loaded when org-mode is loaded so it would be sensible to bind this lambda in org-mode-map as part of your customisation of org-mode.

| improve this answer | |
  • Does this mean I would use something like (define-key org-mode-map (kbd "C-c N") (lambda () (interactive)(org-timer-start '(4))) ? – breathe_in_breathe_out Jun 22 at 17:45
  • Yes, that should work – Aidan Schofield Jun 22 at 18:13
  • To define it as a new function I used (defun org-timer-start-with-offset () "Start the timer and prompt user to enter a time offset" (interactive) (org-timer-start '(4))) – breathe_in_breathe_out Jun 22 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.