2013-07-05 45 views
2

是否有人可能会引导我朝着自动化此功能的正确方向前进,以便我只键入日期一次(或者使用鼠标从内置浏览器中选择它)在弹出的日历中),然后点击返回键,然后重复该过程直到完成。org-deadline - 一次性更改所选块中的所有内容

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

编辑:这里是... /口齿不清/ 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))))) 
+0

你选择什么意思? '区域内'? – Malabarba

+0

当用't'设置变量'org-loop-over-headlines-in-active-region'时,会导致'org-deadline'命令在所选任务组中的每个任务上运行。例如,如果我们选择一个包含5个任务的区域(例如,使用'(setq org-support-shift-select t)'选择shift +向上/向下),然后我们使用'Mx org-deadline',功能将一次处理5个任务中的每一个,并要求用户选择一个新日期,然后按下回车键,重复该过程直至完成。我期待开发一个能够自动重复这个过程的函数。 – lawlist

+0

我在原始问题下面添加了底层函数。 – lawlist

回答

1

下面的代码的主要功能应该做的伎俩。这只是一个单独询问时间的问题,他们自己将它传递给组织最后期限功能。

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

编辑:简化的功能。

+0

真棒!非常感谢 - 非常感谢! – lawlist