소스 검색

Refactoring.

Nicolas Goaziou 14 년 전
부모
커밋
3dfc889cce
2개의 변경된 파일16개의 추가작업 그리고 10개의 파일을 삭제
  1. 13 6
      lisp/org-list.el
  2. 3 4
      lisp/org-timer.el

+ 13 - 6
lisp/org-list.el

@@ -438,6 +438,16 @@ function end."
        (not (member (char-after) '(?\  ?\t)))
        (< (point) (match-end 0))))
 
+(defun org-at-item-timer-p ()
+  "Is point at a line starting a plain list item with a timer?
+This skips checkboxes, if any."
+  (and (or (org-at-item-checkbox-p)
+	   (org-at-item-p))
+       (save-excursion
+	 (goto-char (match-end 0))
+	 (skip-chars-forward " \t")
+	 (looking-at "\\([0-9]+:[0-9]+:[0-9]+\\)[ \t]+::[ \t]+"))))
+
 (defun org-at-item-checkbox-p ()
   "Is point at a line starting a plain-list item with a checklet?"
   (and (org-at-item-p)
@@ -686,10 +696,8 @@ things worked, nil when we are not in an item, or item is
 invisible."
   (unless (or (not (org-in-item-p))
 	      (org-invisible-p))
-    ;; Timer list: delegate to `org-timer-item'.
-    (if (save-excursion
-	  (org-beginning-of-item)
-	  (looking-at "[ \t]*[-+*][ \t]+[0-9]+:[0-9]+:[0-9]+ ::"))
+    (if (org-at-item-timer-p)
+	;; Timer list: delegate to `org-timer-item'.
 	(progn (org-timer-item) t)
       ;; if we're in a description list, ask for the new term.
       (let ((desc-text (when (save-excursion
@@ -1302,8 +1310,7 @@ optional argument WITH-CASE, the sorting considers case as well."
 		   ((= dcst ?t)
 		    (cond
 		     ;; If it is a timer list, convert timer to seconds
-		     ((and (goto-char (match-end 0))
-			   (looking-at "\\([0-9]+:[0-9]+:[0-9]+\\)[ \t]+::"))
+		     ((org-at-item-timer-p)
 		      (org-timer-hms-to-secs (match-string 1)))
 		     ((or (org-search-forward-unenclosed org-ts-regexp
 							 (point-at-eol) t)

+ 3 - 4
lisp/org-timer.el

@@ -203,10 +203,9 @@ it in the buffer."
   (cond
    ;; In a timer list, insert with `org-insert-item-internal'.
    ((and (org-in-item-p)
-	 (save-excursion
-	   (org-beginning-of-item)
-	   (looking-at "[ \t]*[-+*][ \t]+[0-9]+:[0-9]+:[0-9]+ ::")))
-    (org-insert-item-internal (point) nil (concat (org-timer (when arg '(4)) t) ":: ")))
+	 (org-at-item-timer-p))
+    (org-insert-item-internal
+     (point) nil (concat (org-timer (when arg '(4)) t) ":: ")))
    ;; In a list of another type, don't break anything: throw an error.
    ((org-in-item-p)
     (error "This is not a timer list"))