Hot answers tagged

15

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 ...


13

You can roll your own predicate function that waits for 3 seconds and invariably returns non-nil (unless it is interrupted with C-g): (setq confirm-kill-emacs (lambda (&rest args) (interactive) (message "Quitting in 3 seconds. Press `C-g' to stop.") (sleep-for 3) t)) or a variant which will read any key: (setq ...


8

One solution for that narrow case is to dynamically set save-silently for that invocation specific invocation. Try: (run-at-time nil (* 5 60) (lambda () (let ((save-silently t)) (recentf-save-list)))) You might alternatively use advice to globally accomplish the same thing. See Advising Functions in the Emacs ...


7

You can use sit-for instead of using sleep-for plus t. And the function need not be a command (interactive). sit-for returns t if it waited and nil if the user interrupted the wait. (setq confirm-kill-emacs (lambda (&rest _) (message "Quit in 3 sec (`C-g' or other action cancels)") (sit-for 3)))


6

Best method seems to be found in eldoc that also displays temporary info in minibuffer: ;; Decide whether now is a good time to display a message. (defun eldoc-display-message-p () (and (eldoc-display-message-no-interference-p) ;; If this-command is non-nil while running via an idle ;; timer, we're still in the middle of executing a command, ...


4

Yes - call run-at-time using the encode-time method to pass the time argument as mentioned in its doc string: (run-at-time TIME REPEAT FUNCTION &rest ARGS) Probably introduced at or before Emacs version 19.26. Perform an action at time TIME. Repeat the action every REPEAT seconds, if REPEAT is non-nil. REPEAT may be an integer or floating point ...


4

You need to keep the timer object in a global variable or closure. Take global variable for example: (defvar my/timer nil) (defun toggle-mytimer () (interactive) (if (not (timerp my/timer)) (setq my/timer (run-with-timer 5 5 'princ "Ciao")) (cancel-timer my/timer) (setq my/timer nil)))


3

I try not to use standard timers that repeat because they can affect performance while typing or scrolling. An idle-timer only fires once each time an idle occurs. Therefore, I would suggest setting up a system that runs an idle timer while Emacs has focus and a standard timer when Emacs loses focus. Since that is outside the scope of the question, I will ...


3

My personal opinion is that Emacs is not an operating system, and while it is often convenient to do things in Emacs, this is the kind of task that is better solved outside of Emacs. Scheduling your backups within Emacs means that they won't run if Emacs is not running, and that they might run twice if you have two instances of Emacs open. Since Emacs has ...


2

You can use run-at-time to run some code at a specific time. For example, to message "go home" every day at 5 pm: (setq go-home-timer (run-at-time "5:00pm" (* 24 60 60) (lambda () (message "go home!")))) You can stop it with: (cancel-timer go-home-timer) You can create a hook and set it up ...


2

Thanks to @lawlist for directing me to timer.el. A solution I implemented uses timer.el's run-at-time. I replaced the format-line-list item with: (if (< (length chronos--timers-list) 2) "" (cancel-function-timers 'force-mode-line-update) (run-at-time 0.5 nil '(lambda () (force-mode-line-update t))) (list " timer|" (propertize (my-timer-display)...


1

This can be handled by advising the code that handles source code block execution in Org Mode. The function in question is org-babel-execute-src-block - it runs a hook after it executes, but not before, so the advice feature is required - and probably preferred for this use. (defun gjg/time-call (time-call &rest args) (message "Ohai %s" ...


1

Here's some code that converts simple HH:MM time specifications to encoded times for either today or tomorrow, depending on whether the given time is later or earlier than the current time. There are three main functions: convert-hh:mm-to-decoded converts a simple time spec in HH:MM format (N.B. no AM/PM specification - use 24-hour time instead) into the ...


1

For y-or-n-p, you could check the value of input-method-use-echo-area. It is turned on by read-key-sequence, which is indirectly used by y-or-n-p – and quite likely by various other commands you'd like to treat the same way. Detecting an active read-event seems to be harder. Perhaps it's preferable to call it via a wrapper which rebinds some variable to let ...


1

I can't help with the pop up but, in place of that, I suggest that you use a bell sound. You should have a wav sound file for this and you could use a bell sound like org-pomodoro's. From C-h f org-timer-set-timer (org-timer-set-timer function help): With two ‘C-u’ prefix arguments, use ‘org-timer-default-timer’ without prompting the user for a ...


1

I implemented Drews comment. (Improvements are welcome) Here are 2 functions. One, which starts cycling buffers in current selected window my-cycle-buffers. And one, which stops cycling my-cycle-buffers-kill. You can both bind to a hotkey if you want. (defun my-cycle-buffers (seconds-delay) (interactive "p") (setq my-window (selected-window) ...


1

A quick look at the code shows this: blink-matching-open does not return a string - the return value is not the matching text. So message complains that its arg is not a string. blink-matching-open itself calls message to show the matching text, so you should be able to just remove your (when matching-text...).


Only top voted, non community-wiki answers of a minimum length are eligible