Browse Source

Bind `org-clock-in-last' to C-c C-x C-x and ̀org-clock-cancel' to C-c C-x C-q.

* org.el (org-flag-drawer): Add a docstring.
(org-mode-map): Bind ̀org-clock-cancel' to "C-cC-xC-q" and
`org-clock-in-last' to "C-cC-xC-x".  This fixes a bug in the
previous keybinding for `org-clock-in-last', which would
override the one for `org-clock-in'.

* org-clock.el (org-clock-in-last): Prevent errors when there
is no clocking history.
(org-clock-cancel): Fix bug when checking against a clock log
in a folded drawer.

Thanks to Bernt Hansen who reported the problem.
Bastien Guerry 8 years ago
parent
commit
fea1b82bef
2 changed files with 11 additions and 8 deletions
  1. 7 6
      lisp/org-clock.el
  2. 4 2
      lisp/org.el

+ 7 - 6
lisp/org-clock.el

@@ -1264,10 +1264,12 @@ last clock-out time, if any."
     (let ((start-time (if (or org-clock-continuously (equal arg '(16)))
 			  (or org-clock-out-time (current-time))
 			(current-time))))
-      (org-clock-clock-in (list (car org-clock-history)) nil start-time)
-      (message "Now clocking in: %s (in %s)"
-	       org-clock-current-task
-	       (buffer-name (marker-buffer org-clock-marker))))))
+      (if (null org-clock-history)
+	  (message "No last clock")
+	(org-clock-clock-in (list (car org-clock-history)) nil start-time)
+	(message "Clocking back: %s (in %s)"
+		 org-clock-current-task
+		 (buffer-name (marker-buffer org-clock-marker)))))))
 
 (defun org-clock-mark-default-task ()
   "Mark current task as default task."
@@ -1560,8 +1562,7 @@ UPDOWN tells whether to change 'up or 'down."
   (save-excursion ; Do not replace this with `with-current-buffer'.
     (org-no-warnings (set-buffer (org-clocking-buffer)))
     (goto-char org-clock-marker)
-    (if (save-excursion (move-beginning-of-line 1)
-			(looking-at (concat "^[ \t]*" org-clock-string)))
+    (if (looking-back (concat "^[ \t]*" org-clock-string ".*"))
 	(progn (delete-region (1- (point-at-bol)) (point-at-eol))
 	       (org-remove-empty-drawer-at "LOGBOOK" (point)))
       (message "Clock gone, cancel the timer anyway")

+ 4 - 2
lisp/org.el

@@ -6703,6 +6703,8 @@ open and agenda-wise Org files."
 	  (org-flag-drawer t))))))
 
 (defun org-flag-drawer (flag)
+  "When FLAG is non-nil, hide the drawer we are within.
+Otherwise make it visible."
   (save-excursion
     (beginning-of-line 1)
     (when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:")
@@ -17800,10 +17802,10 @@ BEG and END default to the buffer boundaries."
 
 (org-defkey org-mode-map "\C-c\C-x\C-t" 'org-toggle-time-stamp-overlays)
 (org-defkey org-mode-map "\C-c\C-x\C-i" 'org-clock-in)
-(org-defkey org-mode-map "\C-c\C-x\C-I" 'org-clock-in-last)
+(org-defkey org-mode-map "\C-c\C-x\C-x" 'org-clock-in-last)
 (org-defkey org-mode-map "\C-c\C-x\C-o" 'org-clock-out)
 (org-defkey org-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
-(org-defkey org-mode-map "\C-c\C-x\C-x" 'org-clock-cancel)
+(org-defkey org-mode-map "\C-c\C-x\C-q" 'org-clock-cancel)
 (org-defkey org-mode-map "\C-c\C-x\C-d" 'org-clock-display)
 (org-defkey org-mode-map "\C-c\C-x\C-r" 'org-clock-report)
 (org-defkey org-mode-map "\C-c\C-x\C-u" 'org-dblock-update)