emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Option for clock and timer to be displayed in frame-title
@ 2012-02-28 21:44 g.kettleborough
  2012-02-28 22:51 ` Bernt Hansen
  2012-04-23 13:12 ` Bastien
  0 siblings, 2 replies; 11+ messages in thread
From: g.kettleborough @ 2012-02-28 21:44 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 484 bytes --]

Attached is a patch that gives the option to show the clock and timer
information in the frame title as well as the mode line (or both or
neither).  I find this useful as there is often not enough room in the
mode line but there is enough in the frame title.

I am in the process of assigning my copyright to the FSF for this and
hopefully future org-mode contributions.  I submit the patch now and
request comments as this is my first contribution to the project.

Thanks,

George.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Patch --]
[-- Type: text/x-diff, Size: 7625 bytes --]

From 3e29d48fb34e51a81544b1734dd75207c943d567 Mon Sep 17 00:00:00 2001
From: George Kettleborough <g.kettleborough@member.fsf.org>
Date: Tue, 28 Feb 2012 00:51:10 +0000
Subject: [PATCH] Option for clock and timer to be displayed in frame-title

---
 lisp/org-clock.el |   43 +++++++++++++++++++++++++++++++++++--------
 lisp/org-timer.el |   43 +++++++++++++++++++++++++++++++++++--------
 2 files changed, 70 insertions(+), 16 deletions(-)

diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 9206608..1a800b6 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -323,6 +323,15 @@ play with them."
   :version "24.1"
   :type 'boolean)
 
+(defcustom org-clock-clocked-in-display 'mode-line
+  "Where should the clocked in status be displayed."
+  :group 'org-clock
+  :type '(choice
+	  (const :tag "Mode line" mode-line)
+	  (const :tag "Frame title" frame-title)
+	  (const :tag "Both" both)
+	  (const :tag "None" nil)))
+
 (defvar org-clock-in-prepare-hook nil
   "Hook run when preparing the clock.
 This hook is run before anything happens to the task that
@@ -1170,18 +1179,28 @@ the clocking selection, associated with the letter `d'."
 			 (save-excursion (org-back-to-heading t) (point))
 			 (buffer-base-buffer))
 	    (setq org-clock-has-been-used t)
-	    (or global-mode-string (setq global-mode-string '("")))
-	    (or (memq 'org-mode-line-string global-mode-string)
-		(setq global-mode-string
-		      (append global-mode-string '(org-mode-line-string))))
+	    ;; add to mode line
+	    (when (or (eq org-clock-clocked-in-display 'mode-line)
+		      (eq org-clock-clocked-in-display 'both))
+	      (or global-mode-string (setq global-mode-string '("")))
+	      (or (memq 'org-mode-line-string global-mode-string)
+		  (setq global-mode-string
+			(append global-mode-string '(org-mode-line-string)))))
+	    ;; add to frame title
+	    (when (or (eq org-clock-clocked-in-display 'frame-title)
+		      (eq org-clock-clocked-in-display 'both))
+	      (or (memq 'org-mode-line-string frame-title-format)
+		  (setq frame-title-format
+			(append frame-title-format '(" " org-mode-line-string)))))
 	    (org-clock-update-mode-line)
 	    (when org-clock-mode-line-timer
 	      (cancel-timer org-clock-mode-line-timer)
 	      (setq org-clock-mode-line-timer nil))
-	    (setq org-clock-mode-line-timer
-		  (run-with-timer org-clock-update-period
-				  org-clock-update-period
-				  'org-clock-update-mode-line))
+	    (when org-clock-clocked-in-display
+	      (setq org-clock-mode-line-timer
+		    (run-with-timer org-clock-update-period
+				    org-clock-update-period
+				    'org-clock-update-mode-line)))
 	    (when org-clock-idle-timer
 	      (cancel-timer org-clock-idle-timer)
 	      (setq org-clock-idle-timer nil))
@@ -1329,6 +1348,8 @@ If there is no running clock, throw an error, unless FAIL-QUIETLY is set."
     (when (not (org-clocking-p))
       (setq global-mode-string
 	    (delq 'org-mode-line-string global-mode-string))
+      (setq frame-title-format
+	    (delq 'org-mode-line-string frame-title-format))
       (force-mode-line-update)
       (if fail-quietly (throw 'exit t) (error "No active clock")))
     (let (ts te s h m remove)
@@ -1373,6 +1394,8 @@ If there is no running clock, throw an error, unless FAIL-QUIETLY is set."
 	    (setq org-clock-idle-timer nil))
 	  (setq global-mode-string
 		(delq 'org-mode-line-string global-mode-string))
+	  (setq frame-title-format
+		(delq 'org-mode-line-string frame-title-format))
 	  (when org-clock-out-switch-to-state
 	    (save-excursion
 	      (org-back-to-heading t)
@@ -1472,6 +1495,8 @@ UPDOWN tells whether to change 'up or 'down."
   (when (not (org-clocking-p))
     (setq global-mode-string
          (delq 'org-mode-line-string global-mode-string))
+    (setq frame-title-format
+	  (delq 'org-mode-line-string frame-title-format))
     (force-mode-line-update)
     (error "No active clock"))
   (save-excursion ; Do not replace this with `with-current-buffer'.
@@ -1484,6 +1509,8 @@ UPDOWN tells whether to change 'up or 'down."
   (move-marker org-clock-hd-marker nil)
   (setq global-mode-string
 	(delq 'org-mode-line-string global-mode-string))
+  (setq frame-title-format
+	(delq 'org-mode-line-string frame-title-format))
   (force-mode-line-update)
   (message "Clock canceled")
   (run-hooks 'org-clock-cancel-hook))
diff --git a/lisp/org-timer.el b/lisp/org-timer.el
index a3bde0f..b39d362 100644
--- a/lisp/org-timer.el
+++ b/lisp/org-timer.el
@@ -56,6 +56,15 @@ When 0, the user is prompted for a value."
   :version "24.1"
   :type 'number)
 
+(defcustom org-timer-display 'mode-line
+  "Where to display timer."
+  :group 'org-time
+  :type '(choice
+	  (const :tag "Mode line" mode-line)
+	  (const :tag "Frame title" frame-title)
+	  (const :tag "Both" both)
+	  (const :tag "None" nil)))
+
 (defvar org-timer-start-hook nil
   "Hook run after relative timer is started.")
 
@@ -270,10 +279,17 @@ If the integer is negative, the string will start with \"-\"."
 (defun org-timer-set-mode-line (value)
   "Set the mode-line display of the relative timer.
 VALUE can be `on', `off', or `pause'."
-  (or global-mode-string (setq global-mode-string '("")))
-  (or (memq 'org-timer-mode-line-string global-mode-string)
-      (setq global-mode-string
-	    (append global-mode-string '(org-timer-mode-line-string))))
+  (when (or (eq org-timer-display 'mode-line)
+	    (eq org-timer-display 'both))
+    (or global-mode-string (setq global-mode-string '("")))
+    (or (memq 'org-timer-mode-line-string global-mode-string)
+	(setq global-mode-string
+	      (append global-mode-string '(org-timer-mode-line-string)))))
+  (when (or (eq org-timer-display 'frame-title)
+	     (eq org-timer-display 'both))
+    (or (memq 'org-timer-mode-line-string frame-title-format)
+	(setq frame-title-format
+	      (append frame-title-format '(org-timer-mode-line-string)))))
   (cond
    ((equal value 'off)
     (when org-timer-mode-line-timer
@@ -281,21 +297,32 @@ VALUE can be `on', `off', or `pause'."
       (setq org-timer-mode-line-timer nil))
     (setq global-mode-string
 	  (delq 'org-timer-mode-line-string global-mode-string))
+    (setq frame-title-format
+	  (delq 'org-timer-mode-line-string frame-title-format))
     (force-mode-line-update))
    ((equal value 'pause)
     (when org-timer-mode-line-timer
       (cancel-timer org-timer-mode-line-timer)
       (setq org-timer-mode-line-timer nil)))
    ((equal value 'on)
+  (when (or (eq org-timer-display 'mode-line)
+	    (eq org-timer-display 'both))
     (or global-mode-string (setq global-mode-string '("")))
     (or (memq 'org-timer-mode-line-string global-mode-string)
 	(setq global-mode-string
-	      (append global-mode-string '(org-timer-mode-line-string))))
+	      (append global-mode-string '(org-timer-mode-line-string)))))
+  (when (or (eq org-timer-display 'frame-title)
+	    (eq org-timer-display 'both))
+    (or (memq 'org-timer-mode-line-string frame-title-format)
+	(setq frame-title-format
+	      (append frame-title-format '(org-timer-mode-line-string)))))
     (org-timer-update-mode-line)
     (when org-timer-mode-line-timer
-      (cancel-timer org-timer-mode-line-timer))
-    (setq org-timer-mode-line-timer
-	  (run-with-timer 1 1 'org-timer-update-mode-line)))))
+      (cancel-timer org-timer-mode-line-timer)
+      (setq org-timer-mode-line-timer nil))
+    (when org-timer-display
+      (setq org-timer-mode-line-timer
+	    (run-with-timer 1 1 'org-timer-update-mode-line))))))
 
 (defun org-timer-update-mode-line ()
   "Update the timer time in the mode line."
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-04-23 13:21 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-28 21:44 [PATCH] Option for clock and timer to be displayed in frame-title g.kettleborough
2012-02-28 22:51 ` Bernt Hansen
2012-02-29 17:26   ` George Kettleborough
2012-03-01  1:43     ` Bernt Hansen
2012-03-06 17:35       ` Bernt Hansen
2012-03-06 17:43         ` Bernt Hansen
2012-03-06 18:00         ` George Kettleborough
2012-03-06 18:34           ` Jos'h Fuller
2012-03-06 18:48             ` Nick Dokos
2012-03-06 19:59           ` Bernt Hansen
2012-04-23 13:12 ` Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).