2

有人可以引导我朝着自动化这个功能的正确方向前进,这样我就只输入一次日期(或者用鼠标从内置的弹出日历中选择它)然后按回车键,然后它会重复这个过程自己直到完成。

(setq org-loop-over-headlines-in-active-region t)

(defun change-all-deadlines ()
  "Change all deadlines in the group of tasks that are selected / highlighted."
  (interactive)
  (org-deadline)
  (org-map-entries)
  (let (new-date
        (minibuffer-message "Please insert the new date, and then press RET to continue.")
        [User enters (with choice to use built-in calendar popup):  July 5, 2013]
        (format "%s" (new-date))
        [Then magic happens automatically -- :)]
    (minibuffer-message "Congratulations -- all dates have been changed to %s." new-date))))

编辑:这是来自 .../lisp/org.el 的主要功能

(defun org-deadline (&optional remove time)
  "Insert the \"DEADLINE:\" string with a timestamp to make a deadline.
With argument REMOVE, remove any deadline from the item.
With argument TIME, set the deadline at the corresponding date.  TIME
can either be an Org date like \"2011-07-24\" or a delta like \"+2d\"."
  (interactive "P")
  (if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
      (let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
            'region-start-level 'region))
        org-loop-over-headlines-in-active-region)
    (org-map-entries
     `(org-deadline ',remove ,time)
     org-loop-over-headlines-in-active-region
     cl (if (outline-invisible-p) (org-end-of-subtree nil t))))
    (let* ((old-date (org-entry-get nil "DEADLINE"))
       (repeater (and old-date
              (string-match
               "\\([.+-]+[0-9]+[hdwmy]\\(?:[/ ][-+]?[0-9]+[hdwmy]\\)?\\) ?"
               old-date)
              (match-string 1 old-date))))
      (if remove
      (progn
        (when (and old-date org-log-redeadline)
          (org-add-log-setup 'deldeadline nil old-date 'findpos
                 org-log-redeadline))
        (org-remove-timestamp-with-keyword org-deadline-string)
        (message "Item no longer has a deadline."))
    (org-add-planning-info 'deadline time 'closed)
    (when (and old-date org-log-redeadline
           (not (equal old-date
                   (substring org-last-inserted-timestamp 1 -1))))
      (org-add-log-setup 'redeadline nil old-date 'findpos
                 org-log-redeadline))
    (when repeater
      (save-excursion
        (org-back-to-heading t)
        (when (re-search-forward (concat org-deadline-string " "
                         org-last-inserted-timestamp)
                     (save-excursion
                       (outline-next-heading) (point)) t)
          (goto-char (1- (match-end 0)))
          (insert " " repeater)
          (setq org-last-inserted-timestamp
            (concat (substring org-last-inserted-timestamp 0 -1)
                " " repeater
                (substring org-last-inserted-timestamp -1))))))
    (message "Deadline on %s" org-last-inserted-timestamp)))))
4

1 回答 1

1

下面的代码应该可以解决问题。只需单独询问时间,然后他们自己将时间传递给 org-deadline 函数。

(defun org/deadline (remove)
  "like `org-deadline', except ask only once."
  (interactive "P")
  (unless remove (with-temp-buffer (org-time-stamp nil)))
  (org-deadline remove org-last-inserted-timestamp))


(global-set-key [remap org-deadline] 'org/deadline)

编辑:简化功能。

于 2013-07-06T12:18:30.227 回答