组织截止日期 - 一举改变所选区块中的所有区域

时间:2013-07-05 17:01:24

标签: emacs org-mode

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

(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)))))

1 个答案:

答案 0 :(得分: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)

编辑:简化了功能。