0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-09-29 18:36:26 +00:00

org-clock: Use lexical binding

* lisp/org-clock.el (org-clock-save-markers-for-cut-and-paste):
(org-clock-select-task):
(org-clock-out):
(org-clock-load): Use `dolist' instead of `mapc' + `lambda'.

(org-clock-insert-selection-line):
(org-resolve-clocks-if-idle):
(org-clock-find-position):
(org-clock-remove-overlays):
(org-dblock-write:clocktable):
(org-clocktable-steps):
(org-clock-get-table-data): Silence byte-compiler.
This commit is contained in:
Nicolas Goaziou 2015-12-20 23:04:48 +01:00
parent f090a2ae87
commit 35bc1c8853

View file

@ -1,4 +1,4 @@
;;; org-clock.el --- The time clocking code for Org-mode ;;; org-clock.el --- The time clocking code for Org mode -*- lexical-binding: t; -*-
;; Copyright (C) 2004-2015 Free Software Foundation, Inc. ;; Copyright (C) 2004-2015 Free Software Foundation, Inc.
@ -24,7 +24,7 @@
;; ;;
;;; Commentary: ;;; Commentary:
;; This file contains the time clocking code for Org-mode ;; This file contains the time clocking code for Org mode
;;; Code: ;;; Code:
@ -554,8 +554,8 @@ of a different task.")
(org-check-and-save-marker org-clock-hd-marker beg end) (org-check-and-save-marker org-clock-hd-marker beg end)
(org-check-and-save-marker org-clock-default-task beg end) (org-check-and-save-marker org-clock-default-task beg end)
(org-check-and-save-marker org-clock-interrupted-task beg end) (org-check-and-save-marker org-clock-interrupted-task beg end)
(mapc (lambda (m) (org-check-and-save-marker m beg end)) (dolist (m org-clock-history)
org-clock-history)) (org-check-and-save-marker m beg end)))
(defun org-clock-drawer-name () (defun org-clock-drawer-name ()
"Return clock drawer's name for current entry, or nil." "Return clock drawer's name for current entry, or nil."
@ -580,8 +580,8 @@ of a different task.")
(interactive) (interactive)
(let (och chl sel-list rpl (i 0) s) (let (och chl sel-list rpl (i 0) s)
;; Remove successive dups from the clock history to consider ;; Remove successive dups from the clock history to consider
(mapc (lambda (c) (if (not (equal c (car och))) (push c och))) (dolist (c org-clock-history)
org-clock-history) (unless (equal c (car och)) (push c och)))
(setq och (reverse och) chl (length och)) (setq och (reverse och) chl (length och))
(if (zerop chl) (if (zerop chl)
(user-error "No recent clock") (user-error "No recent clock")
@ -602,17 +602,15 @@ of a different task.")
(setq s (org-clock-insert-selection-line ?c org-clock-marker)) (setq s (org-clock-insert-selection-line ?c org-clock-marker))
(push s sel-list)) (push s sel-list))
(insert (org-add-props "Recent Tasks\n" nil 'face 'bold)) (insert (org-add-props "Recent Tasks\n" nil 'face 'bold))
(mapc (dolist (m och)
(lambda (m) (when (marker-buffer m)
(when (marker-buffer m) (setq i (1+ i)
(setq i (1+ i) s (org-clock-insert-selection-line
s (org-clock-insert-selection-line (if (< i 10)
(if (< i 10) (+ i ?0)
(+ i ?0) (+ i (- ?A 10))) m))
(+ i (- ?A 10))) m)) (if (fboundp 'int-to-char) (setf (car s) (int-to-char (car s))))
(if (fboundp 'int-to-char) (setf (car s) (int-to-char (car s)))) (push s sel-list)))
(push s sel-list)))
och)
(run-hooks 'org-clock-before-select-task-hook) (run-hooks 'org-clock-before-select-task-hook)
(goto-char (point-min)) (goto-char (point-min))
;; Set min-height relatively to circumvent a possible but in ;; Set min-height relatively to circumvent a possible but in
@ -632,25 +630,22 @@ of a different task.")
And return a cons cell with the selection character integer and the marker And return a cons cell with the selection character integer and the marker
pointing to it." pointing to it."
(when (marker-buffer marker) (when (marker-buffer marker)
(let (file cat task heading prefix) (let (cat task heading prefix)
(with-current-buffer (org-base-buffer (marker-buffer marker)) (with-current-buffer (org-base-buffer (marker-buffer marker))
(save-excursion (org-with-wide-buffer
(save-restriction (ignore-errors
(widen) (goto-char marker)
(ignore-errors (setq cat (org-get-category)
(goto-char marker) heading (org-get-heading 'notags)
(setq file (buffer-file-name (marker-buffer marker)) prefix (save-excursion
cat (org-get-category) (org-back-to-heading t)
heading (org-get-heading 'notags) (looking-at org-outline-regexp)
prefix (save-excursion (match-string 0))
(org-back-to-heading t) task (substring
(looking-at org-outline-regexp) (org-fontify-like-in-org-mode
(match-string 0)) (concat prefix heading)
task (substring org-odd-levels-only)
(org-fontify-like-in-org-mode (length prefix))))))
(concat prefix heading)
org-odd-levels-only)
(length prefix)))))))
(when (and cat task) (when (and cat task)
(insert (format "[%c] %-12s %s\n" i cat task)) (insert (format "[%c] %-12s %s\n" i cat task))
(cons i marker))))) (cons i marker)))))
@ -1164,13 +1159,12 @@ so long."
(org-clock-resolve (org-clock-resolve
(cons org-clock-marker (cons org-clock-marker
org-clock-start-time) org-clock-start-time)
(function (lambda (_)
(lambda (clock) (format "Clocked in & idle for %.1f mins"
(format "Clocked in & idle for %.1f mins" (/ (org-float-time
(/ (org-float-time (time-subtract (current-time)
(time-subtract (current-time) org-clock-user-idle-start))
org-clock-user-idle-start)) 60.0)))
60.0))))
org-clock-user-idle-start))))) org-clock-user-idle-start)))))
(defvar org-clock-current-task nil "Task currently clocked in.") (defvar org-clock-current-task nil "Task currently clocked in.")
@ -1488,7 +1482,8 @@ line and position cursor in that line."
(throw 'exit t))))))) (throw 'exit t)))))))
(goto-char beg) (goto-char beg)
(let ((clock-re (concat "^[ \t]*" org-clock-string)) (let ((clock-re (concat "^[ \t]*" org-clock-string))
(count 0) positions first) (count 0)
positions)
;; Count the CLOCK lines and store their positions. ;; Count the CLOCK lines and store their positions.
(save-excursion (save-excursion
(while (re-search-forward clock-re end t) (while (re-search-forward clock-re end t)
@ -1641,7 +1636,7 @@ to, overriding the existing value of `org-clock-out-switch-to-state'."
(eq org-log-done 'note) (eq org-log-done 'note)
org-clock-out-when-done) org-clock-out-when-done)
(setq h (delq 'org-clock-remove-empty-clock-drawer h))) (setq h (delq 'org-clock-remove-empty-clock-drawer h)))
(mapc (lambda (f) (funcall f)) h)) (mapc #'funcall h))
(unless (org-clocking-p) (unless (org-clocking-p)
(setq org-clock-current-task nil))))))) (setq org-clock-current-task nil)))))))
@ -1971,13 +1966,13 @@ will be easy to remove."
(push ov org-clock-overlays))) (push ov org-clock-overlays)))
;;;###autoload ;;;###autoload
(defun org-clock-remove-overlays (&optional beg end noremove) (defun org-clock-remove-overlays (&optional _beg _end noremove)
"Remove the occur highlights from the buffer. "Remove the occur highlights from the buffer.
BEG and END are ignored. If NOREMOVE is nil, remove this function If NOREMOVE is nil, remove this function from the
from the `before-change-functions' in the current buffer." `before-change-functions' in the current buffer."
(interactive) (interactive)
(unless org-inhibit-highlight-removal (unless org-inhibit-highlight-removal
(mapc 'delete-overlay org-clock-overlays) (mapc #'delete-overlay org-clock-overlays)
(setq org-clock-overlays nil) (setq org-clock-overlays nil)
(unless noremove (unless noremove
(remove-hook 'before-change-functions (remove-hook 'before-change-functions
@ -2367,22 +2362,19 @@ the currently selected interval size."
(block (plist-get params :block)) (block (plist-get params :block))
(ts (plist-get params :tstart)) (ts (plist-get params :tstart))
(te (plist-get params :tend)) (te (plist-get params :tend))
(link (plist-get params :link))
(maxlevel (or (plist-get params :maxlevel) 3))
(ws (plist-get params :wstart)) (ws (plist-get params :wstart))
(ms (plist-get params :mstart)) (ms (plist-get params :mstart))
(step (plist-get params :step)) (step (plist-get params :step))
(timestamp (plist-get params :timestamp))
(formatter (or (plist-get params :formatter) (formatter (or (plist-get params :formatter)
org-clock-clocktable-formatter org-clock-clocktable-formatter
'org-clocktable-write-default)) 'org-clocktable-write-default))
cc range-text ipos pos one-file-with-archives cc ipos one-file-with-archives scope-is-list tbls level)
scope-is-list tbls level)
;; Check if we need to do steps ;; Check if we need to do steps
(when block (when block
;; Get the range text for the header ;; Get the range text for the header
(setq cc (org-clock-special-range block nil t ws ms) (setq cc (org-clock-special-range block nil t ws ms)
ts (car cc) te (nth 1 cc) range-text (nth 2 cc))) ts (car cc)
te (nth 1 cc)))
(when step (when step
;; Write many tables, in steps ;; Write many tables, in steps
(unless (or block (and ts te)) (unless (or block (and ts te))
@ -2393,7 +2385,6 @@ the currently selected interval size."
(setq ipos (point)) ; remember the insertion position (setq ipos (point)) ; remember the insertion position
;; Get the right scope ;; Get the right scope
(setq pos (point))
(cond (cond
((and scope (listp scope) (symbolp (car scope))) ((and scope (listp scope) (symbolp (car scope)))
(setq scope (eval scope))) (setq scope (eval scope)))
@ -2469,8 +2460,6 @@ from the dynamic block definition."
(multifile (plist-get params :multifile)) (multifile (plist-get params :multifile))
(block (plist-get params :block)) (block (plist-get params :block))
(sort (plist-get params :sort)) (sort (plist-get params :sort))
(ts (plist-get params :tstart))
(te (plist-get params :tend))
(header (plist-get params :header)) (header (plist-get params :header))
(narrow (plist-get params :narrow)) (narrow (plist-get params :narrow))
(ws (or (plist-get params :wstart) 1)) (ws (or (plist-get params :wstart) 1))
@ -2710,10 +2699,11 @@ LEVEL is an integer. Indent by two spaces per level above 1."
(step (cdr (assoc step0 '((day . 86400) (week . 604800))))) (step (cdr (assoc step0 '((day . 86400) (week . 604800)))))
(stepskip0 (plist-get p1 :stepskip0)) (stepskip0 (plist-get p1 :stepskip0))
(block (plist-get p1 :block)) (block (plist-get p1 :block))
cc range-text step-time tsb) cc step-time tsb)
(when block (when block
(setq cc (org-clock-special-range block nil t ws ms) (setq cc (org-clock-special-range block nil t ws ms)
ts (car cc) te (nth 1 cc) range-text (nth 2 cc))) ts (car cc)
te (nth 1 cc)))
(cond (cond
((numberp ts) ((numberp ts)
;; If ts is a number, it's an absolute day number from org-agenda. ;; If ts is a number, it's an absolute day number from org-agenda.
@ -2769,7 +2759,7 @@ file time (in minutes) as 1st and 2nd elements. The third element
of this list will be a list of headline entries. Each entry has the of this list will be a list of headline entries. Each entry has the
following structure: following structure:
(LEVEL HEADLINE TIMESTAMP TIME) \(LEVEL HEADLINE TIMESTAMP TIME)
LEVEL: The level of the headline, as an integer. This will be LEVEL: The level of the headline, as an integer. This will be
the reduced leve, so 1,2,3,... even if only odd levels the reduced leve, so 1,2,3,... even if only odd levels
@ -2793,14 +2783,14 @@ TIME: The sum of all time spend in this tree, in minutes. This time
(tags (plist-get params :tags)) (tags (plist-get params :tags))
(properties (plist-get params :properties)) (properties (plist-get params :properties))
(inherit-property-p (plist-get params :inherit-props)) (inherit-property-p (plist-get params :inherit-props))
todo-only (matcher (and tags (cdr (org-make-tags-matcher tags))))
(matcher (if tags (cdr (org-make-tags-matcher tags)))) cc st p time level hdl props tsp tbl)
cc range-text st p time level hdl props tsp tbl)
(setq org-clock-file-total-minutes nil) (setq org-clock-file-total-minutes nil)
(when block (when block
(setq cc (org-clock-special-range block nil t ws ms) (setq cc (org-clock-special-range block nil t ws ms)
ts (car cc) te (nth 1 cc) range-text (nth 2 cc))) ts (car cc)
te (nth 1 cc)))
(when (integerp ts) (setq ts (calendar-gregorian-from-absolute ts))) (when (integerp ts) (setq ts (calendar-gregorian-from-absolute ts)))
(when (integerp te) (setq te (calendar-gregorian-from-absolute te))) (when (integerp te) (setq te (calendar-gregorian-from-absolute te)))
(when (and ts (listp ts)) (when (and ts (listp ts))
@ -2997,11 +2987,10 @@ The details of what will be saved are regulated by the variable
;; load history ;; load history
(when stored-clock-history (when stored-clock-history
(save-window-excursion (save-window-excursion
(mapc (lambda (task) (dolist (task stored-clock-history)
(if (file-exists-p (car task)) (when (file-exists-p (car task))
(org-clock-history-push (cdr task) (org-clock-history-push (cdr task)
(find-file (car task))))) (find-file (car task)))))))
stored-clock-history)))
;; resume clock ;; resume clock
(when (and resume-clock org-clock-persist (when (and resume-clock org-clock-persist
(file-exists-p (car resume-clock)) (file-exists-p (car resume-clock))