Function: org-agenda-add-entry-to-org-agenda-diary-file

org-agenda-add-entry-to-org-agenda-diary-file is a byte-compiled function defined in org-agenda.el.gz.

Signature

(org-agenda-add-entry-to-org-agenda-diary-file TYPE TEXT &optional D1 D2)

Documentation

Add a diary entry with TYPE to org-agenda-diary-file.

If TEXT is not empty, it will become the headline of the new entry, and the resulting entry will not be shown. When TEXT is empty, switch to org-agenda-diary-file and let the user finish the entry there.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-agenda.el.gz
(defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  "Add a diary entry with TYPE to `org-agenda-diary-file'.
If TEXT is not empty, it will become the headline of the new entry, and
the resulting entry will not be shown.  When TEXT is empty, switch to
`org-agenda-diary-file' and let the user finish the entry there."
  (let ((cw (current-window-configuration)))
    (org-switch-to-buffer-other-window
     (find-file-noselect org-agenda-diary-file))
    (widen)
    (goto-char (point-min))
    (cl-case type
      (anniversary
       (or (re-search-forward "^\\*[ \t]+Anniversaries" nil t)
	   (progn
	     (or (org-at-heading-p)
		 (progn
		   (outline-next-heading)
		   (insert "* Anniversaries\n\n")
		   (beginning-of-line -1)))))
       (outline-next-heading)
       (org-back-over-empty-lines)
       (backward-char 1)
       (insert "\n")
       (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
		       (nth 2 d1) (car d1) (nth 1 d1) text)))
      (day
       (let ((org-prefix-has-time t)
	     (org-agenda-time-leading-zero t)
	     fmt time time2)
	 (when org-agenda-insert-diary-extract-time
	   ;; Use org-agenda-format-item to parse text for a time-range and
	   ;; remove it.  FIXME: This is a hack, we should refactor
	   ;; that function to make time extraction available separately
	   (setq fmt (org-agenda-format-item nil text nil nil nil t)
		 time (get-text-property 0 'time fmt)
		 time2 (if (> (length time) 0)
			   ;; split-string removes trailing ...... if
			   ;; no end time given.  First space
			   ;; separates time from date.
			   (concat " " (car (split-string time "\\.")))
			 nil)
		 text (get-text-property 0 'txt fmt)))
	 (if (eq org-agenda-insert-diary-strategy 'top-level)
	     (org-agenda-insert-diary-as-top-level text)
	   (require 'org-datetree)
	   (org-datetree-find-date-create d1)
	   (org-agenda-insert-diary-make-new-entry text))
	 (org-insert-time-stamp (org-time-from-absolute
				 (calendar-absolute-from-gregorian d1))
				nil nil nil nil time2))
       (end-of-line 0))
      ((block) ;; Wrap this in (strictly unnecessary) parens because
       ;; otherwise the indentation gets confused by the
       ;; special meaning of 'block
       (when (> (calendar-absolute-from-gregorian d1)
		(calendar-absolute-from-gregorian d2))
	 (setq d1 (prog1 d2 (setq d2 d1))))
       (if (eq org-agenda-insert-diary-strategy 'top-level)
	   (org-agenda-insert-diary-as-top-level text)
	 (require 'org-datetree)
	 (org-datetree-find-date-create d1)
	 (org-agenda-insert-diary-make-new-entry text))
       (org-insert-time-stamp (org-time-from-absolute
			       (calendar-absolute-from-gregorian d1)))
       (insert "--")
       (org-insert-time-stamp (org-time-from-absolute
			       (calendar-absolute-from-gregorian d2)))
       (end-of-line 0)))
    (if (string-match "\\S-" text)
	(progn
	  (set-window-configuration cw)
	  (message "%s entry added to %s"
		   (capitalize (symbol-name type))
		   (abbreviate-file-name org-agenda-diary-file)))
      (org-fold-reveal t)
      (message "Please finish entry here"))))