1426
1603
:group 'org-todo
1606
(defvar org-blocker-hook nil
1607
"Hook for functions that are allowed to block a state change.
1609
Each function gets as its single argument a property list, see
1610
`org-trigger-hook' for more information about this list.
1612
If any of the functions in this hook returns nil, the state change
1615
(defvar org-trigger-hook nil
1616
"Hook for functions that are triggered by a state change.
1618
Each function gets as its single argument a property list with at least
1619
the following elements:
1621
(:type type-of-change :position pos-at-entry-start
1622
:from old-state :to new-state)
1624
Depending on the type, more properties may be present.
1626
This mechanism is currently implemented for:
1630
:type todo-state-change
1631
:from previous state (keyword as a string), or nil, or a symbol
1632
'todo' or 'done', to indicate the general type of state.
1633
:to new state, like in :from")
1635
(defcustom org-enforce-todo-dependencies nil
1636
"Non-nil means, undone TODO entries will block switching the parent to DONE.
1637
Also, if a parent has an :ORDERED: property, switching an entry to DONE will
1638
be blocked if any prior sibling is not yet done.
1639
This variable needs to be set before org.el is loaded, and you need to
1640
restart Emacs after a change to make the change effective. The only way
1641
to change is while Emacs is running is through the customize interface."
1642
:set (lambda (var val)
1645
(add-hook 'org-blocker-hook
1646
'org-block-todo-from-children-or-siblings)
1647
(remove-hook 'org-blocker-hook
1648
'org-block-todo-from-children-or-siblings)))
1652
(defcustom org-enforce-todo-checkbox-dependencies nil
1653
"Non-nil means, unchecked boxes will block switching the parent to DONE.
1654
When this is nil, checkboxes have no influence on switching TODO states.
1655
When non-nil, you first need to check off all check boxes before the TODO
1656
entry can be switched to DONE.
1657
This variable needs to be set before org.el is loaded, and you need to
1658
restart Emacs after a change to make the change effective. The only way
1659
to change is while Emacs is running is through the customize interface."
1660
:set (lambda (var val)
1663
(add-hook 'org-blocker-hook
1664
'org-block-todo-from-checkboxes)
1665
(remove-hook 'org-blocker-hook
1666
'org-block-todo-from-checkboxes)))
1670
(defcustom org-todo-state-tags-triggers nil
1671
"Tag changes that should be triggered by TODO state changes.
1672
This is a list. Each entry is
1674
(state-change (tag . flag) .......)
1676
State-change can be a string with a state, and empty string to indicate the
1677
state that has no TODO keyword, or it can be one of the symbols `todo'
1678
or `done', meaning any not-done or done state, respectively."
1682
(cons (choice :tag "When changing to"
1683
(const :tag "Not-done state" todo)
1684
(const :tag "Done state" done)
1685
(string :tag "State"))
1687
(cons :tag "Tag action"
1689
(choice (const :tag "Add" t) (const :tag "Remove" nil)))))))
1429
1691
(defcustom org-log-done nil
1430
"Non-nil means, record a CLOSED timestamp when moving an entry to DONE.
1431
When equal to the list (done), also prompt for a closing note.
1432
This can also be configured on a per-file basis by adding one of
1433
the following lines anywhere in the buffer:
1692
"Information to record when a task moves to the DONE state.
1694
Possible values are:
1696
nil Don't add anything, just change the keyword
1697
time Add a time stamp to the task
1698
note Prompt a closing note and add it with template `org-log-note-headings'
1700
This option can also be set with on a per-file-basis with
1702
#+STARTUP: nologdone
1435
1703
#+STARTUP: logdone
1436
1704
#+STARTUP: lognotedone
1437
#+STARTUP: nologdone"
1706
You can have local logging settings for a subtree by setting the LOGGING
1707
property to one or more of these keywords."
1438
1708
:group 'org-todo
1439
1709
:group 'org-progress
7743
8380
\"WAITING\" -> switch to the specified keyword, but only if it
7744
8381
really is a member of `org-todo-keywords'."
7745
8382
(interactive "P")
7748
(org-back-to-heading)
7749
(if (looking-at outline-regexp) (goto-char (1- (match-end 0))))
7750
(or (looking-at (concat " +" org-todo-regexp " *"))
7752
(let* ((match-data (match-data))
7753
(startpos (point-at-bol))
7754
(logging (save-match-data (org-entry-get nil "LOGGING" t)))
7755
(org-log-done org-log-done)
7756
(org-log-repeat org-log-repeat)
7757
(org-todo-log-states org-todo-log-states)
7758
(this (match-string 1))
7759
(hl-pos (match-beginning 0))
7760
(head (org-get-todo-sequence-head this))
7761
(ass (assoc head org-todo-kwd-alist))
7762
(interpret (nth 1 ass))
7763
(done-word (nth 3 ass))
7764
(final-done-word (nth 4 ass))
7765
(last-state (or this ""))
7766
(completion-ignore-case t)
7767
(member (member this org-todo-keywords-1))
7770
((and org-todo-key-trigger
7771
(or (and (equal arg '(4)) (eq org-use-fast-todo-selection 'prefix))
7772
(and (not arg) org-use-fast-todo-selection
7773
(not (eq org-use-fast-todo-selection 'prefix)))))
7774
;; Use fast selection
7775
(org-fast-todo-selection))
7776
((and (equal arg '(4))
7777
(or (not org-use-fast-todo-selection)
7778
(not org-todo-key-trigger)))
7779
;; Read a state with completion
7780
(completing-read "State: " (mapcar (lambda(x) (list x))
7781
org-todo-keywords-1)
7785
(if tail (car tail) nil)
7786
(car org-todo-keywords-1)))
7788
(if (equal member org-todo-keywords-1)
8383
(if (equal arg '(16)) (setq arg 'nextset))
8384
(let ((org-blocker-hook org-blocker-hook))
8385
(when (equal arg '(64))
8386
(setq arg nil org-blocker-hook nil))
8389
(org-back-to-heading)
8390
(if (looking-at outline-regexp) (goto-char (1- (match-end 0))))
8391
(or (looking-at (concat " +" org-todo-regexp " *"))
8393
(let* ((match-data (match-data))
8394
(startpos (point-at-bol))
8395
(logging (save-match-data (org-entry-get nil "LOGGING" t)))
8396
(org-log-done org-log-done)
8397
(org-log-repeat org-log-repeat)
8398
(org-todo-log-states org-todo-log-states)
8399
(this (match-string 1))
8400
(hl-pos (match-beginning 0))
8401
(head (org-get-todo-sequence-head this))
8402
(ass (assoc head org-todo-kwd-alist))
8403
(interpret (nth 1 ass))
8404
(done-word (nth 3 ass))
8405
(final-done-word (nth 4 ass))
8406
(last-state (or this ""))
8407
(completion-ignore-case t)
8408
(member (member this org-todo-keywords-1))
8411
((and org-todo-key-trigger
8412
(or (and (equal arg '(4))
8413
(eq org-use-fast-todo-selection 'prefix))
8414
(and (not arg) org-use-fast-todo-selection
8415
(not (eq org-use-fast-todo-selection
8417
;; Use fast selection
8418
(org-fast-todo-selection))
8419
((and (equal arg '(4))
8420
(or (not org-use-fast-todo-selection)
8421
(not org-todo-key-trigger)))
8422
;; Read a state with completion
8423
(org-ido-completing-read
8424
"State: " (mapcar (lambda(x) (list x))
8425
org-todo-keywords-1)
7791
(nth (- (length org-todo-keywords-1) (length tail) 2)
7792
org-todo-keywords-1)
7793
(org-last org-todo-keywords-1))))
7794
((and (eq org-use-fast-todo-selection t) (equal arg '(4))
7795
(setq arg nil))) ; hack to fall back to cycling
7797
;; user or caller requests a specific state
7799
((equal arg "") nil)
7800
((eq arg 'none) nil)
7801
((eq arg 'done) (or done-word (car org-done-keywords)))
7803
(or (car (cdr (member head org-todo-heads)))
7804
(car org-todo-heads)))
7805
((eq arg 'previousset)
7806
(let ((org-todo-heads (reverse org-todo-heads)))
8429
(if tail (car tail) nil)
8430
(car org-todo-keywords-1)))
8432
(if (equal member org-todo-keywords-1)
8435
(nth (- (length org-todo-keywords-1)
8437
org-todo-keywords-1)
8438
(org-last org-todo-keywords-1))))
8439
((and (eq org-use-fast-todo-selection t) (equal arg '(4))
8440
(setq arg nil))) ; hack to fall back to cycling
8442
;; user or caller requests a specific state
8444
((equal arg "") nil)
8445
((eq arg 'none) nil)
8446
((eq arg 'done) (or done-word (car org-done-keywords)))
7807
8448
(or (car (cdr (member head org-todo-heads)))
7808
(car org-todo-heads))))
7809
((car (member arg org-todo-keywords-1)))
7810
((nth (1- (prefix-numeric-value arg))
7811
org-todo-keywords-1))))
7812
((null member) (or head (car org-todo-keywords-1)))
7813
((equal this final-done-word) nil) ;; -> make empty
7814
((null tail) nil) ;; -> first entry
7815
((eq interpret 'sequence)
7817
((memq interpret '(type priority))
7818
(if (eq this-command last-command)
7820
(if (> (length tail) 0)
7821
(or done-word (car org-done-keywords))
7824
(next (if state (concat " " state " ") " "))
7825
(change-plist (list :type 'todo-state-change :from this :to state
7826
:position startpos))
7828
(when org-blocker-hook
7829
(unless (save-excursion
7831
(run-hook-with-args-until-failure
7832
'org-blocker-hook change-plist)))
7834
(error "TODO state change from %s to %s blocked" this state)
7836
(message "TODO state change from %s to %s blocked" this state)
7837
(throw 'exit nil))))
7838
(store-match-data match-data)
7839
(replace-match next t t)
7840
(unless (pos-visible-in-window-p hl-pos)
7841
(message "TODO state changed to %s" (org-trim next)))
7843
(setq head (org-get-todo-sequence-head state)
7844
ass (assoc head org-todo-kwd-alist)
7845
interpret (nth 1 ass)
7846
done-word (nth 3 ass)
7847
final-done-word (nth 4 ass)))
7848
(when (memq arg '(nextset previousset))
7849
(message "Keyword-Set %d/%d: %s"
7850
(- (length org-todo-sets) -1
7851
(length (memq (assoc state org-todo-sets) org-todo-sets)))
7852
(length org-todo-sets)
7853
(mapconcat 'identity (assoc state org-todo-sets) " ")))
7854
(setq org-last-todo-state-is-todo
7855
(not (member state org-done-keywords)))
7856
(setq now-done-p (and (member state org-done-keywords)
7857
(not (member this org-done-keywords))))
7858
(and logging (org-local-logging logging))
7859
(when (and (or org-todo-log-states org-log-done)
7860
(not (memq arg '(nextset previousset))))
7861
;; we need to look at recording a time and note
7862
(setq dolog (or (nth 1 (assoc state org-todo-log-states))
7863
(nth 2 (assoc this org-todo-log-states))))
7865
(member state org-not-done-keywords)
7866
(not (member this org-not-done-keywords)))
7867
;; This is now a todo state and was not one before
7868
;; If there was a CLOSED time stamp, get rid of it.
7869
(org-add-planning-info nil nil 'closed))
7870
(when (and now-done-p org-log-done)
7871
;; It is now done, and it was not done before
7872
(org-add-planning-info 'closed (org-current-time))
7873
(if (and (not dolog) (eq 'note org-log-done))
7874
(org-add-log-setup 'done state 'findpos 'note)))
7875
(when (and state dolog)
7876
;; This is a non-nil state, and we need to log it
7877
(org-add-log-setup 'state state 'findpos dolog)))
7878
;; Fixup tag positioning
7879
(and org-auto-align-tags (not org-setting-tags) (org-set-tags nil t))
7880
(when org-provide-todo-statistics
7881
(org-update-parent-todo-statistics))
7882
(run-hooks 'org-after-todo-state-change-hook)
7883
(if (and arg (not (member state org-done-keywords)))
7884
(setq head (org-get-todo-sequence-head state)))
7885
(put-text-property (point-at-bol) (point-at-eol) 'org-todo-head head)
7886
;; Do we need to trigger a repeat?
7887
(when now-done-p (org-auto-repeat-maybe state))
7888
;; Fixup cursor location if close to the keyword
7889
(if (and (outline-on-heading-p)
7891
(save-excursion (beginning-of-line 1)
7892
(looking-at org-todo-line-regexp))
7893
(< (point) (+ 2 (or (match-end 2) (match-end 1)))))
7895
(goto-char (or (match-end 2) (match-end 1)))
7897
(when org-trigger-hook
7899
(run-hook-with-args 'org-trigger-hook change-plist)))))))
8449
(car org-todo-heads)))
8450
((eq arg 'previousset)
8451
(let ((org-todo-heads (reverse org-todo-heads)))
8452
(or (car (cdr (member head org-todo-heads)))
8453
(car org-todo-heads))))
8454
((car (member arg org-todo-keywords-1)))
8455
((nth (1- (prefix-numeric-value arg))
8456
org-todo-keywords-1))))
8457
((null member) (or head (car org-todo-keywords-1)))
8458
((equal this final-done-word) nil) ;; -> make empty
8459
((null tail) nil) ;; -> first entry
8460
((eq interpret 'sequence)
8462
((memq interpret '(type priority))
8463
(if (eq this-command last-command)
8465
(if (> (length tail) 0)
8466
(or done-word (car org-done-keywords))
8469
(next (if state (concat " " state " ") " "))
8470
(change-plist (list :type 'todo-state-change :from this :to state
8471
:position startpos))
8473
(when org-blocker-hook
8474
(setq org-last-todo-state-is-todo
8475
(not (member this org-done-keywords)))
8476
(unless (save-excursion
8478
(run-hook-with-args-until-failure
8479
'org-blocker-hook change-plist)))
8481
(error "TODO state change from %s to %s blocked" this state)
8483
(message "TODO state change from %s to %s blocked" this state)
8484
(throw 'exit nil))))
8485
(store-match-data match-data)
8486
(replace-match next t t)
8487
(unless (pos-visible-in-window-p hl-pos)
8488
(message "TODO state changed to %s" (org-trim next)))
8490
(setq head (org-get-todo-sequence-head state)
8491
ass (assoc head org-todo-kwd-alist)
8492
interpret (nth 1 ass)
8493
done-word (nth 3 ass)
8494
final-done-word (nth 4 ass)))
8495
(when (memq arg '(nextset previousset))
8496
(message "Keyword-Set %d/%d: %s"
8497
(- (length org-todo-sets) -1
8498
(length (memq (assoc state org-todo-sets) org-todo-sets)))
8499
(length org-todo-sets)
8500
(mapconcat 'identity (assoc state org-todo-sets) " ")))
8501
(setq org-last-todo-state-is-todo
8502
(not (member state org-done-keywords)))
8503
(setq now-done-p (and (member state org-done-keywords)
8504
(not (member this org-done-keywords))))
8505
(and logging (org-local-logging logging))
8506
(when (and (or org-todo-log-states org-log-done)
8507
(not (memq arg '(nextset previousset))))
8508
;; we need to look at recording a time and note
8509
(setq dolog (or (nth 1 (assoc state org-todo-log-states))
8510
(nth 2 (assoc this org-todo-log-states))))
8512
(member state org-not-done-keywords)
8513
(not (member this org-not-done-keywords)))
8514
;; This is now a todo state and was not one before
8515
;; If there was a CLOSED time stamp, get rid of it.
8516
(org-add-planning-info nil nil 'closed))
8517
(when (and now-done-p org-log-done)
8518
;; It is now done, and it was not done before
8519
(org-add-planning-info 'closed (org-current-time))
8520
(if (and (not dolog) (eq 'note org-log-done))
8521
(org-add-log-setup 'done state 'findpos 'note)))
8522
(when (and state dolog)
8523
;; This is a non-nil state, and we need to log it
8524
(org-add-log-setup 'state state 'findpos dolog)))
8525
;; Fixup tag positioning
8526
(org-todo-trigger-tag-changes state)
8527
(and org-auto-align-tags (not org-setting-tags) (org-set-tags nil t))
8528
(when org-provide-todo-statistics
8529
(org-update-parent-todo-statistics))
8530
(run-hooks 'org-after-todo-state-change-hook)
8531
(if (and arg (not (member state org-done-keywords)))
8532
(setq head (org-get-todo-sequence-head state)))
8533
(put-text-property (point-at-bol) (point-at-eol) 'org-todo-head head)
8534
;; Do we need to trigger a repeat?
8536
(when (boundp 'org-agenda-headline-snapshot-before-repeat)
8537
;; This is for the agenda, take a snapshot of the headline.
8539
(setq org-agenda-headline-snapshot-before-repeat
8540
(org-get-heading))))
8541
(org-auto-repeat-maybe state))
8542
;; Fixup cursor location if close to the keyword
8543
(if (and (outline-on-heading-p)
8545
(save-excursion (beginning-of-line 1)
8546
(looking-at org-todo-line-regexp))
8547
(< (point) (+ 2 (or (match-end 2) (match-end 1)))))
8549
(goto-char (or (match-end 2) (match-end 1)))
8551
(when org-trigger-hook
8553
(run-hook-with-args 'org-trigger-hook change-plist))))))))
8555
(defun org-block-todo-from-children-or-siblings (change-plist)
8556
"Block turning an entry into a TODO, using the hierarchy.
8557
This checks whether the current task should be blocked from state
8558
changes. Such blocking occurs when:
8560
1. The task has children which are not all in a completed state.
8562
2. A task has a parent with the property :ORDERED:, and there
8563
are siblings prior to the current task with incomplete
8566
;; If this is not a todo state change, or if this entry is already DONE,
8568
(when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
8569
(member (plist-get change-plist :from)
8570
(cons 'done org-done-keywords))
8571
(member (plist-get change-plist :to)
8572
(cons 'todo org-not-done-keywords)))
8573
(throw 'dont-block t))
8574
;; If this task has children, and any are undone, it's blocked
8576
(org-back-to-heading t)
8577
(let ((this-level (funcall outline-level)))
8578
(outline-next-heading)
8579
(let ((child-level (funcall outline-level)))
8580
(while (and (not (eobp))
8581
(> child-level this-level))
8582
;; this todo has children, check whether they are all
8584
(if (and (not (org-entry-is-done-p))
8585
(org-entry-is-todo-p))
8586
(throw 'dont-block nil))
8587
(outline-next-heading)
8588
(setq child-level (funcall outline-level))))))
8589
;; Otherwise, if the task's parent has the :ORDERED: property, and
8590
;; any previous siblings are undone, it's blocked
8592
(org-back-to-heading t)
8593
(when (save-excursion
8595
(org-up-heading-all 1)
8596
(org-entry-get (point) "ORDERED")))
8597
(let* ((this-level (funcall outline-level))
8598
(current-level this-level))
8599
(while (and (not (bobp))
8600
(= current-level this-level))
8601
(outline-previous-heading)
8602
(setq current-level (funcall outline-level))
8603
(if (= current-level this-level)
8604
;; this todo has children, check whether they are all
8606
(if (and (not (org-entry-is-done-p))
8607
(org-entry-is-todo-p))
8608
(throw 'dont-block nil)))))))
8611
(defun org-toggle-ordered-property ()
8612
"Toggle the ORDERED property of the current entry."
8615
(org-back-to-heading)
8616
(if (org-entry-get nil "ORDERED")
8618
(org-delete-property "ORDERED")
8619
(message "Subtasks can be completed in arbitrary order or parallel"))
8620
(org-entry-put nil "ORDERED" "t")
8621
(message "Subtasks must be completed in sequence"))))
8623
(defun org-block-todo-from-checkboxes (change-plist)
8624
"Block turning an entry into a TODO, using checkboxes.
8625
This checks whether the current task should be blocked from state
8626
changes because there are uncheckd boxes in this entry."
8628
;; If this is not a todo state change, or if this entry is already DONE,
8630
(when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
8631
(member (plist-get change-plist :from)
8632
(cons 'done org-done-keywords))
8633
(member (plist-get change-plist :to)
8634
(cons 'todo org-not-done-keywords)))
8635
(throw 'dont-block t))
8636
;; If this task has checkboxes that are not checked, it's blocked
8638
(org-back-to-heading t)
8639
(let ((beg (point)) end)
8640
(outline-next-heading)
8643
(if (re-search-forward "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\)[ \t]+\\[[- ]\\]"
8645
(throw 'dont-block nil))))
7901
8648
(defun org-update-parent-todo-statistics ()
7902
8649
"Update any statistics cookie in the parent of the current headline."
7904
8651
(let ((box-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
7905
level (cnt-all 0) (cnt-done 0) is-percent kwd)
8652
level (cnt-all 0) (cnt-done 0) is-percent kwd cookie-present)
7907
8654
(save-excursion
7908
8655
(setq level (org-up-heading-safe))
7910
(re-search-forward box-re (point-at-eol) t))
7911
8657
(throw 'exit nil))
7912
(setq is-percent (match-end 2))
7914
(unless (outline-next-heading) (throw 'exit nil))
7915
(while (looking-at org-todo-line-regexp)
7916
(setq kwd (match-string 2))
7917
(and kwd (setq cnt-all (1+ cnt-all)))
7918
(and (member kwd org-done-keywords)
7919
(setq cnt-done (1+ cnt-done)))
7921
(org-forward-same-level 1)
7922
(error (end-of-line 1)))))
7925
(format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all)))
7926
(format "[%d/%d]" cnt-done cnt-all)))
7927
(run-hook-with-args 'org-after-todo-statistics-hook
7928
cnt-done (- cnt-all cnt-done))))))
8658
(while (re-search-forward box-re (point-at-eol) t)
8659
(setq cnt-all 0 cnt-done 0 cookie-present t)
8660
(setq is-percent (match-end 2))
8662
(unless (outline-next-heading) (throw 'exit nil))
8663
(while (looking-at org-todo-line-regexp)
8664
(setq kwd (match-string 2))
8665
(and kwd (setq cnt-all (1+ cnt-all)))
8666
(and (member kwd org-done-keywords)
8667
(setq cnt-done (1+ cnt-done)))
8669
(org-forward-same-level 1)
8670
(error (end-of-line 1)))))
8673
(format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all)))
8674
(format "[%d/%d]" cnt-done cnt-all))))
8675
(when cookie-present
8676
(run-hook-with-args 'org-after-todo-statistics-hook
8677
cnt-done (- cnt-all cnt-done)))))))
7930
8679
(defvar org-after-todo-statistics-hook nil
7931
8680
"Hook that is called after a TODO statistics cookie has been updated.
12376
13252
depending on context. See the individual commands for more information."
12377
13253
(interactive "P")
13255
((and org-support-shift-select (org-region-active-p))
13256
(org-call-for-shift-select 'next-line))
12379
13257
((org-at-timestamp-p t)
12380
13258
(call-interactively (if org-edit-timestamp-down-means-later
12381
13259
'org-timestamp-up 'org-timestamp-down)))
12382
((org-on-heading-p) (call-interactively 'org-priority-down))
13260
((and (not (eq org-support-shift-select 'always))
13261
(org-on-heading-p))
13262
(call-interactively 'org-priority-down))
13263
((and (not org-support-shift-select) (org-at-item-p))
13264
(call-interactively 'org-next-item))
12383
13265
((org-clocktable-try-shift 'down arg))
12384
(t (call-interactively 'org-next-item))))
13266
(org-support-shift-select
13267
(org-call-for-shift-select 'next-line))
13268
(t (org-shiftselect-error))))
12386
13270
(defun org-shiftright (&optional arg)
12387
"Next TODO keyword or timestamp one day later, depending on context."
13271
"Cycle the thing at point or in the current line, depending on context.
13272
Depending on context, this does one of the following:
13274
- switch a timestamp at point one day into the future
13275
- on a headline, switch to the next TODO keyword.
13276
- on an item, switch entire list to the next bullet type
13277
- on a property line, switch to the next allowed value
13278
- on a clocktable definition line, move time block into the future"
12388
13279
(interactive "P")
13281
((and org-support-shift-select (org-region-active-p))
13282
(org-call-for-shift-select 'forward-char))
12390
13283
((org-at-timestamp-p t) (call-interactively 'org-timestamp-up-day))
12391
((org-on-heading-p) (org-call-with-arg 'org-todo 'right))
12392
((org-at-item-p) (org-call-with-arg 'org-cycle-list-bullet nil))
12393
((org-at-property-p) (call-interactively 'org-property-next-allowed-value))
13284
((and (not (eq org-support-shift-select 'always))
13285
(org-on-heading-p))
13286
(org-call-with-arg 'org-todo 'right))
13287
((or (and org-support-shift-select
13288
(not (eq org-support-shift-select 'always))
13289
(org-at-item-bullet-p))
13290
(and (not org-support-shift-select) (org-at-item-p)))
13291
(org-call-with-arg 'org-cycle-list-bullet nil))
13292
((and (not (eq org-support-shift-select 'always))
13293
(org-at-property-p))
13294
(call-interactively 'org-property-next-allowed-value))
12394
13295
((org-clocktable-try-shift 'right arg))
12395
(t (org-shiftcursor-error))))
13296
(org-support-shift-select
13297
(org-call-for-shift-select 'forward-char))
13298
(t (org-shiftselect-error))))
12397
13300
(defun org-shiftleft (&optional arg)
12398
"Previous TODO keyword or timestamp one day earlier, depending on context."
13301
"Cycle the thing at point or in the current line, depending on context.
13302
Depending on context, this does one of the following:
13304
- switch a timestamp at point one day into the past
13305
- on a headline, switch to the previous TODO keyword.
13306
- on an item, switch entire list to the previous bullet type
13307
- on a property line, switch to the previous allowed value
13308
- on a clocktable definition line, move time block into the past"
12399
13309
(interactive "P")
13311
((and org-support-shift-select (org-region-active-p))
13312
(org-call-for-shift-select 'backward-char))
12401
13313
((org-at-timestamp-p t) (call-interactively 'org-timestamp-down-day))
12402
((org-on-heading-p) (org-call-with-arg 'org-todo 'left))
12403
((org-at-item-p) (org-call-with-arg 'org-cycle-list-bullet 'previous))
12404
((org-at-property-p)
13314
((and (not (eq org-support-shift-select 'always))
13315
(org-on-heading-p))
13316
(org-call-with-arg 'org-todo 'left))
13317
((or (and org-support-shift-select
13318
(not (eq org-support-shift-select 'always))
13319
(org-at-item-bullet-p))
13320
(and (not org-support-shift-select) (org-at-item-p)))
13321
(org-call-with-arg 'org-cycle-list-bullet 'previous))
13322
((and (not (eq org-support-shift-select 'always))
13323
(org-at-property-p))
12405
13324
(call-interactively 'org-property-previous-allowed-value))
12406
13325
((org-clocktable-try-shift 'left arg))
12407
(t (org-shiftcursor-error))))
13326
(org-support-shift-select
13327
(org-call-for-shift-select 'backward-char))
13328
(t (org-shiftselect-error))))
12409
13330
(defun org-shiftcontrolright ()
12410
13331
"Switch to next TODO set."
12411
13332
(interactive)
12413
((org-on-heading-p) (org-call-with-arg 'org-todo 'nextset))
12414
(t (org-shiftcursor-error))))
13334
((and org-support-shift-select (org-region-active-p))
13335
(org-call-for-shift-select 'forward-word))
13336
((and (not (eq org-support-shift-select 'always))
13337
(org-on-heading-p))
13338
(org-call-with-arg 'org-todo 'nextset))
13339
(org-support-shift-select
13340
(org-call-for-shift-select 'forward-word))
13341
(t (org-shiftselect-error))))
12416
13343
(defun org-shiftcontrolleft ()
12417
13344
"Switch to previous TODO set."
12418
13345
(interactive)
12420
((org-on-heading-p) (org-call-with-arg 'org-todo 'previousset))
12421
(t (org-shiftcursor-error))))
13347
((and org-support-shift-select (org-region-active-p))
13348
(org-call-for-shift-select 'backward-word))
13349
((and (not (eq org-support-shift-select 'always))
13350
(org-on-heading-p))
13351
(org-call-with-arg 'org-todo 'previousset))
13352
(org-support-shift-select
13353
(org-call-for-shift-select 'backward-word))
13354
(t (org-shiftselect-error))))
12423
13356
(defun org-ctrl-c-ret ()
12424
13357
"Call `org-table-hline-and-move' or `org-insert-heading' dep. on context."
13793
14782
(org-set-tags nil t))
13794
14783
(t (kill-region (point) (point-at-eol)))))
13797
14785
(define-key org-mode-map "\C-k" 'org-kill-line)
13800
"Yank, and if the yanked text is a single subtree, fold it.
13801
In fact, if the yanked text is a sequence of subtrees, fold all of them."
13803
(if org-yank-folded-subtrees
13804
(let ((beg (point)) end)
13805
(call-interactively 'yank)
13809
(org-kill-is-subtree-p))
13810
(or (looking-at outline-regexp)
13811
(re-search-forward (concat "^" outline-regexp) end t))
13812
(while (and (< (point) end) (looking-at outline-regexp))
13814
(org-cycle-show-empty-lines 'folded)
13815
(condition-case nil
13816
(outline-forward-same-level 1)
13817
(error (goto-char end)))))
13819
(skip-chars-forward " \t\n\r"))
13820
(call-interactively 'yank)))
14787
(defun org-yank (&optional arg)
14788
"Yank. If the kill is a subtree, treat it specially.
14789
This command will look at the current kill and check if is a single
14790
subtree, or a series of subtrees[1]. If it passes the test, and if the
14791
cursor is at the beginning of a line or after the stars of a currently
14792
empty headline, then the yank is handled specially. How exactly depends
14793
on the value of the following variables, both set by default.
14795
org-yank-folded-subtrees
14796
When set, the subtree(s) will be folded after insertion, but only
14797
if doing so would now swallow text after the yanked text.
14799
org-yank-adjusted-subtrees
14800
When set, the subtree will be promoted or demoted in order to
14801
fit into the local outline tree structure, which means that the level
14802
will be adjusted so that it becomes the smaller one of the two
14803
*visible* surrounding headings.
14805
Any prefix to this command will cause `yank' to be called directly with
14806
no special treatment. In particular, a simple `C-u' prefix will just
14807
plainly yank the text as it is.
14809
\[1] Basically, the test checks if the first non-white line is a heading
14810
and if there are no other headings with fewer stars."
14812
(setq this-command 'yank)
14814
(call-interactively 'yank)
14815
(let ((subtreep ; is kill a subtree, and the yank position appropriate?
14816
(and (org-kill-is-subtree-p)
14818
(and (looking-at "[ \t]*$")
14821
(buffer-substring (point-at-bol) (point)))))))
14824
((and subtreep org-yank-folded-subtrees)
14825
(let ((beg (point))
14827
(if (and subtreep org-yank-adjusted-subtrees)
14828
(org-paste-subtree nil nil 'for-yank)
14829
(call-interactively 'yank))
14832
(when (and (bolp) subtreep
14833
(not (setq swallowp
14834
(org-yank-folding-would-swallow-text beg end))))
14835
(or (looking-at outline-regexp)
14836
(re-search-forward (concat "^" outline-regexp) end t))
14837
(while (and (< (point) end) (looking-at outline-regexp))
14839
(org-cycle-show-empty-lines 'folded)
14840
(condition-case nil
14841
(outline-forward-same-level 1)
14842
(error (goto-char end)))))
14845
"Yanked text not folded because that would swallow text"))
14847
(skip-chars-forward " \t\n\r")
14848
(beginning-of-line 1)
14849
(push-mark beg 'nomsg)))
14850
((and subtreep org-yank-adjusted-subtrees)
14851
(let ((beg (point-at-bol)))
14852
(org-paste-subtree nil nil 'for-yank)
14853
(push-mark beg 'nomsg)))
14855
(call-interactively 'yank))))))
14857
(defun org-yank-folding-would-swallow-text (beg end)
14858
"Would hide-subtree at BEG swallow any text after END?"
14862
(when (or (looking-at outline-regexp)
14863
(re-search-forward (concat "^" outline-regexp) end t))
14864
(setq level (org-outline-level)))
14866
(skip-chars-forward " \t\r\n\v\f")
14868
(and (bolp) (looking-at org-outline-regexp)
14869
(<= (org-outline-level) level)))
14870
nil ; Nothing would be swallowed
14871
t)))) ; something would swallow
13822
14873
(define-key org-mode-map "\C-y" 'org-yank)