emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-clock-out overrides frame-title-format [9.2.3 (9.2.3-17-g4df705-elpa @ ~/.emacs.d/elpa/org-20190513/)]
@ 2019-05-17 12:15 Andrii Kolomoiets
  2019-05-28  9:02 ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Andrii Kolomoiets @ 2019-05-17 12:15 UTC (permalink / raw)
  To: emacs-orgmode

Hello.

The org-frame-title-format-backup variable is initialized on
org-clock.el loading and future changes to frame-title-format is
ignored:

1. emacs -Q
2. M-: frame-title-format
   It's "%b"
3. M-: (require 'org-clock)
4. (setq frame-title-format "%b bar")
5. C-x b test.org
6. M-x org-mode
7. Insert heading (M-RET foo)
8. M-x org-clock-in
9. M-x org-clock-out
10. M-: frame-title-format
    It's "%b" again
    
With provided patch org-frame-title-format-backup is initialized on
org-clock-in. Also frame-title-format is restored to
org-frame-title-format-backup only if current frame-title-format is
equal to org-clock-frame-title-format in case frame title format is
changed after org-clock-in.

diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 9a8928a49..b07f4b221 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -1359,6 +1359,7 @@ the default behavior."
         ;; add to frame title
         (when (or (eq org-clock-clocked-in-display 'frame-title)
                   (eq org-clock-clocked-in-display 'both))
+          (setq org-frame-title-format-backup frame-title-format)
           (setq frame-title-format org-clock-frame-title-format))
         (org-clock-update-mode-line)
         (when org-clock-mode-line-timer
@@ -1560,7 +1561,8 @@ to, overriding the existing value of `org-clock-out-switch-to-state'."
     (when (not (org-clocking-p))
       (setq global-mode-string
            (delq 'org-mode-line-string global-mode-string))
-      (setq frame-title-format org-frame-title-format-backup)
+      (when (equal frame-title-format org-clock-frame-title-format)
+       (setq frame-title-format org-frame-title-format-backup))
       (force-mode-line-update)
       (if fail-quietly (throw 'exit t) (user-error "No active clock")))
     (let ((org-clock-out-switch-to-state
@@ -1618,7 +1620,8 @@ to, overriding the existing value of `org-clock-out-switch-to-state'."
            (setq org-clock-idle-timer nil))
          (setq global-mode-string
                (delq 'org-mode-line-string global-mode-string))
-         (setq frame-title-format org-frame-title-format-backup)
+         (when (equal frame-title-format org-clock-frame-title-format)
+           (setq frame-title-format org-frame-title-format-backup))
          (when org-clock-out-switch-to-state
            (save-excursion
              (org-back-to-heading t)
@@ -1718,7 +1721,8 @@ Optional argument N tells to change by that many units."
   (when (not (org-clocking-p))
     (setq global-mode-string
          (delq 'org-mode-line-string global-mode-string))
-    (setq frame-title-format org-frame-title-format-backup)
+    (when (equal frame-title-format org-clock-frame-title-format)
+      (setq frame-title-format org-frame-title-format-backup))
     (force-mode-line-update)
     (error "No active clock"))
   (save-excursion    ; Do not replace this with `with-current-buffer'.
@@ -1734,7 +1738,8 @@ Optional argument N tells to change by that many units."
   (move-marker org-clock-hd-marker nil)
   (setq global-mode-string
        (delq 'org-mode-line-string global-mode-string))
-  (setq frame-title-format org-frame-title-format-backup)
+  (when (equal frame-title-format org-clock-frame-title-format)
+    (setq frame-title-format org-frame-title-format-backup))
   (force-mode-line-update)
   (message "Clock canceled")
   (run-hooks 'org-clock-cancel-hook))

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

* Re: [PATCH] org-clock-out overrides frame-title-format [9.2.3 (9.2.3-17-g4df705-elpa @ ~/.emacs.d/elpa/org-20190513/)]
  2019-05-17 12:15 [PATCH] org-clock-out overrides frame-title-format [9.2.3 (9.2.3-17-g4df705-elpa @ ~/.emacs.d/elpa/org-20190513/)] Andrii Kolomoiets
@ 2019-05-28  9:02 ` Nicolas Goaziou
  2019-05-28 13:57   ` [PATCH] org-clock.el: Fix restore of frame-title-format Andrii Kolomoiets
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2019-05-28  9:02 UTC (permalink / raw)
  To: Andrii Kolomoiets; +Cc: emacs-orgmode

Hello,

Andrii Kolomoiets <andreyk.mad@gmail.com> writes:

> The org-frame-title-format-backup variable is initialized on
> org-clock.el loading and future changes to frame-title-format is
> ignored:
>
> 1. emacs -Q
> 2. M-: frame-title-format
>    It's "%b"
> 3. M-: (require 'org-clock)
> 4. (setq frame-title-format "%b bar")
> 5. C-x b test.org
> 6. M-x org-mode
> 7. Insert heading (M-RET foo)
> 8. M-x org-clock-in
> 9. M-x org-clock-out
> 10. M-: frame-title-format
>     It's "%b" again
>     
> With provided patch org-frame-title-format-backup is initialized on
> org-clock-in. Also frame-title-format is restored to
> org-frame-title-format-backup only if current frame-title-format is
> equal to org-clock-frame-title-format in case frame title format is
> changed after org-clock-in.

Thank you.

I think this could be factored out a bit, for example creating a simple
function taking care of updating `frame-title-format' if needed.

Also, could you provide a proper commit message and use git format-patch
to send it again?

Regards,

-- 
Nicolas Goaziou

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

* [PATCH] org-clock.el: Fix restore of frame-title-format
  2019-05-28  9:02 ` Nicolas Goaziou
@ 2019-05-28 13:57   ` Andrii Kolomoiets
  2019-05-28 17:59     ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Andrii Kolomoiets @ 2019-05-28 13:57 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

* lisp/org-clock.el (org-frame-title-format-backup): Use nil as initial value.
(org-clock-in): set `org-frame-title-format-backup' to `frame-title-format'.
(org-clock-restore-frame-title-format): New function.
(org-clock-out): Use it.
(org-clock-cancel): Use it.

The problem was that the `org-frame-title-format-backup' variable is
initialized on org-clock.el loading and future changes to `frame-title-format'
is ignored.

TINYCHANGE
---
 lisp/org-clock.el | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 9a8928a49..12b412f7b 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -41,7 +41,7 @@
 (declare-function org-table-goto-line "org-table" (n))
 (declare-function org-dynamic-block-define "org" (type func))

-(defvar org-frame-title-format-backup frame-title-format)
+(defvar org-frame-title-format-backup nil)
 (defvar org-state)
 (defvar org-link-bracket-re)
 (defvar org-time-stamp-formats)
@@ -1359,6 +1359,7 @@ the default behavior."
 	 ;; add to frame title
 	 (when (or (eq org-clock-clocked-in-display 'frame-title)
 		   (eq org-clock-clocked-in-display 'both))
+	   (setq org-frame-title-format-backup frame-title-format)
 	   (setq frame-title-format org-clock-frame-title-format))
 	 (org-clock-update-mode-line)
 	 (when org-clock-mode-line-timer
@@ -1549,6 +1550,14 @@ line and position cursor in that line."
 	 (org-log-states-order-reversed (goto-char (car (last positions))))
 	 (t (goto-char (car positions))))))))

+(defun org-clock-restore-frame-title-format ()
+  "Restore `frame-title-format' from `org-frame-title-format-backup'.
+`frame-title-format' is restored if `org-frame-title-format-backup' is not nil
+and current `frame-title-format' is equal to `org-clock-frame-title-format'."
+  (when (and org-frame-title-format-backup
+	     (equal frame-title-format org-clock-frame-title-format))
+    (setq frame-title-format org-frame-title-format-backup)))
+
 ;;;###autoload
 (defun org-clock-out (&optional switch-to-state fail-quietly at-time)
   "Stop the currently running clock.
@@ -1560,7 +1569,7 @@ to, overriding the existing value of `org-clock-out-switch-to-state'."
     (when (not (org-clocking-p))
       (setq global-mode-string
 	    (delq 'org-mode-line-string global-mode-string))
-      (setq frame-title-format org-frame-title-format-backup)
+      (org-clock-restore-frame-title-format)
       (force-mode-line-update)
       (if fail-quietly (throw 'exit t) (user-error "No active clock")))
     (let ((org-clock-out-switch-to-state
@@ -1618,7 +1627,7 @@ to, overriding the existing value of `org-clock-out-switch-to-state'."
 	    (setq org-clock-idle-timer nil))
 	  (setq global-mode-string
 		(delq 'org-mode-line-string global-mode-string))
-	  (setq frame-title-format org-frame-title-format-backup)
+	  (org-clock-restore-frame-title-format)
 	  (when org-clock-out-switch-to-state
 	    (save-excursion
 	      (org-back-to-heading t)
@@ -1718,7 +1727,7 @@ Optional argument N tells to change by that many units."
   (when (not (org-clocking-p))
     (setq global-mode-string
 	  (delq 'org-mode-line-string global-mode-string))
-    (setq frame-title-format org-frame-title-format-backup)
+    (org-clock-restore-frame-title-format)
     (force-mode-line-update)
     (error "No active clock"))
   (save-excursion    ; Do not replace this with `with-current-buffer'.
@@ -1734,7 +1743,7 @@ Optional argument N tells to change by that many units."
   (move-marker org-clock-hd-marker nil)
   (setq global-mode-string
 	(delq 'org-mode-line-string global-mode-string))
-  (setq frame-title-format org-frame-title-format-backup)
+  (org-clock-restore-frame-title-format)
   (force-mode-line-update)
   (message "Clock canceled")
   (run-hooks 'org-clock-cancel-hook))
--
2.15.1

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

* Re: [PATCH] org-clock.el: Fix restore of frame-title-format
  2019-05-28 13:57   ` [PATCH] org-clock.el: Fix restore of frame-title-format Andrii Kolomoiets
@ 2019-05-28 17:59     ` Nicolas Goaziou
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Goaziou @ 2019-05-28 17:59 UTC (permalink / raw)
  To: Andrii Kolomoiets; +Cc: emacs-orgmode

Hello,

Andrii Kolomoiets <andreyk.mad@gmail.com> writes:

> * lisp/org-clock.el (org-frame-title-format-backup): Use nil as initial value.
> (org-clock-in): set `org-frame-title-format-backup' to `frame-title-format'.
> (org-clock-restore-frame-title-format): New function.
> (org-clock-out): Use it.
> (org-clock-cancel): Use it.
>
> The problem was that the `org-frame-title-format-backup' variable is
> initialized on org-clock.el loading and future changes to `frame-title-format'
> is ignored.

Applied. Thank you.

Regards,

-- 
Nicolas Goaziou

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

end of thread, other threads:[~2019-05-28 18:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-17 12:15 [PATCH] org-clock-out overrides frame-title-format [9.2.3 (9.2.3-17-g4df705-elpa @ ~/.emacs.d/elpa/org-20190513/)] Andrii Kolomoiets
2019-05-28  9:02 ` Nicolas Goaziou
2019-05-28 13:57   ` [PATCH] org-clock.el: Fix restore of frame-title-format Andrii Kolomoiets
2019-05-28 17:59     ` Nicolas Goaziou

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).