1

I am trying to rebuild my Org Agenda buffer with a timer. I am trying to do it like this:

(defun renewOrgBuffer ()
  (interactive)
  (dolist (buffer (buffer-list))
    (with-current-buffer buffer
      (when (derived-mode-p 'org-agenda-mode)
    (org-agenda-redo t))))
  )
(run-with-idle-timer 60 1000 #'renewOrgBuffer)

I basically swiped this from another answer but they wanted to do somehting when the org file saved. I want to update it with a timer and am running into errors.

When I just run the function in ielm I get the error: *** Eval error *** ‘recenter’ing a window that does not display current-buffer.

I am running Emacs 25.1.50.2 client connected to a daemon with org verion 8.2.10 on Ubuntu 15.10.

The purpose for this for me is that I like to have my org file with my todos and appointments up in one buffer and the Org Agenda buffer up next to it. So the the main purpose for me to update the Org Agenda buffer is just so that the line that says now - - - - - updates. It is a small think but I just want to figure it out.

Any help or pointers is appreciated.

Edit March 7

I have found that if you enable the sticky agenda view from the dispatcher (* option) then I can call my previously defined renewOrgBuffer function interactively with M-x and instead of getting an error, I get a message in the mini buffer that says "org-agenda-list: ‘recenter’ing a window that does not display current-buffer.", which is great, but I don't want to call it interactively every time.

When I try to run that function from the scratch buffer or on a timer like

(run-with-idle-timer 3 1000 #'renewOrgBuffer)

I get the error:

Rebuilding agenda buffer...done
Error running timer ‘renewOrgBuffer’: (error "‘recenter’ing a window that does not display current-buffer.")

Although it says "Rebuilding agenda buffer...done" it does not actually rebuild it.

Any help with this added information would be helpful, Thank you.

4
  • There are only a few recenter in org-mode -- grep them and comment them out, and re-byte-compile if necessary. Or, find the offending function that has the word (recenter and redefine it or use advice. You want to be able to operate on buffers that are not visible, and recenter is preventing you from further developing your new system. Later on, you can write-in some exceptions for when a window is visible, then recenter . . . I took care of that in my own setup a long time ago.
    – lawlist
    Commented Feb 26, 2016 at 7:31
  • @lawlist If I am using the orgmode version that came with emacs, where is the source? I can only find the compiled elisp files in /usr/local/share/emacs/25.1.50/lisp/org. Are you suggesting editing the source and recompiling it? Thanks
    – Jesse
    Commented Mar 7, 2016 at 17:53
  • You'll need to download the source-code of the version that you are using. Then you can word-search for recenter. You can either edit the source and re-byte-compile, or you can just create new functions with the same names for those that need modification. For example, if the function named foo contains a recenter command` and foo is located in the library named org-foo.el, then your .emacs can have something like: (require 'org-foo) (defun foo (however many arguments) [the modified guts less the recenter garbage])) and then restart Emacs or evaluate your .emacs file.
    – lawlist
    Commented Mar 7, 2016 at 21:32
  • @lawlist I did grep around the source and was commenting out different lines where recentering was being used but I also stumbled across org-agenda-maybe-redo, which calls org-agenda-redo but does some other things making it usable to me. Thanks for your input though!
    – Jesse
    Commented Mar 21, 2016 at 18:52

1 Answer 1

0

I found that using the function org-agenda-maybe-redo worked instead of org-agenda-redo. So my renew function now looks like this:

(defun renewOrgBuffer ()
  (interactive)
  (dolist (buffer (buffer-list))
    (with-current-buffer buffer
      (when (derived-mode-p 'org-agenda-mode)
    (org-agenda-maybe-redo))))
  )

and I made a timer to renew the agenda buffers:

(run-with-idle-timer 3 1000 #'renewOrgBuffer)

comparing org-agenda-redo and org-agenda-maybe-redo, it appears that maybe my issue was that I wasn't using the get-buffer-window function.

3
  • The last line of org-agenda-redo is (recenter window-line) -- so you could just rewrite that function to comment out the last line -- same procedure mentioned above: (require 'org-agenda) (defun org-agenda-redo (&optional all) . . . [everything but the last line of code relating to recentering]) You simply cannot call recenter on a buffer unless it is visible in a window, or else it will throw an error. You could also write in an exception to recenter only when the buffer window is visible.
    – lawlist
    Commented Mar 21, 2016 at 19:31
  • Yes I did see that. What I had done was copied the function into my scratch buffer and then I commented out that line and loaded it in with C-x C-e. I still had the issue, making me think that the recenter function was being called somewhere else as well.
    – Jesse
    Commented Mar 21, 2016 at 19:34
  • It's possible it came from somewhere else, but there are no more than 10 places in the latest version of org-mode that call recenter. It's not likely coming from any location other than org-mode.
    – lawlist
    Commented Mar 21, 2016 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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