emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Re: BROKEN BADLY: How to pause the relative timer. new version and warning
@ 2009-01-05 13:05 Alan E. Davis
  0 siblings, 0 replies; only message in thread
From: Alan E. Davis @ 2009-01-05 13:05 UTC (permalink / raw)
  To: emacs-orgmode Mailinglist


[-- Attachment #1.1: Type: text/plain, Size: 7249 bytes --]

I feel sorry that I have unleashed this broken code, and have now "fixed"
the first problem I have found.  I think it's best to ask for help and
advice.

The code I just posted does work, but when restarting after a pause, if one
has paused twice, time is subtracted serially, each time the restart routine
is run.

Also, the rest of the relative timer code is ignorant of my code, and
continues to stamp times using, for example, org-timer-item, progressively.
But then, when the timer is "restarted" the time is adjusted to the paused
time.

I have solved one problem, and left others.  I would welcome any ideas.  I
cannot hack the timer code, as much of it is beyond the limits of my lisp
cluefullness.  But probably the best that can be hoped for is for this to be
incorporated into the code in org-timer.el .

I have written into my little dired-vlc a test for C-u that starts the
relative timer if the argument is detected when starting the video!  Man,
this is nice.  It's much more straightforward for me to start, comment,
pause, reset as needed, etc., at this point.  And I already see the
pitfalls.  I'm likely to keep it simple, keep it for my own purposes.
Should I post that?  It's not very large, so I will do so below, with thanks
to the emms people and others, as well as caveats aplenty.

Thanks for the relative timer.  And org-mode.

Alan


------PAUSE----VERSION 2 -----------%--------------------
(defvar org-timer-pause-time nil
  "t=0 for pause")

(defvar org-timer-pause-restart-time nil
  "t=last for pause")

(defvar org-timer-pause-flag nil)

(defun org-aed-pause-timer-pause ()
  "Set the time of the pause timer to the start time
of the pause interval."
  (interactive)
  (if org-timer-pause-flag
    (let ((ind 0))
      (save-excursion
    (skip-chars-backward " \n\t")
    (condition-case nil
        (progn
          (org-beginning-of-item)
          (setq ind (org-get-indentation)))
      (error nil)))
      (or (bolp) (newline))
      (org-indent-line-to ind)
      (insert "Timer is already paused!  Do not pause again.")))
  (or org-timer-pause-flag
      (progn
    (setq org-timer-pause-time (current-time))
    (let ((ind 0))
      (save-excursion
        (skip-chars-backward " \n\t")
        (condition-case nil
        (progn
          (org-beginning-of-item)
          (setq ind (org-get-indentation)))
          (error nil)))
      (or (bolp) (newline))
      (org-indent-line-to ind)
      (insert "- paused:  ")
      (org-timer))
    (setq org-timer-pause-flag t))))a



;; Temporary variable for
(defvar scnds nil)

(defun org-aed-pause-timer-restart ()
  "Get current time, calculate pause interval, do the math,
and reset org-timer-start-time"
  (interactive)
  (if org-timer-pause-flag
      (progn
    (setq scnds (time-to-seconds org-timer-start-time))
    (setq org-timer-start-time
          (seconds-to-time
           (+ scnds
          (-
           (time-to-seconds (current-time))
           (time-to-seconds org-timer-pause-time)))))
    (let ((ind 0))
      (save-excursion
        (skip-chars-backward " \n\t")
        (condition-case nil
        (progn
          (org-beginning-of-item)
          (setq ind (org-get-indentation)))
          (error nil)))
      (or (bolp) (newline))
      (org-indent-line-to ind)
      (insert "- pause off:  ")
      (org-timer))
        (setq org-timer-pause-flag nil))
    (let ((ind 0))
      (save-excursion
        (skip-chars-backward " \n\t")
        (condition-case nil
        (progn
          (org-beginning-of-item)
          (setq ind (org-get-indentation)))
          (error nil)))
      (or (bolp) (newline))
      (org-indent-line-to ind)
      (insert "Error: not paused."))))

-----------------END Version 2---------%--------------


;;---------dired-vlc.el --------------%-----------------
;;  -*- mode: elisp -*-
;; Time-stamp: <05-Jan-2009 23:03:58 orm@hardware>
;; AED 05 January 2009
;;;;;;;;;;;;;;;;;

(require 'org-mode)


(defvar dired-vlc-program "/usr/bin/vlc")


(defun dired-vlc (&optional timer)
  "Asynchronously start vlc on file through dired.  If an optional
argument is given (C-u), the org relative timer is started.  This
function purports to start vlc in rc mode, to leave open the
possibility of remote control."
  (interactive "P")
  (let ((file (expand-file-name (dired-get-filename)))
        ext files basename dir curr-file ;idx-file sub-file srt-file
    command options)
    (setq basename (file-name-nondirectory
            (file-name-sans-extension file)))
    (setq dir (file-name-directory file))
    (setq files (directory-files dir t basename))
    (delete file files)
    (setq command (format "\"%s\" \"%s" dired-vlc-program "--intf rc"))
;              file))
    (if (y-or-n-p (format "Run command %s?" command))
;        (shell-command command))))
        (start-process "junk" nil dired-vlc-program file)))
  (if (equal timer '(4)) (org-timer-start))
)



;; Doesn't work.
;(defun vlc-pause ()
;  (interactive)
;  "Depends on vlc's rc mode."
;  (process-send-string
;   "junk" "pause\n"))



;; end dired-vlc.el
;;----------------------

On Mon, Jan 5, 2009 at 9:23 PM, Alan E. Davis <lngndvs@gmail.com> wrote:

> Hello:
>
> I have been able to put together a tentative solution to this problem of
> pausing the relative timer.
>
> It needs work, but perhaps one will be forgiven for posting it (below).  It
> has mostly been stolen, as anyone will see:
>
>
> ---------------- Code --------------
> (defvar org-timer-pause-time nil
>   "t=0 for pause")
>
> (defvar org-timer-pause-restart-time nil
>   "t=last for pause")
>
> (defun org-aed-pause-timer-pause ()
>   "Set the time of the pause timer to the start time
> of the pause interval."
>   (interactive)
>   (setq org-timer-pause-time (current-time))
>   (let ((ind 0))
>     (save-excursion
>       (skip-chars-backward " \n\t")
>       (condition-case nil
>       (progn
>         (org-beginning-of-item)
>         (setq ind (org-get-indentation)))
>     (error nil)))
>     (or (bolp) (newline))
>     (org-indent-line-to ind)
>     (insert "- paused:  ")
>     (org-timer)))
>
> (defvar scnds nil)
>
> (defun org-aed-pause-timer-restart ()
>   "Get current time, calculate pause interval, do the math,
> and reset org-timer-start-time"
>   (interactive)
> ;  (setq org-timer-start-time
> ;    (seconds-to-time
> ;     (+ (time-to-seconds org-timer-start-time)
>   (setq scnds (time-to-seconds org-timer-start-time))
>   (setq org-timer-start-time
>     (seconds-to-time
>      (+ scnds
>         (-
>          (time-to-seconds (current-time))
>          (time-to-seconds org-timer-pause-time)))))
>   (let ((ind 0))
>     (save-excursion
>       (skip-chars-backward " \n\t")
>       (condition-case nil
>       (progn
>         (org-beginning-of-item)
>         (setq ind (org-get-indentation)))
>     (error nil)))
>     (or (bolp) (newline))
>     (org-indent-line-to ind)
>     (insert "- pause off:  ")
>     (org-timer)))
>
> ------------END Code ---------------%---------------------
>
>
>
>
> --
> Alan Davis
>
> "It's never a matter of liking or disliking ..."
>       ---Santa Ynez Chumash Medicine Man
>
>


-- 
Alan Davis

"It's never a matter of liking or disliking ..."
      ---Santa Ynez Chumash Medicine Man

[-- Attachment #1.2: Type: text/html, Size: 11566 bytes --]

[-- Attachment #2: Type: text/plain, Size: 204 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-01-05 13:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-05 13:05 BROKEN BADLY: How to pause the relative timer. new version and warning Alan E. Davis

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