Function: org-add-planning-info
org-add-planning-info is a byte-compiled function defined in
org.el.gz.
Signature
(org-add-planning-info WHAT &optional TIME &rest REMOVE)
Documentation
Insert new timestamp with keyword in the planning line.
WHAT indicates what kind of time stamp to add. It is a symbol
among closed, deadline, scheduled and nil. TIME indicates
the time to use. If none is given, the user is prompted for
a date. REMOVE indicates what kind of entries to remove. An old
WHAT entry will also be removed.
Source Code
;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org-add-planning-info (what &optional time &rest remove)
"Insert new timestamp with keyword in the planning line.
WHAT indicates what kind of time stamp to add. It is a symbol
among `closed', `deadline', `scheduled' and nil. TIME indicates
the time to use. If none is given, the user is prompted for
a date. REMOVE indicates what kind of entries to remove. An old
WHAT entry will also be removed."
(org-fold-core-ignore-modifications
(let (org-time-was-given org-end-time-was-given default-time default-input)
(when (and (memq what '(scheduled deadline))
(or (not time)
(and (stringp time)
(string-match "^[-+]+[0-9]" time))))
;; Try to get a default date/time from existing timestamp
(save-excursion
(org-back-to-heading t)
(let ((end (save-excursion (outline-next-heading) (point))) ts)
(when (re-search-forward (if (eq what 'scheduled)
org-scheduled-time-regexp
org-deadline-time-regexp)
end t)
(setq ts (match-string 1)
default-time (org-time-string-to-time ts)
default-input (and ts (org-get-compact-tod ts)))))))
(when what
(setq time
(if (stringp time)
;; This is a string (relative or absolute), set
;; proper date.
(org-encode-time
(org-read-date-analyze
time default-time (decode-time default-time)))
;; If necessary, get the time from the user
(or time (org-read-date nil 'to-time nil
(cl-case what
(deadline "DEADLINE")
(scheduled "SCHEDULED")
(otherwise nil))
default-time default-input)))))
(org-with-wide-buffer
(org-back-to-heading t)
(let ((planning? (save-excursion
(forward-line)
(looking-at-p org-planning-line-re))))
(cond
(planning?
(forward-line)
;; Move to current indentation.
(skip-chars-forward " \t")
;; Check if we have to remove something.
(dolist (type (if what (cons what remove) remove))
(save-excursion
(when (re-search-forward
(cl-case type
(closed org-closed-time-regexp)
(deadline org-deadline-time-regexp)
(scheduled org-scheduled-time-regexp)
(otherwise (error "Invalid planning type: %s" type)))
(line-end-position)
t)
;; Delete until next keyword or end of line.
(delete-region
(match-beginning 0)
(if (re-search-forward org-keyword-time-not-clock-regexp
(line-end-position)
t)
(match-beginning 0)
(line-end-position))))))
;; If there is nothing more to add and no more keyword is
;; left, remove the line completely.
(if (and (looking-at-p "[ \t]*$") (not what))
(delete-region (line-end-position 0)
(line-end-position))
;; If we removed last keyword, do not leave trailing white
;; space at the end of line.
(let ((p (point)))
(save-excursion
(end-of-line)
(unless (= (skip-chars-backward " \t" p) 0)
(delete-region (point) (line-end-position)))))))
(what
(end-of-line)
(insert-and-inherit "\n")
(when org-adapt-indentation
(indent-to-column (1+ (org-outline-level)))))
(t nil)))
(when what
;; Insert planning keyword.
(insert-and-inherit (cl-case what
(closed org-closed-string)
(deadline org-deadline-string)
(scheduled org-scheduled-string)
(otherwise (error "Invalid planning type: %s" what)))
" ")
;; Insert associated timestamp.
(let ((ts (org-insert-timestamp
time
(or org-time-was-given
(and (eq what 'closed) org-log-done-with-time))
(eq what 'closed)
nil nil (list org-end-time-was-given))))
(unless (eolp) (insert " "))
ts))))))