Changeset main,5


Ignore:
Timestamp:
04/29/2020 11:22:23 PM (4 years ago)
Author:
David Owen <dsowen@…>
branch-nick:
org-autofocus
revision id:
dsowen@fugue88.ws-20200429232223-serz3bz90crxlspb
Message:

Initial minor mode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/org-autofocus.el

    r4 r5  
    1818
    1919
    20 (defvar-local org-af--ewoc nil)
     20(defun org-af-mark ()
     21  "Mark or unmark the current task."
     22  (interactive)
     23  (save-excursion
     24    (let ((inhibit-read-only t)
     25          (props '(org-af-marked t display "*"))
     26          bol)
     27      (beginning-of-line)
     28      (setq bol (point))
     29      (funcall (if (get-text-property bol 'org-af-marked)
     30                   'remove-list-of-text-properties
     31                 'add-text-properties)
     32               bol (1+ bol) props))))
    2133
    2234
    23 (defclass org-af--task ()
    24   ((org :initarg :org)
    25    (marked :initform nil)
    26    (passed :initform nil)))
     35(defvar org-autofocus-mode-map (make-sparse-keymap))
     36(define-key org-autofocus-mode-map "." 'org-af-mark)
    2737
    2838
    29 (defun org-af--pp (obj)
    30   "Print the task OBJ in the current buffer at point."
    31   (with-slots (org marked passed) obj
    32     (when (or marked (not passed))
    33       (insert (if marked "*" " ")
    34               " "
    35               (if passed
    36                   (propertize org 'face 'org-agenda-dimmed-todo-face)
    37                 org)
    38               "\n"))))
     39(define-minor-mode org-autofocus-mode nil nil " AF" org-autofocus-mode-map
     40  nil)
    3941
    4042
    41 (define-derived-mode org-autofocus-mode special-mode "Org AF" nil
    42   (let ((inhibit-read-only t)
    43         (date (calendar-current-date))
    44         tasks)
    45     (setq buffer-undo-list t)
    46 
    47     (dolist (f (org-agenda-files))
    48       (catch 'nextfile
    49         (org-check-agenda-file f)
    50         (setq tasks (nconc (org-agenda-get-day-entries f date :todo) tasks))))
    51 
    52     (setq org-af--ewoc (ewoc-create 'org-af--pp "header\n" "footer\n" t))
    53     (dolist (task tasks)
    54       (ewoc-enter-last org-af--ewoc (make-instance 'org-af--task :org task)))))
     43;; (defvar-local org-af--ewoc nil)
    5544
    5645
    57 (defun org-af--mark ()
    58   "Toggle whether the task at point is marked."
    59   (interactive)
    60   (let* ((node (ewoc-locate org-af--ewoc))
    61          (obj (ewoc-data node))
    62          changed)
    63     (unless (slot-value obj 'passed)
    64       (let ((marked (not (slot-value obj 'marked))))
    65         (setf (slot-value obj 'marked) marked)
    66         (push node changed)
    67         (let ((node node))
    68           (while (and (setf node (ewoc-prev org-af--ewoc node))
    69                       (setf obj (ewoc-data node))
    70                       (not (slot-value obj 'marked)))
    71             (setf (slot-value obj 'passed) marked)
    72             (push node changed))
    73           (when node
    74             (setf (slot-value obj 'passed) marked)
    75             (push node changed))))
    76       (apply 'ewoc-invalidate org-af--ewoc changed)
    77       (ewoc-goto-node org-af--ewoc node))))
     46;; (defclass org-af--task ()
     47;;   ((org :initarg :org)
     48;;    (marked :initform nil)
     49;;    (passed :initform nil)))
    7850
    7951
    80 (define-key org-autofocus-mode-map "." 'org-af--mark)
     52;; (defun org-af--pp (obj)
     53;;   "Print the task OBJ in the current buffer at point."
     54;;   (with-slots (org marked passed) obj
     55;;     (when (or marked (not passed))
     56;;       (insert (if marked "*" " ")
     57;;               " "
     58;;               (if passed
     59;;                   (propertize org 'face 'org-agenda-dimmed-todo-face)
     60;;                 org)
     61;;               "\n"))))
    8162
    8263
    83 ;;;###autoload
    84 (defun org-autofocus ()
    85   "Show the AutoFocus buffer; create it if necessary."
    86   (interactive)
    87   (pop-to-buffer (get-buffer-create "*Org AutoFocus*"))
    88   (org-autofocus-mode))
     64;; (define-derived-mode org-autofocus-mode special-mode "Org AF" nil
     65;;   (let ((inhibit-read-only t)
     66;;         (date (calendar-current-date))
     67;;         tasks)
     68;;     (setq buffer-undo-list t)
     69
     70;;     (dolist (f (org-agenda-files))
     71;;       (catch 'nextfile
     72;;      (org-check-agenda-file f)
     73;;      (setq tasks (nconc (org-agenda-get-day-entries f date :todo) tasks))))
     74
     75;;     (setq org-af--ewoc (ewoc-create 'org-af--pp "header\n" "footer\n" t))
     76;;     (dolist (task tasks)
     77;;       (ewoc-enter-last org-af--ewoc (make-instance 'org-af--task :org task)))))
     78
     79
     80;; (defun org-af--mark ()
     81;;   "Toggle whether the task at point is marked."
     82;;   (interactive)
     83;;   (let* ((node (ewoc-locate org-af--ewoc))
     84;;          (obj (ewoc-data node))
     85;;          changed)
     86;;     (unless (slot-value obj 'passed)
     87;;       (let ((marked (not (slot-value obj 'marked))))
     88;;         (setf (slot-value obj 'marked) marked)
     89;;         (push node changed)
     90;;         (let ((node node))
     91;;           (while (and (setf node (ewoc-prev org-af--ewoc node))
     92;;                       (setf obj (ewoc-data node))
     93;;                       (not (slot-value obj 'marked)))
     94;;             (setf (slot-value obj 'passed) marked)
     95;;             (push node changed))
     96;;           (when node
     97;;             (setf (slot-value obj 'passed) marked)
     98;;             (push node changed))))
     99;;       (apply 'ewoc-invalidate org-af--ewoc changed)
     100;;       (ewoc-goto-node org-af--ewoc node))))
     101
     102
     103;; (defun org-af--complete ()
     104;;   "Complete the task at point, if it's marked and not passed over."
     105;;   (interactive)
     106;;   (let* ((node (ewoc-locate org-af--ewoc))
     107;;          (obj (ewoc-data node)))
     108;;     (unless (and nil (or (slot-value obj 'passed)
     109;;                 (not (slot-value obj 'marked))))
     110;;       (org-agenda-todo)
     111;;       (org-autofocus-mode))))
     112
     113
     114;; (define-key org-autofocus-mode-map "." 'org-af--mark)
     115;; (define-key org-autofocus-mode-map "c" 'org-af--complete)
     116
     117
     118;; ;;;###autoload
     119;; (defun org-autofocus ()
     120;;   "Show the AutoFocus buffer; create it if necessary."
     121;;   (interactive)
     122;;   (pop-to-buffer (get-buffer-create "*Org AutoFocus*"))
     123;;   (org-autofocus-mode))
    89124
    90125
Note: See TracChangeset for help on using the changeset viewer.