From mboxrd@z Thu Jan 1 00:00:00 1970 From: George Kettleborough Subject: Re: [PATCH] Option for clock and timer to be displayed in frame-title Date: Wed, 29 Feb 2012 17:26:35 +0000 Message-ID: <87boohczzo.fsf@uea.ac.uk> References: <87pqcypr9v.fsf@uea.ac.uk> <87hayafu5w.fsf@norang.ca> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:52739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S2nIb-0002bG-Mc for emacs-orgmode@gnu.org; Wed, 29 Feb 2012 12:27:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S2nIV-00077N-St for emacs-orgmode@gnu.org; Wed, 29 Feb 2012 12:26:45 -0500 Received: from mtaout03-winn.ispmail.ntl.com ([81.103.221.49]:31370) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S2nIV-00076t-I6 for emacs-orgmode@gnu.org; Wed, 29 Feb 2012 12:26:39 -0500 In-Reply-To: <87hayafu5w.fsf@norang.ca> (Bernt Hansen's message of "Tue, 28 Feb 2012 22:51:55 +0000") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Bernt Hansen Cc: "emacs-orgmode@gnu.org" --=-=-= On Tue, Feb 28 2012, Bernt Hansen wrote: > This patch needs a changelog entry in the commit text and a long > description would also be appreciated. The long description allows us > to see the purpose of the patch and how to use it without the necessity > to read and parse any of the code changes. Ok, I've done a changelog entry. I hope this is what is expected. (Also fixed a minor bug in original patch and added better documentation to the new custom variable). The patch adds options to both org-clock and org-timer regarding how the current clock/timer is displayed. Currently they are both displayed in the mode line. This is not ideal since if you split your window horizontally then the mode line becomes quite short so often the clock is truncated and the timer might not even be visible. The new options control whether the clock/timer is displayed in the mode line and/or frame title. The frame title is usually wasted space for people running a graphical version of emacs so it is quite useful there I think. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Option-for-clock-and-timer-to-be-displayed-in-frame-.patch Content-Description: Patch >From 23b45a824a6118a6aa51ae1ad734747b54ee2f08 Mon Sep 17 00:00:00 2001 From: George Kettleborough Date: Wed, 29 Feb 2012 17:04:22 +0000 Subject: [PATCH] Option for clock and timer to be displayed in frame-title * lisp/org-clock.el: Add variable org-clock-clocked-in-display which controls whether the current clock is displayed in the mode line and/or frame title. * lisp/org-timer.el: Add variable org-timer-display which controls whether the current timer is displayed in the mode line and/or frame title. This allows the clock and timer to be displayed in the frame title instead of, or as well as, the mode line. This is useful for people with limited space in the mode line but with ample space in the frame title. --- lisp/org-clock.el | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- lisp/org-timer.el | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 86 insertions(+), 16 deletions(-) diff --git a/lisp/org-clock.el b/lisp/org-clock.el index 9206608..b5a9a1b 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -323,6 +323,22 @@ play with them." :version "24.1" :type 'boolean) +(defcustom org-clock-clocked-in-display 'mode-line + "When clocked in for a task, org-mode can display the current +task and accumulated time in the mode line and/or frame title. +Allowed values are: + +both displays in both mode line and frame title +mode-line displays only in mode line (default) +frame-title displays only in frame title +nil current clock is not 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 @@ -345,6 +361,8 @@ to add an effort property.") (defvar org-mode-line-string "") (put 'org-mode-line-string 'risky-local-variable t) +(defvar org-frame-title-string '(" " org-mode-line-string)) + (defvar org-clock-mode-line-timer nil) (defvar org-clock-idle-timer nil) (defvar org-clock-heading) ; defined in org.el @@ -1170,18 +1188,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-frame-title-string frame-title-format) + (setq frame-title-format + (append frame-title-format '(org-frame-title-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 +1357,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-frame-title-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 +1403,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-frame-title-string frame-title-format)) (when org-clock-out-switch-to-state (save-excursion (org-back-to-heading t) @@ -1472,6 +1504,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-frame-title-string frame-title-format)) (force-mode-line-update) (error "No active clock")) (save-excursion ; Do not replace this with `with-current-buffer'. @@ -1484,6 +1518,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-frame-title-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..0734c11 100644 --- a/lisp/org-timer.el +++ b/lisp/org-timer.el @@ -56,6 +56,22 @@ When 0, the user is prompted for a value." :version "24.1" :type 'number) +(defcustom org-timer-display 'mode-line + "When a timer is running, org-mode can display it in the mode +line and/or frame title. +Allowed values are: + +both displays in both mode line and frame title +mode-line displays only in mode line (default) +frame-title displays only in frame title +nil current timer is not displayed" + :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 +286,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 +304,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 --=-=-=--