emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Re: Problem with agenda and diary


From: Nick Dokos
Subject: Re: [O] Re: Problem with agenda and diary
Date: Thu, 17 Mar 2011 18:01:18 -0400

Dan Griswold <address@hidden> wrote:


> Sure. But I don't want to include absolutely everything, because of
> personal calendar entries. Here it is, back to the point where it gets
> too specific to my life:
> 

That's of course as it should be.

> 
> Debugger entered--Lisp error: (args-out-of-range -1 0)
>   add-text-properties(0 -1 (org-heading t) "")
...
>   org-format-agenda-item("" "" "Diary" nil time)


The code in org-format-agenda-item is 

,----
|       ;; Set org-heading property on `txt' to mark the start of the
|       ;; heading.
|       (add-text-properties 0 (1- (length txt)) '(org-heading t) txt)
| 
`----

where txt is the second argument of org-format-agenda-item. As you can see
from your backtrace, that is the empty string, so the call to 
add-text-properties
ends up trying to give some property to an empty string: it does not like that.
So the problem is that that second argument is the empty string.

Now org-format-agenda-item is called from many places:

In org-agenda.el

- org-search-view
- org-get-entries-from-diary
- org-agenda-get-todos
- org-agenda-get-timestamps
- org-agenda-get-sexps
- org-agenda-get-progress
- org-agenda-get-deadlines
- org-agenda-get-scheduled
- org-agenda-get-blocks
- org-agenda-add-time-grid-maybe
- org-agenda-change-all-lines
- org-agenda-add-entry-to-org-agenda-diary-file

In org.el

- org-scan-tags

Of these, org-get-entries-from-diary and
org-agenda-add-entry-to-org-agenda-diary-file sound like the plausible
candidates, but since I don't have the rest of the backtrace, I cannot
tell for sure. Can you check whether one or the other (or both) occurs
further down in your backtrace and let us know? If neither appears, can
you check whether one of the others does?

Proceeding on the *assumption* that it is org-get-entries-from-diary,
the call chain is

    org-agenda-list --> org-get-entries-from-diary --> org-format-agenda-item 
--> boom

The code in org-get-entries-from-diary that calls org-format-agenda-item looks 
like this:
  ...
  (when entries
      (setq entries (org-split-string entries "\n"))
      (setq entries
            (mapcar
             (lambda (x)
               (setq x (org-format-agenda-item "" x "Diary" nil 'time))
               ;; Extend the text properties to the beginning of the line
               (org-add-props x (text-properties-at (1- (length x)) x)
                 'type "diary" 'date date 'face 'org-agenda-diary))
             entries)))

and the entries come from your diary, so that's the end of the road for us.

What I would suggest you do depends on a number of factors: whether you
use git to manage your org sources, how conversant you are with elisp
and the debugger and how much time you want to spend on it.

At the most basic level, I would first take a jaundiced look at the
diary file: see if there is anything that looks strange, like an empty
entry. Then I would bisect my way through it: copy the diary file to a
backup. Then start editing the original by whacking half of it away at
each stage, and seeing whether you still have the problem: if you do,
continue on this half; if you don't, continue on the other half - until
you are down to a single entry.  Then copy your backup back to the
original, delete the suspect entry and try again.

Alternatively, if you want to get your hands dirty with some debugging,
you can try changing the code above as follows:

  ...
  (when entries
      (setq entries (org-split-string entries "\n"))
      (debug)
      (setq entries
            (mapcar
             (lambda (x)
               (setq x (org-format-agenda-item "" x "Diary" nil 'time))
               ;; Extend the text properties to the beginning of the line
               (org-add-props x (text-properties-at (1- (length x)) x)
                 'type "diary" 'date date 'face 'org-agenda-diary))
             entries)))

adding a call to debug: when it reaches that point, emacs will drop you
into the debugger and you can examine the variable `entries' with

     e entries <RET>

The result will be shown in the minibuffer which may not be large enough
for everything, in which case switch to the *Messages* buffer which will
have everything. Look for an empty entry and check its neighbors. I haven't
looked at the code that reads the stuff from the diary, but chances are that
the empty entry's neighbors will be its neighbors in the diary file as well.
That should give you a good indication of what entry is at fault.

If you use git, you can create a temporary branch and make your changes there,
experiment and then switch back to master and delete the temporary branch.
If you don't use git, save org-agenda.el in a backup file, do the experiment
and restore it afterwards. In either case, it's probably best to restart your
emacs and possibly use a minimal .emacs file to get only the behavior you need
to test.

Good luck! And let us know how you fare.

Nick



reply via email to

[Prev in Thread] Current Thread [Next in Thread]