Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 124 lines (99 sloc) 4.343 kb
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
;;; ne2wm-plugin-org-clock.el --- org-clock plugin

;; Copyright (C) 2012 Takafumi Arakaki

;; Author: Takafumi Arakaki
;; Keywords: tools, window manager

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;;; Code:

(require 'e2wm)

(eval-when-compile (require 'org nil t))
(declare-function org-get-heading "org")
(declare-function org-up-heading-safe "org")


(defvar ne2wm:c-plugin-org-clock-enable t
  "A customize variable to enable/disable org-clock plug-in globally.")


(defun ne2wm:def-plugin-org-clock (frame wm winfo)
  "Show clocked-in task and its ancestors

This plugin provides two things:
* Show task name in its mode line.
No buffer name, minor modes etc. to hide the task name.
* Show ancestors of the current task in the plugin buffer.
It makes the context of the current task clear.
"
  (let ((wname (wlf:window-name winfo))
        (buf (get-buffer-create " *WM:Org clock*"))
        (selected-wname (wlf:get-window-name wm (selected-window))))
    (with-current-buffer buf
      (setq truncate-lines t)
      (setq mode-line-format 'global-mode-string))
    (wlf:set-buffer wm wname buf)
    ;; show org-clock window
    (if (ne2wm:def-plugin-org-clock-clocking-p)
        (progn
          (ne2wm:def-plugin-org-clock-insert-tree buf)
          (wlf:show wm wname))
      (wlf:hide wm wname))
    ;; focus goes to org-clock window w/o the following explicit (re)select
    (when selected-wname
      (wlf:select wm selected-wname))))

(e2wm:plugin-register 'org-clock
                      "Org clock"
                      'ne2wm:def-plugin-org-clock)

(defun ne2wm:def-plugin-org-clock-clocking-p ()
  "ne2wm wrapper for `org-clocking-p'."
  (and ne2wm:c-plugin-org-clock-enable
       (fboundp 'org-clocking-p)
       (org-clocking-p)))

(defun ne2wm:def-plugin-org-clock-wname ()
  "Return t if current perspective uses org-clock plugin, nil otherwise"
  (let ((wm (when (e2wm:pst-get-instance) ; check if e2wm is active
              (e2wm:pst-get-wm))))
    (and wm
         ne2wm:c-plugin-org-clock-enable
         (loop for wname in (mapcar 'wlf:window-name (wlf:wset-winfo-list wm))
               if (eq 'org-clock (e2wm:pst-window-plugin-get wm wname))
               return wname))))

(defun ne2wm:def-plugin-org-clock-show ()
  "Show org-clock plugin if available"
  (e2wm:aif (ne2wm:def-plugin-org-clock-wname)
      (let ((wm (e2wm:pst-get-wm))
            (wname it))
        (ne2wm:def-plugin-org-clock-insert-tree (wlf:get-buffer wm wname))
        (wlf:show wm wname))))

(defun ne2wm:def-plugin-org-clock-hide ()
  "Hide org-clock plugin"
  (e2wm:aif (ne2wm:def-plugin-org-clock-wname)
      (wlf:hide (e2wm:pst-get-wm) it)))

(add-hook 'org-clock-in-hook 'ne2wm:def-plugin-org-clock-show)
(add-hook 'org-clock-out-hook 'ne2wm:def-plugin-org-clock-hide)

(defun ne2wm:def-plugin-org-clock-show-hide ()
  "Show org-clock plugin if clocking a task, hide otherwise"
  (if (ne2wm:def-plugin-org-clock-clocking-p)
      (ne2wm:def-plugin-org-clock-show)
    (ne2wm:def-plugin-org-clock-hide)))

(defun ne2wm:def-plugin-org-clock-insert-tree (buf)
  (let ((nodes nil))
    (save-excursion
      (with-current-buffer (marker-buffer org-clock-marker)
        (goto-char org-clock-marker)
        (push (org-get-heading) nodes)
        (while (org-up-heading-safe)
          (push (org-get-heading) nodes))))
    (save-excursion
      (with-current-buffer buf
        (erase-buffer)
        (loop for head in nodes
              for n from 1
              for stars = (mapconcat 'identity
                                     (loop for i from 1 to n collect "*") "")
              do (insert stars " " head "\n"))))))


(provide 'ne2wm-plugin-org-clock)
;;; ne2wm-plugin-org-clock.el ends here
Something went wrong with that request. Please try again.