title: Custom diary-sunrise function not working. `autoload-diary`? (Emacs.)
body: <h2>Intro:</h2>
  
  <p>Based on the existing code for Emacs' <code>diary-sunrise-sunset</code>, I attempted to create two new functions <code>diary-sunrise</code> and <code>diary-sunset</code>. </p>
  
  <p>My reasons for this are included below under the heading "XY-description". </p>
  
  <p>I have code below which seems to work, except when I restart with a new Emacs. I can fix this by momentarily using the original built-in <code>diary-sunrise-sunset</code>. From then on, my functions perform beautifully. </p>
  
  <p>In other words, I have to use the built-in <code>%%(diary-sunrise-sunset)</code> just a one time before my <code>%%(diary-sunrise)</code> and <code>%%(diary-sunset)</code> will work. </p>
  
  <h2>Question:</h2>
  
  <p>Can you help me fix my use of these functions so that I do not have to take the awkward step of first getting the built-in function called? </p>
  
  <p>The lines of code that seem suspicious to me are the ones that go </p>
  
  <pre><code>;;;###diary-autoload
  </code></pre>
  
  <p>While I have some idea of the necessity of loading programs, I am not sure what's going on here, or if this is where the issue lies. (I've never seen that particular syntax.) </p>
  
  <p>I have tried <code>M-: (require 'solar)</code> and <code>M-: (require 'diary)</code>, but neither have worked (and just now <code>calendar</code>). I have tried putting my code both in my <code>.emacs</code> and in the built-in <code>.../lisp/calendar/solar.el</code> (and byte-recompiling), but neither have worked. </p>
  
  <h2>My functions:</h2>
  
  <p>(They are each slight modifications of <code>solar-sunrise-sunset-string</code> and <code>diary-sunrise-sunset</code>, which are both defined in <code>.../lisp/calendar/solar.el</code>). </p>
  
  <p><strong>Sunrise:</strong></p>
  
  <pre><code>(defun solar-sunrise-string (date &amp;optional nolocation)
    "String of *local* time of sunrise and daylight on Gregorian DATE."
    (let ((l (solar-sunrise-sunset date)))
      (format
       "%s (%s hours daylight)"
       (if (car l)
       (concat "Sunset " (apply 'solar-time-string (car l)))
         "no sunset")
       (nth 2 l)
       )))
  ;; To be called from diary-list-sexp-entries, where DATE is bound.
  ;;;###diary-autoload
  (defun diary-sunrise ()
    "Local time of sunrise as a diary entry.
    Accurate to a few seconds."
    (or (and calendar-latitude calendar-longitude calendar-time-zone)
        (solar-setup))
    (solar-sunrise-string date))
  </code></pre>
  
  <p><strong>Sunset:</strong> </p>
  
  <pre><code>(defun solar-sunset-string (date &amp;optional nolocation)
    "String of *local* time of sunset and daylight on Gregorian DATE."
    (let ((l (solar-sunrise-sunset date)))
      (format
       "%s (%s hours daylight)"
       (if (cadr l)
       (concat "Sunset " (apply 'solar-time-string (cadr l)))
         "no sunset")
       (nth 2 l)
       )))
  ;; To be called from diary-list-sexp-entries, where DATE is bound.
  ;;;###diary-autoload
  (defun diary-sunset ()
    "Local time of sunset as a diary entry.
    Accurate to a few seconds."
    (or (and calendar-latitude calendar-longitude calendar-time-zone)
        (solar-setup))
    (solar-sunset-string date))
  </code></pre>
  
  <h2>XY description:</h2>
  
  <p>I am using Emacs' Org-mode, and just starting to use agenda views. I like the builtin <code>diary-sunrise-sunset</code> function, but wanted to make some minor tweaks to make it more to my liking. </p>
  
  <p>Basically, Org-mode's agenda view will extract the first time it sees from the diary sexp <code>%%(diary-sunrise-sunset)</code>, for instance </p>
  
  <pre><code>Sat, Apr 5, 2014
  Sunrise 6:43am (PDT), sunset 7:42pm (PDT) at Springfield, OH (12:59 hours daylight)
  </code></pre>
  
  <p>and thus make an entry of </p>
  
  <pre><code>6:43am........  Sunrise (PDT), sunset 7:42pm (PDT) at Springfield, OH (12:59 hours daylight)
  </code></pre>
  
  <p>in the agenda view. </p>
  
  <p>What I would like it to do is something more like, </p>
  
  <pre><code> 6:43am........  Sunrise (PDT) (12:59 hours daylight)
   8:00am........  ----------------
  10:00am........  ----------------
  12:00pm........  ----------------
   2:00pm........  ----------------
   4:00pm........  ----------------
   5:51pm........  now - - - - - - - - - - - - - - - - - - - - - - - - -
   6:00pm........  ----------------
   7:42pm........  Sunset (PDT) (12:59 hours daylight)
  </code></pre>
  
  <p>Where the data is split into the two times, rather than all written only at the sunrise time. </p>
  
  <h2>Bonus:</h2>
  
  <p>a snippet so that <code>C-c a d</code> will give you a nice day agenda view: </p>
  
  <pre><code>(setq org-agenda-custom-commands 
        '(("d" "day's agenda"
           agenda ""
           (
            (org-agenda-files '("/e/org/agendatest.org"))
            (org-agenda-prefix-format "%t %s")
            (org-agenda-span 'day)
            (org-agenda-timegrid-use-ampm t)
            )
           )
          ))
  </code></pre>