I know this solution is posted, but I cannot find it. I had in my .emacs code to kill suggestions buffers automatically after n seconds (mine was set to 5). This allowed me to not have to switch to that pane and kill it or have 90 auto-complete or suggestions buffers open. I can no longer find the code though. Does anybody know how to do this?
Thanks
Try Midnight Mode, included with recent versions of Emacs.
(run-with-idle-timer SECS REPEAT 'x-function)
Perform an action the next time Emacs is idle for SECS seconds.
The action is to call FUNCTION with arguments ARGS.
SECS may be an integer, a floating point number, or the internal
time format returned by, e.g., `current-idle-time'.
If Emacs is currently idle, and has been idle for N seconds (N < SECS),
then it will call FUNCTION in SECS - N seconds from now.
If REPEAT is non-nil, do the action each time Emacs has been idle for
exactly SECS seconds (that is, only once for each time Emacs becomes idle).
You define a function x-function that kills buffers you want.
Related
I'm trying to automate the creation of an ical file (the one I get after C-c C-e c a) every 30 minutes, to visualize it in a calendar app. Ideally, it should be done asynchronously to asynchronously. I tried adding this to my .emacs file
(run-with-timer 0 (* 30 60) 'org-icalendar-export-agenda-files async)
but it didn't work (as you can see, I have no idea of elisp).
Can someone help me with this?
I'm trying to get the content of current selected region in buffer. I'm aware of idle timer, but a hook should be more efficient/cleaner...
Not sure what you mean by "region change". If you mean "the text in the region is modified", then you'll need to use after-change-functions. If you mean that the selected text is modified by changing its bounds, then you'll probably want post-command-hook or maybe an idle timer (which is not less efficient than a hook, the main difference is that you get less guarantees about when it gets run; e.g. it won't be run between two commands if there's no idle time between the two, as is the case when running a keyboard macro).
A way to go seems to advice handle-shift-selection. AFAICT this function is called with every region-change by keyboard. Resp. advice mouse-drag-region.
I usually encounter situation when I enter minibuffer command such as open file or change buffer and instead of completing it in a minibuffer, I start doing something else, usually editing the buffer. I would like that minibuffer simply forget the command if it was not completed after some period of inactivity in a minibuffer. Is it possible?
If it would be possible to make the minibuffer simply flush itself after losing focus it would be great too. Now frequently I get the queue of minibuffer commands waiting for me and it is annoying as hell, since when I C-g them, emacs changes the buffers in the frames.
I wouldn't really advise doing anything of the sort, but would suggest instead that you provide a visual clue to yourself when the minibuffer is active. But since you asked for it...
You can put a function to exit the minibuffer on a suitable hook or in a timer. The function could check the value of (active-minibuffer-window) and call, say, (top-level) to return to the top level whenever it is nil. (Function abort-recursive-edit will exit the current minibuffer, but that can return to a parent (shallower) minibuffer, not necessarily `top-level'.
What hook or timer to use? You could use `post-command-hook', which is run after each command (e.g., each key press). That is perhaps overkill, but it won't miss a chance. There is perhaps another, more pertinent hook; dunno.
You could use an idle timer, which kicks in only after Emacs has been idle for a specified time. Or you could use a regular timer, just checking periodically. A timer could be started on minibuffer-setup-hook and then canceled on minibuffer-exit-hook.
I'm using an emacs-lisp script that has a minor bug which causes it to sometimes choke with an error message, and then execution proceeds without problem. The error itself does not bother me, what annoys me is that Emacs remains 10-15 seconds blocked after that and I must wait for what I believe to be some timer (designed to ensure I see the error message before it disappears) to end before I can resume my editing.
Is there a simple way to reduce this delay? I couldn't find where this timer is defined in order to change its value.
Some additional information:
I'm using Emacs 23.2, but I tried recompiling and using 23.4, it didn't change anything;
I tried Emacs 24.1 and the error disappeared, but I had a huge performance impact (the script has been designed for Emacs 23.2), so the "wait for error" is still a better option than using 24.1;
The script in question will be updated by its author sometime in the future, but I'm looking for a quick and dirty solution meanwhile.
The error message is: "error in process filter: Attempt to delete minibuffer or sole ordinary window".
as already said, it's a bug. Please report it to the maintainer.
Beside you may look into the code for a form like
(accept-process-output &optional PROCESS SECONDS
MILLISEC JUST-THIS-ONE)
Allow any pending output from subprocesses to be read by Emacs.
It is read into the process' buffers or given to their filter functions.
Non-nil arg PROCESS means do not return until some output has been received
from PROCESS.
Non-nil second arg SECONDS and third arg MILLISEC are number of seconds
and milliseconds to wait;
;;;
Is there a way to periodically run an elisp function in a long-running emacs, similar to cron, but within the emacs process?
For example I want to "automatically run (recentf-save-list) every half hour" because it otherwise only runs on exit, which sucks when emacs occasionally crashes. (There are other examples as well so looking for a general solution rather than one in particular for recentf).
Check out run-with-timer.
(run-with-timer 0 (* 30 60) 'recentf-save-list)
You might also find midnight mode useful. One can arbitrarily define 'midnight' and then add hooks as desired.