org-deadline — change all in selected block in one fell swoop

怎甘沉沦 提交于 2019-12-24 00:33:35

问题


Could someone please steer me in the right direction towards automating this function so that I only type the date one time (or select it with the mouse from the built-in popup calendar) and hit the return key, and then it repeats the process all by itself until finished.

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

EDIT: Here is the main function from .../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:


The following code should do the trick. It's just a matter of asking the time separately and them passing it yourself to the org-deadline function.

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

EDIT: Simplified the function.



来源:https://stackoverflow.com/questions/17493745/org-deadline-change-all-in-selected-block-in-one-fell-swoop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!