Changeset main,11
- Timestamp:
- 05/02/2020 07:24:14 PM (5 years ago)
- branch-nick:
- org-autofocus
- revision id:
- dsowen@fugue88.ws-20200502192414-lt1ompx7s4kk4qf2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/org-autofocus.el
r10 r11 101 101 102 102 103 (defun org-af--timestamp () 104 "Return the current local time, with nanoseconds, formatted as an ISO string." 105 (format-time-string "%Y-%m-%d %H:%M:%S.%N" (current-time))) 106 107 108 (defun org-af-defer (&optional no-redisplay) 109 "Defer the current task and update the display, unless NO-REDISPLAY." 110 (interactive) 111 (org-af--beg-of-task) 112 (if (org-af--dimmed-p (point)) 113 (message "dimmed; skipping") 114 (when (org-af--marked-p (point)) 115 (org-af-mark)) 116 117 ;; This comes from the guts of the org-agenda-set-property command. 118 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker) 119 (org-agenda-error))) 120 (buffer (marker-buffer hdmarker)) 121 (pos (marker-position hdmarker)) 122 (inhibit-read-only t) 123 (time (org-af--timestamp))) 124 (org-with-remote-undo buffer 125 (with-current-buffer buffer 126 (widen) 127 (goto-char pos) 128 (org-show-context 'agenda) 129 (org-set-property "TOUCHED" time)))) 130 131 (save-excursion 132 (let* ((inhibit-read-only t) 133 (text (delete-and-extract-region (point) 134 (1+ (line-end-position))))) 135 (goto-char (point-max)) 136 (save-excursion 137 (insert text)))))) 138 139 140 (defun org-af-complete () 141 (interactive) 142 (org-af--beg-of-task) 143 (when (org-af--marked-p (point)) 144 (org-af-mark)) 145 (org-agenda-todo) 146 (org-af-defer t)) 147 148 103 149 (defvar org-autofocus-mode-map (make-sparse-keymap)) 104 150 (define-key org-autofocus-mode-map "." 'org-af-mark) 151 (define-key org-autofocus-mode-map "d" 'org-af-defer) 152 (define-key org-autofocus-mode-map "c" 'org-af-complete) 153 (define-key org-autofocus-mode-map "t" 'org-af-complete) 154 155 156 (defun org-af--touched (entry) 157 (let* ((marker (get-text-property 0 'org-hd-marker entry)) 158 (touched (org-entry-get marker "TOUCHED"))) 159 (unless touched 160 (setq touched (org-af--timestamp)) 161 (org-entry-put marker "TOUCHED" touched)) 162 touched)) 163 164 165 (defun org-af--cmp (a b) 166 "Compare A to B. 167 If A > B, return +1; if A < B, return -1; else, return NIL." 168 (let* ((a-touched (org-af--touched a)) 169 (b-touched (org-af--touched b)) 170 (c (compare-strings a-touched nil nil b-touched nil nil))) 171 (cond 172 ((eq c t) nil) 173 ((< c 0) -1) 174 ((> c 0) +1) 175 (t (error "%S and %S compared as %S" a-touched b-touched c))))) 105 176 106 177 107 178 (define-minor-mode org-autofocus-mode nil nil " AF" org-autofocus-mode-map 108 nil) 179 ;;(setq org-agenda-redo-command '(org-autofocus)) 180 ) 181 182 183 (defun org-autofocus () 184 (interactive) 185 (let ((org-agenda-cmp-user-defined 'org-af--cmp) 186 (org-agenda-sorting-strategy '(user-defined-up))) 187 (org-agenda nil "n") 188 (org-autofocus-mode))) 189 190 191 (add-hook 'org-agenda-mode-hook 'org-autofocus-mode) 192 (remove-hook 'org-agenda-mode-hook 'org-autofocus-mode) 109 193 110 194
Note: See TracChangeset
for help on using the changeset viewer.