8

Is it possible to execute a function or command at a specific time? As an explicit example, is it possible to kill emacs at a specific time (time determined by the OS).

  • 1
    See also midnight-mode – nanny Jan 5 '15 at 14:00
  • I see someone is taking hard measure to prevent emacs addiction :) – biocyberman Apr 22 '16 at 14:17
12

You want to use the function run-at-time, described in Chapter 38.10 of the Emacs Lisp manual. In your case, something like this should do the trick:

(run-at-time "20:30" nil #'kill-emacs)

If the function you want to call takes parameters, you can specify them as additional parameters to run-at-time:

(run-at-time "5 sec" nil #'message "Tempus volat, hora fugit.")

Note that absolute times are taken to be today, even if they are in the past, so the first example above will exit immediately if it is after 20:30.

  • 1
    I put your code it in my .emacs file. It kills emacs at the given time! But when I restart emacs, it is immediately killed. Any hint? – Name Jan 4 '15 at 23:11
  • 1
    @Name edited to clarify. – jch Jan 4 '15 at 23:24
  • LOL, you can start with the -q switch to bypass the init file that'll be toasting your emacs until midnight. Then the glass slipper falls and you can edit again until that same time tomorrow. – devon Apr 29 at 15:26

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.