sachac / subed

subed is a subtitle editor for Emacs
177 stars 16 forks source link

Add computing and displaying characters per second #36

Closed mbork closed 3 years ago

rndusr commented 3 years ago

Thank you for contributing.

  1. The code looks like I should get a "x.y cps" display somewhere around the subtitle but I don't see it. subed-calculate-cps works as expected. Is that because I'm using Emacs in my terminal and overlays need Emacs with graphics?

  2. I see you're disabling the overlay movement while sorting srt subtitles but not while sorting vtt subtitles. Is this not necessary for vtt?

mbork commented 3 years ago

Hi, and thanks for your answer!

  1. I fixed the issue – it was a stupid bug, so I rebased it. Please delete your local cps branch and fetch it again (or reset --hard to the new branch). It should work in a terminal Emacs now.

  2. This is a bit embarassing, but it turned out that it's not necessary at all. I removed my code from subed-srt.el.

(The reason for this mess was that I had two slightly different functions defined in my Emacs – subed-calculate-cps and subed--calculate-cps. This is a reminder that I should always test my code in a fresh Emacs instance!)

rndusr commented 3 years ago

Thank you for revising. I can now see the CPS display. Nifty!

But when I adjust the start time (C-[ or C-]), I get: "Match data clobbered by buffer modification hooks"

Adjusting the stop time doesn't produce any errors.

(The reason for this mess was that I had two slightly different functions defined in my Emacs – subed-calculate-cps and subed--calculate-cps. This is a reminder that I should always test my code in a fresh Emacs instance!)

In my experience, writing tests helps a lot with this kind of problem.

mbork commented 3 years ago

On 2021-05-19, at 11:40, rndusr @.***> wrote:

Thank you for revising. I can now see the CPS display. Nifty!

But when I adjust the start time (C-[ or C-]), I get: "Match data clobbered by buffer modification hooks"

Adjusting the stop time doesn't produce any errors.

I am not sure what exactly happened (this seems not to be documented in the Emacs Lisp Reference), but it is not difficult to guess the reason and the remedy.

(The reason for this mess was that I had two slightly different functions defined in my Emacs – subed-calculate-cps and subed--calculate-cps. This is a reminder that I should always test my code in a fresh Emacs instance!)

In my experience, writing tests helps a lot with this kind of problem.

I looked into the tests, but saying `make test' yields this:

--8<---------------cut here---------------start------------->8--- $ make test emacs -batch -f package-initialize -L . -f buttercup-run-discover Eager macro-expansion failure: (wrong-number-of-arguments (3 . 4) 2) Eager macro-expansion failure: (wrong-number-of-arguments (3 . 4) 2) Error loading autoloads: (wrong-number-of-arguments (3 . 4) 2) Package cl is deprecated Debugger entered--Lisp error: (void-function subed-subtitle-time-adjusted-hook) (subed-subtitle-time-adjusted-hook) (closure (t) nil :var (subed-subtitle-time-adjusted-hook) (buttercup-it "runs the appropriate hook." #'(lambda nil (let ((foo (fset ... ...))) (spy-on 'foo) (let ((temp-buffer ...)) (save-current-buffer (set-buffer temp-buffer) (unwind-protect ... ...)))))) (buttercup-it "adjusts the start/stop time." #'(lambda nil (let ((temp-buffer (generate-new-buffer " temp" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn ... ... ...) (and ... ...)))))) (buttercup-describe "enforces boundaries" #'(lambda nil (buttercup-describe "when decreasing start time" #'(lambda nil (buttercup-it "of the first subtitle." ...) (buttercup-it "of a non-first subtitle." ...))) (buttercup-it "when increasing start time." #'(lambda nil (let ... ...))) (buttercup-it "when decreasing stop time." #'(lambda nil (let ... ...))) (buttercup-describe "when increasing stop time" #'(lambda nil (buttercup-it "of the last subtitle." ...) (buttercup-it "of a non-last subtitle." ...))) (buttercup-it "without undershooting the target time." #'(lambda nil (let ... ...))) (buttercup-it "without overshooting the target time." #'(lambda nil (let ... ...))))) (buttercup-describe "ignores negative duration if the first argument is..." #'(lambda nil (buttercup-it "when adjusting start time." #'(lambda nil (let ... ...))) (buttercup-it "when adjusting stop time." #'(lambda nil (let ... ...))))) (buttercup-describe "ignores subtitle spacing if the second argument is..." #'(lambda nil (buttercup-it "when adjusting start time." #'(lambda nil (let ... ...))) (buttercup-it "when adjusting stop time." #'(lambda nil (let ... ...))))) (buttercup-describe "ignores negative duration if subed-enforce-time-bo..." #'(lambda nil (buttercup-it "when adjusting start time." #'(lambda nil (let ... ...))) (buttercup-it "when adjusting stop time." #'(lambda nil (let ... ...))))) (buttercup-describe "ignores subtitle spacing if subed-enforce-time-bou..." #'(lambda nil (buttercup-it "when adjusting start time." #'(lambda nil (let ... ...))) (buttercup-it "when adjusting stop time." #'(lambda nil (let ... ...))))) (buttercup-describe "prevents negative time even if subed-enforce-time-..." #'(lambda nil (buttercup-it "when adjusting start time." #'(lambda nil (let ... ...))) (buttercup-it "when adjusting stop time." #'(lambda nil (let ... ...))))) (buttercup-it "does nothing if no timestamp can be found." #'(lambda nil (let ((temp-buffer (generate-new-buffer " temp" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn ... ... ...) (and ... ...)))))))() buttercup-describe("Adjusting subtitle start/stop time" (closure (t) nil :var (subed-subtitle-time-adjusted-hook) (buttercup-it "runs the appropriate hook." #'(lambda nil (let ((foo ...)) (spy-on 'foo) (let (...) (save-current-buffer ... ...))))) (buttercup-it "adjusts the start/stop time." #'(lambda nil (let ((temp-buffer ...)) (save-current-buffer (set-buffer temp-buffer) (unwind-protect ... ...))))) (buttercup-describe "enforces boundaries" #'(lambda nil (buttercup-describe "when decreasing start time" #'(lambda nil ... ...)) (buttercup-it "when increasing start time." #'(lambda nil ...)) (buttercup-it "when decreasing stop time." #'(lambda nil ...)) (buttercup-describe "when increasing stop time" #'(lambda nil ... ...)) (buttercup-it "without undershooting the target time." #'(lambda nil ...)) (buttercup-it "without overshooting the target time." #'(lambda nil ...)))) (buttercup-describe "ignores negative duration if the first argument is..." #'(lambda nil (buttercup-it "when adjusting start time." #'(lambda nil ...)) (buttercup-it "when adjusting stop time." #'(lambda nil ...)))) (buttercup-describe "ignores subtitle spacing if the second argument is..." #'(lambda nil (buttercup-it "when adjusting start time." #'(lambda nil ...)) (buttercup-it "when adjusting stop time." #'(lambda nil ...)))) (buttercup-describe "ignores negative duration if subed-enforce-time-bo..." #'(lambda nil (buttercup-it "when adjusting start time." #'(lambda nil ...)) (buttercup-it "when adjusting stop time." #'(lambda nil ...)))) (buttercup-describe "ignores subtitle spacing if subed-enforce-time-bou..." #'(lambda nil (buttercup-it "when adjusting start time." #'(lambda nil ...)) (buttercup-it "when adjusting stop time." #'(lambda nil ...)))) (buttercup-describe "prevents negative time even if subed-enforce-time-..." #'(lambda nil (buttercup-it "when adjusting start time." #'(lambda nil ...)) (buttercup-it "when adjusting stop time." #'(lambda nil ...)))) (buttercup-it "does nothing if no timestamp can be found." #'(lambda nil (let ((temp-buffer ...)) (save-current-buffer (set-buffer temp-buffer) (unwind-protect ... ...))))))) eval-buffer(#<buffer load> nil "[redacted]" nil t) ; Reading at buffer position 20367 load-with-code-conversion("[redacted]" "[redacted]" nil t) load("./tests/test-subed-common.el" nil t) buttercup-run-discover() command-line-1(("-f" "package-initialize" "-L" "." "-f" "buttercup-run-discover")) command-line() normal-top-level()

make: *** [Makefile:9: test] Error 255 --8<---------------cut here---------------end--------------->8---

Best,

-- Marcin Borkowski http://mbork.pl

rndusr commented 3 years ago

Thanks for fixing this.

The tests run fine for me. It looks like my hacky abstraction layer is failing you. I gave up on ever getting that working properly, so forget I even mentioned the tests. :)

mbork commented 3 years ago

On 2021-05-26, at 11:32, rndusr @.***> wrote:

Thanks for fixing this.

You're welcome, and thanks for merging. (I have two more additions in the pipeline.)

The tests run fine for me. It looks like my hacky abstraction layer is failing you. I gave up on ever getting that working properly, so forget I even mentioned the tests. :)

Well, I'd really like to add some tests, so I'll just try to figure out what's wrong on my end. (Not today, though.)

-- Marcin Borkowski http://mbork.pl