gnu-emacs-sources
[Top][All Lists]
Advanced

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

`diary-make-entry': insert new entries in order rather than at end


From: Joe Corneli
Subject: `diary-make-entry': insert new entries in order rather than at end
Date: Tue, 20 Aug 2013 10:54:38 -0700 (PDT)
User-agent: G2/1.0

(defun diary-date-to-time (string)
  (apply #'encode-time (map 'list (lambda (x) (if (null x) 0 x))  
                            (parse-time-string string))))

(defun diary-make-entry (string &optional nonmarking file)
  "Insert a diary entry STRING which may be NONMARKING in FILE.
If omitted, NONMARKING defaults to nil and FILE defaults to
`diary-file'."
  (let ((pop-up-frames (or pop-up-frames
                           (window-dedicated-p (selected-window)))))
    (find-file-other-window (or file diary-file)))
  (when (eq major-mode (default-value 'major-mode)) (diary-mode))
  (widen)
  (diary-unhide-everything)
  (let ((new-date (diary-date-to-time string))
        time
        insert-at-end)
    (goto-char (point-min))
    ;; Need some special care if we're inserting into the last line;
    ;; the first relevant issue is to find out when that is the case.
    (while (and (if (re-search-forward "^[^# ].*" nil t)
                    t
                  (setq insert-at-end t)
                  nil)
                (time-less-p (diary-date-to-time (match-string 0))
                                        new-date)))
    (unless insert-at-end
      (goto-char (line-beginning-position))
      (backward-char 1)))
  (insert
   (if (bolp) "" "\n")
   (if nonmarking diary-nonmarking-symbol "")
   string " "))


reply via email to

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