| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
(require 'time-stamp) |
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 |
(defgroup todo nil |
|---|
| 267 |
"Maintain a list of todo items." |
|---|
| 268 |
:link '(emacs-commentary-link "todo-mode") |
|---|
| 269 |
:version "21.1" |
|---|
| 270 |
:group 'calendar) |
|---|
| 271 |
|
|---|
| 272 |
(defcustom todo-prefix "*/*" |
|---|
| 273 |
"*TODO mode prefix for entries. |
|---|
| 274 |
|
|---|
| 275 |
This is useful in conjunction with `calendar' and `diary' if you use |
|---|
| 276 |
|
|---|
| 277 |
#include \"~/.todo-do\" |
|---|
| 278 |
|
|---|
| 279 |
in your diary file to include your todo list file as part of your |
|---|
| 280 |
diary. With the default value \"*/*\" the diary displays each entry |
|---|
| 281 |
every day and it may also be marked on every day of the calendar. |
|---|
| 282 |
Using \"&%%(equal (calendar-current-date) date)\" instead will only |
|---|
| 283 |
show and mark todo entries for today, but may slow down processing of |
|---|
| 284 |
the diary file somewhat." |
|---|
| 285 |
:type 'string |
|---|
| 286 |
:group 'todo) |
|---|
| 287 |
(defcustom todo-file-do "~/.todo-do" |
|---|
| 288 |
"*TODO mode list file." |
|---|
| 289 |
:type 'file |
|---|
| 290 |
:group 'todo) |
|---|
| 291 |
(defcustom todo-file-done "~/.todo-done" |
|---|
| 292 |
"*TODO mode archive file." |
|---|
| 293 |
:type 'file |
|---|
| 294 |
:group 'todo) |
|---|
| 295 |
(defcustom todo-mode-hook nil |
|---|
| 296 |
"*TODO mode hooks." |
|---|
| 297 |
:type 'hook |
|---|
| 298 |
:group 'todo) |
|---|
| 299 |
(defcustom todo-edit-mode-hook nil |
|---|
| 300 |
"*TODO Edit mode hooks." |
|---|
| 301 |
:type 'hook |
|---|
| 302 |
:group 'todo) |
|---|
| 303 |
(defcustom todo-insert-threshold 0 |
|---|
| 304 |
"*TODO mode insertion accuracy. |
|---|
| 305 |
|
|---|
| 306 |
If you have 8 items in your TODO list, then you may get asked 4 |
|---|
| 307 |
questions by the binary insertion algorithm. However, you may not |
|---|
| 308 |
really have a need for such accurate priorities amongst your TODO |
|---|
| 309 |
items. If you now think about the binary insertion halving the size |
|---|
| 310 |
of the window each time, then the threshold is the window size at |
|---|
| 311 |
which it will stop. If you set the threshold to zero, the upper and |
|---|
| 312 |
lower bound will coincide at the end of the loop and you will insert |
|---|
| 313 |
your item just before that point. If you set the threshold to, |
|---|
| 314 |
e.g. 8, it will stop as soon as the window size drops below that |
|---|
| 315 |
amount and will insert the item in the approximate center of that |
|---|
| 316 |
window." |
|---|
| 317 |
:type 'integer |
|---|
| 318 |
:group 'todo) |
|---|
| 319 |
(defvar todo-edit-buffer " *TODO Edit*" |
|---|
| 320 |
"TODO Edit buffer name.") |
|---|
| 321 |
(defcustom todo-file-top "~/.todo-top" |
|---|
| 322 |
"*TODO mode top priorities file. |
|---|
| 323 |
|
|---|
| 324 |
Not in TODO format, but diary compatible. |
|---|
| 325 |
Automatically generated when `todo-save-top-priorities' is non-nil." |
|---|
| 326 |
:type 'string |
|---|
| 327 |
:group 'todo) |
|---|
| 328 |
|
|---|
| 329 |
(defcustom todo-print-function 'ps-print-buffer-with-faces |
|---|
| 330 |
"*Function to print the current buffer." |
|---|
| 331 |
:type 'symbol |
|---|
| 332 |
:group 'todo) |
|---|
| 333 |
(defcustom todo-show-priorities 1 |
|---|
| 334 |
"*Default number of priorities to show by \\[todo-top-priorities]. |
|---|
| 335 |
0 means show all entries." |
|---|
| 336 |
:type 'integer |
|---|
| 337 |
:group 'todo) |
|---|
| 338 |
(defcustom todo-print-priorities 0 |
|---|
| 339 |
"*Default number of priorities to print by \\[todo-print]. |
|---|
| 340 |
0 means print all entries." |
|---|
| 341 |
:type 'integer |
|---|
| 342 |
:group 'todo) |
|---|
| 343 |
(defcustom todo-remove-separator t |
|---|
| 344 |
"*Non-nil to remove category separators in\ |
|---|
| 345 |
\\[todo-top-priorities] and \\[todo-print]." |
|---|
| 346 |
:type 'boolean |
|---|
| 347 |
:group 'todo) |
|---|
| 348 |
(defcustom todo-save-top-priorities-too t |
|---|
| 349 |
"*Non-nil makes `todo-save' automatically save top-priorities in `todo-file-top'." |
|---|
| 350 |
:type 'boolean |
|---|
| 351 |
:group 'todo) |
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
(defcustom todo-time-string-format |
|---|
| 357 |
"%:y-%02m-%02d %02H:%02M" |
|---|
| 358 |
"*TODO mode time string format for done entries. |
|---|
| 359 |
For details see the variable `time-stamp-format'." |
|---|
| 360 |
:type 'string |
|---|
| 361 |
:group 'todo) |
|---|
| 362 |
|
|---|
| 363 |
(defcustom todo-entry-prefix-function 'todo-entry-timestamp-initials |
|---|
| 364 |
"*Function producing text to insert at start of todo entry." |
|---|
| 365 |
:type 'symbol |
|---|
| 366 |
:group 'todo) |
|---|
| 367 |
(defcustom todo-initials (or (getenv "INITIALS") (user-login-name)) |
|---|
| 368 |
"*Initials of todo item author." |
|---|
| 369 |
:type 'string |
|---|
| 370 |
:group 'todo) |
|---|
| 371 |
|
|---|
| 372 |
(defun todo-entry-timestamp-initials () |
|---|
| 373 |
"Prepend timestamp and your initials to the head of a TODO entry." |
|---|
| 374 |
(let ((time-stamp-format todo-time-string-format)) |
|---|
| 375 |
(concat (time-stamp-string) " " todo-initials ": "))) |
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
(defvar todo-categories nil |
|---|
| 382 |
"TODO categories.") |
|---|
| 383 |
|
|---|
| 384 |
(defvar todo-cats nil |
|---|
| 385 |
"Old variable for holding the TODO categories. |
|---|
| 386 |
Use `todo-categories' instead.") |
|---|
| 387 |
|
|---|
| 388 |
(defvar todo-previous-line 0 |
|---|
| 389 |
"Previous line asked about.") |
|---|
| 390 |
|
|---|
| 391 |
(defvar todo-previous-answer 0 |
|---|
| 392 |
"Previous answer got.") |
|---|
| 393 |
|
|---|
| 394 |
(defvar todo-mode-map |
|---|
| 395 |
(let ((map (make-keymap))) |
|---|
| 396 |
(suppress-keymap map t) |
|---|
| 397 |
(define-key map "+" 'todo-forward-category) |
|---|
| 398 |
(define-key map "-" 'todo-backward-category) |
|---|
| 399 |
(define-key map "d" 'todo-file-item) |
|---|
| 400 |
(define-key map "e" 'todo-edit-item) |
|---|
| 401 |
(define-key map "E" 'todo-edit-multiline) |
|---|
| 402 |
(define-key map "f" 'todo-file-item) |
|---|
| 403 |
(define-key map "i" 'todo-insert-item) |
|---|
| 404 |
(define-key map "I" 'todo-insert-item-here) |
|---|
| 405 |
(define-key map "j" 'todo-jump-to-category) |
|---|
| 406 |
(define-key map "k" 'todo-delete-item) |
|---|
| 407 |
(define-key map "l" 'todo-lower-item) |
|---|
| 408 |
(define-key map "n" 'todo-forward-item) |
|---|
| 409 |
(define-key map "p" 'todo-backward-item) |
|---|
| 410 |
(define-key map "P" 'todo-print) |
|---|
| 411 |
(define-key map "q" 'todo-quit) |
|---|
| 412 |
(define-key map "r" 'todo-raise-item) |
|---|
| 413 |
(define-key map "s" 'todo-save) |
|---|
| 414 |
(define-key map "S" 'todo-save-top-priorities) |
|---|
| 415 |
(define-key map "t" 'todo-top-priorities) |
|---|
| 416 |
map) |
|---|
| 417 |
"TODO mode keymap.") |
|---|
| 418 |
|
|---|
| 419 |
(defvar todo-category-number 0 "TODO category number.") |
|---|
| 420 |
|
|---|
| 421 |
(defvar todo-tmp-buffer-name " *todo tmp*") |
|---|
| 422 |
|
|---|
| 423 |
(defvar todo-category-sep (make-string 75 ?-) |
|---|
| 424 |
"Category separator.") |
|---|
| 425 |
|
|---|
| 426 |
(defvar todo-category-beg " --- " |
|---|
| 427 |
"Category start separator to be prepended onto category name.") |
|---|
| 428 |
|
|---|
| 429 |
(defvar todo-category-end "--- End" |
|---|
| 430 |
"Separator after a category.") |
|---|
| 431 |
|
|---|
| 432 |
(defvar todo-header "-*- mode: todo; " |
|---|
| 433 |
"Header of todo files.") |
|---|
| 434 |
|
|---|
| 435 |
|
|---|
| 436 |
|
|---|
| 437 |
(defun todo-category-select () |
|---|
| 438 |
"Make TODO mode display the current category correctly." |
|---|
| 439 |
(let ((name (nth todo-category-number todo-categories))) |
|---|
| 440 |
(setq mode-line-buffer-identification |
|---|
| 441 |
|
|---|
| 442 |
(concat "Category: " (format "%18s" name))) |
|---|
| 443 |
(widen) |
|---|
| 444 |
(goto-char (point-min)) |
|---|
| 445 |
(search-forward-regexp |
|---|
| 446 |
(concat "^" |
|---|
| 447 |
(regexp-quote (concat todo-prefix todo-category-beg name)) |
|---|
| 448 |
"$")) |
|---|
| 449 |
(let ((begin (1+ (line-end-position)))) |
|---|
| 450 |
(search-forward-regexp (concat "^" todo-category-end)) |
|---|
| 451 |
(narrow-to-region begin (line-beginning-position)) |
|---|
| 452 |
(goto-char (point-min))))) |
|---|
| 453 |
(defalias 'todo-cat-slct 'todo-category-select) |
|---|
| 454 |
|
|---|
| 455 |
(defun todo-forward-category () |
|---|
| 456 |
"Go forward to TODO list of next category." |
|---|
| 457 |
(interactive) |
|---|
| 458 |
(setq todo-category-number |
|---|
| 459 |
(mod (1+ todo-category-number) (length todo-categories))) |
|---|
| 460 |
(todo-category-select)) |
|---|
| 461 |
(defalias 'todo-cmd-forw 'todo-forward-category) |
|---|
| 462 |
|
|---|
| 463 |
(defun todo-backward-category () |
|---|
| 464 |
"Go back to TODO list of previous category." |
|---|
| 465 |
(interactive) |
|---|
| 466 |
(setq todo-category-number |
|---|
| 467 |
(mod (1- todo-category-number) (length todo-categories))) |
|---|
| 468 |
(todo-category-select)) |
|---|
| 469 |
(defalias 'todo-cmd-back 'todo-backward-category) |
|---|
| 470 |
|
|---|
| 471 |
(defun todo-backward-item () |
|---|
| 472 |
"Select previous entry of TODO list." |
|---|
| 473 |
(interactive) |
|---|
| 474 |
(search-backward-regexp (concat "^" (regexp-quote todo-prefix)) nil t) |
|---|
| 475 |
(message "")) |
|---|
| 476 |
(defalias 'todo-cmd-prev 'todo-backward-item) |
|---|
| 477 |
|
|---|
| 478 |
(defun todo-forward-item (&optional count) |
|---|
| 479 |
"Select COUNT-th next entry of TODO list." |
|---|
| 480 |
(interactive "P") |
|---|
| 481 |
(if (listp count) (setq count (car count))) |
|---|
| 482 |
(end-of-line) |
|---|
| 483 |
(search-forward-regexp (concat "^" (regexp-quote todo-prefix)) |
|---|
| 484 |
nil 'goto-end count) |
|---|
| 485 |
(beginning-of-line) |
|---|
| 486 |
(message "")) |
|---|
| 487 |
(defalias 'todo-cmd-next 'todo-forward-item) |
|---|
| 488 |
|
|---|
| 489 |
(defun todo-save () |
|---|
| 490 |
"Save the TODO list." |
|---|
| 491 |
(interactive) |
|---|
| 492 |
(save-excursion |
|---|
| 493 |
(save-restriction |
|---|
| 494 |
(save-buffer))) |
|---|
| 495 |
(if todo-save-top-priorities-too (todo-save-top-priorities))) |
|---|
| 496 |
(defalias 'todo-cmd-save 'todo-save) |
|---|
| 497 |
|
|---|
| 498 |
(defun todo-quit () |
|---|
| 499 |
"Done with TODO list for now." |
|---|
| 500 |
(interactive) |
|---|
| 501 |
(widen) |
|---|
| 502 |
(todo-save) |
|---|
| 503 |
(message "") |
|---|
| 504 |
(bury-buffer)) |
|---|
| 505 |
(defalias 'todo-cmd-done 'todo-quit) |
|---|
| 506 |
|
|---|
| 507 |
(defun todo-edit-item () |
|---|
| 508 |
"Edit current TODO list entry." |
|---|
| 509 |
(interactive) |
|---|
| 510 |
(let ((item (todo-item-string))) |
|---|
| 511 |
(if (todo-string-multiline-p item) |
|---|
| 512 |
(todo-edit-multiline) |
|---|
| 513 |
(let ((new (read-from-minibuffer "Edit: " item))) |
|---|
| 514 |
(todo-remove-item) |
|---|
| 515 |
(insert new "\n") |
|---|
| 516 |
(todo-backward-item) |
|---|
| 517 |
(message ""))))) |
|---|
| 518 |
(defalias 'todo-cmd-edit 'todo-edit-item) |
|---|
| 519 |
|
|---|
| 520 |
(defun todo-edit-multiline () |
|---|
| 521 |
"Set up a buffer for editing a multiline TODO list entry." |
|---|
| 522 |
(interactive) |
|---|
| 523 |
(let ((buffer-name (generate-new-buffer-name todo-edit-buffer))) |
|---|
| 524 |
(switch-to-buffer |
|---|
| 525 |
(make-indirect-buffer |
|---|
| 526 |
(file-name-nondirectory todo-file-do) buffer-name)) |
|---|
| 527 |
(message "To exit, simply kill this buffer and return to list.") |
|---|
| 528 |
(todo-edit-mode) |
|---|
| 529 |
(narrow-to-region (todo-item-start) (todo-item-end)))) |
|---|
| 530 |
|
|---|
| 531 |
|
|---|
| 532 |
(defun todo-add-category (cat) |
|---|
| 533 |
"Add new category CAT to the TODO list." |
|---|
| 534 |
(interactive "sCategory: ") |
|---|
| 535 |
(save-window-excursion |
|---|
| 536 |
(setq todo-categories (cons cat todo-categories)) |
|---|
| 537 |
(find-file todo-file-do) |
|---|
| 538 |
(widen) |
|---|
| 539 |
(goto-char (point-min)) |
|---|
| 540 |
(let ((posn (search-forward "-*- mode: todo; " 17 t))) |
|---|
| 541 |
(if (not (null posn)) (goto-char posn)) |
|---|
| 542 |
(if (equal posn nil) |
|---|
| 543 |
(progn |
|---|
| 544 |
(insert "-*- mode: todo; \n") |
|---|
| 545 |
(forward-char -1)) |
|---|
| 546 |
(kill-line))) |
|---|
| 547 |
(insert (format "todo-categories: %S; -*-" todo-categories)) |
|---|
| 548 |
(forward-char 1) |
|---|
| 549 |
(insert (format "%s%s%s\n%s\n%s %s\n" |
|---|
| 550 |
todo-prefix todo-category-beg cat |
|---|
| 551 |
todo-category-end |
|---|
| 552 |
todo-prefix todo-category-sep))) |
|---|
| 553 |
0) |
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 |
(defun todo-add-item-non-interactively (new-item category) |
|---|
| 557 |
"Insert NEW-ITEM in TODO list as a new entry in CATEGORY." |
|---|
| 558 |
(save-excursion |
|---|
| 559 |
(todo-show)) |
|---|
| 560 |
(save-excursion |
|---|
| 561 |
(if (string= "" category) |
|---|
| 562 |
(setq category (nth todo-category-number todo-categories))) |
|---|
| 563 |
(let ((cat-exists (member category todo-categories))) |
|---|
| 564 |
(setq todo-category-number |
|---|
| 565 |
(if cat-exists |
|---|
| 566 |
(- (length todo-categories) (length cat-exists)) |
|---|
| 567 |
(todo-add-category category)))) |
|---|
| 568 |
(todo-show) |
|---|
| 569 |
(setq todo-previous-line 0) |
|---|
| 570 |
(let ((top 1) |
|---|
| 571 |
(bottom (1+ (count-lines (point-min) (point-max))))) |
|---|
| 572 |
(while (> (- bottom top) todo-insert-threshold) |
|---|
| 573 |
(let* ((current (/ (+ top bottom) 2)) |
|---|
| 574 |
(answer (if (< current bottom) |
|---|
| 575 |
(todo-more-important-p current) nil))) |
|---|
| 576 |
(if answer |
|---|
| 577 |
(setq bottom current) |
|---|
| 578 |
(setq top (1+ current))))) |
|---|
| 579 |
(setq top (/ (+ top bottom) 2)) |
|---|
| 580 |
|
|---|
| 581 |
(goto-char (point-min)) |
|---|
| 582 |
(forward-line (1- top))) |
|---|
| 583 |
(insert new-item "\n") |
|---|
| 584 |
(todo-backward-item) |
|---|
| 585 |
(todo-save) |
|---|
| 586 |
(message ""))) |
|---|
| 587 |
|
|---|
| 588 |
|
|---|
| 589 |
(defun todo-insert-item (arg) |
|---|
| 590 |
"Insert new TODO list entry. |
|---|
| 591 |
With a prefix argument solicit the category, otherwise use the current |
|---|
| 592 |
category." |
|---|
| 593 |
(interactive "P") |
|---|
| 594 |
(save-excursion |
|---|
| 595 |
(if (not (string-equal mode-name "TODO")) (todo-show)) |
|---|
| 596 |
(let* ((new-item (concat todo-prefix " " |
|---|
| 597 |
(read-from-minibuffer |
|---|
| 598 |
"New TODO entry: " |
|---|
| 599 |
(if todo-entry-prefix-function |
|---|
| 600 |
(funcall todo-entry-prefix-function))))) |
|---|
| 601 |
(categories todo-categories) |
|---|
| 602 |
(history (cons 'categories (1+ todo-category-number))) |
|---|
| 603 |
(current-category (nth todo-category-number todo-categories)) |
|---|
| 604 |
(category |
|---|
| 605 |
(if arg |
|---|
| 606 |
current-category |
|---|
| 607 |
(completing-read (concat "Category [" current-category "]: ") |
|---|
| 608 |
(todo-category-alist) nil nil nil |
|---|
| 609 |
history current-category)))) |
|---|
| 610 |
(todo-add-item-non-interactively new-item category)))) |
|---|
| 611 |
|
|---|
| 612 |
(defalias 'todo-cmd-inst 'todo-insert-item) |
|---|
| 613 |
|
|---|
| 614 |
(defun todo-insert-item-here () |
|---|
| 615 |
"Insert new TODO list entry under the cursor." |
|---|
| 616 |
(interactive "") |
|---|
| 617 |
(save-excursion |
|---|
| 618 |
(if (not (string-equal mode-name "TODO")) (todo-show)) |
|---|
| 619 |
(let* ((new-item (concat todo-prefix " " |
|---|
| 620 |
(read-from-minibuffer |
|---|
| 621 |
"New TODO entry: " |
|---|
| 622 |
(if todo-entry-prefix-function |
|---|
| 623 |
(funcall todo-entry-prefix-function)))))) |
|---|
| 624 |
(insert (concat new-item "\n"))))) |
|---|
| 625 |
|
|---|
| 626 |
(defun todo-more-important-p (line) |
|---|
| 627 |
"Ask whether entry is more important than the one at LINE." |
|---|
| 628 |
(if (not (equal todo-previous-line line)) |
|---|
| 629 |
(progn |
|---|
| 630 |
(setq todo-previous-line line) |
|---|
| 631 |
(goto-char (point-min)) |
|---|
| 632 |
(forward-line (1- todo-previous-line)) |
|---|
| 633 |
(let ((item (todo-item-string-start))) |
|---|
| 634 |
(setq todo-previous-answer |
|---|
| 635 |
(y-or-n-p (concat "More important than '" item "'? ")))))) |
|---|
| 636 |
todo-previous-answer) |
|---|
| 637 |
(defalias 'todo-ask-p 'todo-more-important-p) |
|---|
| 638 |
|
|---|
| 639 |
(defun todo-delete-item () |
|---|
| 640 |
"Delete current TODO list entry." |
|---|
| 641 |
(interactive) |
|---|
| 642 |
(if (> (count-lines (point-min) (point-max)) 0) |
|---|
| 643 |
(let* ((todo-entry (todo-item-string-start)) |
|---|
| 644 |
(todo-answer (y-or-n-p (concat "Permanently remove '" |
|---|
| 645 |
todo-entry "'? ")))) |
|---|
| 646 |
(if todo-answer |
|---|
| 647 |
(progn |
|---|
| 648 |
(todo-remove-item) |
|---|
| 649 |
(todo-backward-item))) |
|---|
| 650 |
(message "")) |
|---|
| 651 |
(error "No TODO list entry to delete"))) |
|---|
| 652 |
(defalias 'todo-cmd-kill 'todo-delete-item) |
|---|
| 653 |
|
|---|
| 654 |
(defun todo-raise-item () |
|---|
| 655 |
"Raise priority of current entry." |
|---|
| 656 |
(interactive) |
|---|
| 657 |
(if (> (count-lines (point-min) (point)) 0) |
|---|
| 658 |
(let ((item (todo-item-string))) |
|---|
| 659 |
(todo-remove-item) |
|---|
| 660 |
(todo-backward-item) |
|---|
| 661 |
(save-excursion |
|---|
| 662 |
(insert item "\n")) |
|---|
| 663 |
(message "")) |
|---|
| 664 |
(error "No TODO list entry to raise"))) |
|---|
| 665 |
(defalias 'todo-cmd-rais 'todo-raise-item) |
|---|
| 666 |
|
|---|
| 667 |
(defun todo-lower-item () |
|---|
| 668 |
"Lower priority of current entry." |
|---|
| 669 |
(interactive) |
|---|
| 670 |
(if (> (count-lines (point) (point-max)) 1) |
|---|
| 671 |
|
|---|
| 672 |
(let ((item (todo-item-string))) |
|---|
| 673 |
(todo-remove-item) |
|---|
| 674 |
(todo-forward-item) |
|---|
| 675 |
(save-excursion |
|---|
| 676 |
(insert item "\n")) |
|---|
| 677 |
(message "")) |
|---|
| 678 |
(error "No TODO list entry to lower"))) |
|---|
| 679 |
(defalias 'todo-cmd-lowr 'todo-lower-item) |
|---|
| 680 |
|
|---|
| 681 |
(defun todo-file-item (&optional comment) |
|---|
| 682 |
"File the current TODO list entry away, annotated with an optional COMMENT." |
|---|
| 683 |
(interactive "sComment: ") |
|---|
| 684 |
(or (> (count-lines (point-min) (point-max)) 0) |
|---|
| 685 |
(error "No TODO list entry to file away")) |
|---|
| 686 |
(let ((time-stamp-format todo-time-string-format)) |
|---|
| 687 |
(if (and comment (> (length comment) 0)) |
|---|
| 688 |
(progn |
|---|
| 689 |
(goto-char (todo-item-end)) |
|---|
| 690 |
(insert |
|---|
| 691 |
(if (save-excursion (beginning-of-line) |
|---|
| 692 |
(looking-at (regexp-quote todo-prefix))) |
|---|
| 693 |
" " |
|---|
| 694 |
"\n\t") |
|---|
| 695 |
"(" comment ")"))) |
|---|
| 696 |
(goto-char (todo-item-end)) |
|---|
| 697 |
(insert " [" (nth todo-category-number todo-categories) "]") |
|---|
| 698 |
(goto-char (todo-item-start)) |
|---|
| 699 |
(let ((temp-point (point))) |
|---|
| 700 |
(if (looking-at (regexp-quote todo-prefix)) |
|---|
| 701 |
(replace-match (time-stamp-string)) |
|---|
| 702 |
|
|---|
| 703 |
|
|---|
| 704 |
(insert (time-stamp-string))) |
|---|
| 705 |
(append-to-file temp-point (1+ (todo-item-end)) todo-file-done) |
|---|
| 706 |
(delete-region temp-point (1+ (todo-item-end)))) |
|---|
| 707 |
(todo-backward-item) |
|---|
| 708 |
(message ""))) |
|---|
| 709 |
|
|---|
| 710 |
|
|---|
| 711 |
|
|---|
| 712 |
|
|---|
| 713 |
|
|---|
| 714 |
|
|---|
| 715 |
|
|---|
| 716 |
(defun todo-top-priorities (&optional nof-priorities category-pr-page) |
|---|
| 717 |
"List top priorities for each category. |
|---|
| 718 |
|
|---|
| 719 |
Number of entries for each category is given by NOF-PRIORITIES which |
|---|
| 720 |
defaults to \'todo-show-priorities\'. |
|---|
| 721 |
|
|---|
| 722 |
If CATEGORY-PR-PAGE is non-nil, a page separator \'^L\' is inserted |
|---|
| 723 |
between each category." |
|---|
| 724 |
|
|---|
| 725 |
(interactive "P") |
|---|
| 726 |
(or nof-priorities (setq nof-priorities todo-show-priorities)) |
|---|
| 727 |
(if (listp nof-priorities) |
|---|
| 728 |
(setq nof-priorities (car nof-priorities))) |
|---|
| 729 |
(let ((todo-print-buffer-name todo-tmp-buffer-name) |
|---|
| 730 |
|
|---|
| 731 |
(todo-category-break (if category-pr-page "" "")) |
|---|
| 732 |
(cat-end |
|---|
| 733 |
(concat |
|---|
| 734 |
(if todo-remove-separator |
|---|
| 735 |
(concat todo-category-end "\n" |
|---|
| 736 |
(regexp-quote todo-prefix) " " todo-category-sep "\n") |
|---|
| 737 |
(concat todo-category-end "\n")))) |
|---|
| 738 |
beg end) |
|---|
| 739 |
(todo-show) |
|---|
| 740 |
(save-excursion |
|---|
| 741 |
(save-restriction |
|---|
| 742 |
(widen) |
|---|
| 743 |
(copy-to-buffer todo-print-buffer-name (point-min) (point-max)) |
|---|
| 744 |
(set-buffer todo-print-buffer-name) |
|---|
| 745 |
(goto-char (point-min)) |
|---|
| 746 |
(when (re-search-forward (regexp-quote todo-header) nil t) |
|---|
| 747 |
(beginning-of-line 1) |
|---|
| 748 |
(delete-region (point) (line-end-position))) |
|---|
| 749 |
(while (re-search-forward |
|---|
| 750 |
(regexp-quote (concat todo-prefix todo-category-beg)) |
|---|
| 751 |
nil t) |
|---|
| 752 |
(setq beg (+ (line-end-position) 1)) |
|---|
| 753 |
(re-search-forward cat-end nil t) |
|---|
| 754 |
(setq end (match-beginning 0)) |
|---|
| 755 |
(replace-match todo-category-break) |
|---|
| 756 |
(narrow-to-region beg end) |
|---|
| 757 |
(goto-char (point-min)) |
|---|
| 758 |
(if (= 0 nof-priorities) |
|---|
| 759 |
(goto-char end) |
|---|
| 760 |
(todo-forward-item nof-priorities)) |
|---|
| 761 |
(setq beg (point)) |
|---|
| 762 |
(delete-region beg end) |
|---|
| 763 |
(widen)) |
|---|
| 764 |
(and (looking-at "") (replace-match "")) |
|---|
| 765 |
(goto-char (point-min)) |
|---|
| 766 |
)) |
|---|
| 767 |
|
|---|
| 768 |
|
|---|
| 769 |
|
|---|
| 770 |
(display-buffer todo-print-buffer-name) |
|---|
| 771 |
(message "Type C-x 1 to remove %s window. M-C-v to scroll the help." |
|---|
| 772 |
todo-print-buffer-name))) |
|---|
| 773 |
|
|---|
| 774 |
(defun todo-save-top-priorities (&optional nof-priorities) |
|---|
| 775 |
"Save top priorities for each category in `todo-file-top'. |
|---|
| 776 |
|
|---|
| 777 |
Number of entries for each category is given by NOF-PRIORITIES which |
|---|
| 778 |
|
|---|