rnkn / fountain-mode

Emacs major mode for screenwriting in Fountain plain-text markup
https://fountain-mode.org
GNU General Public License v3.0
391 stars 16 forks source link

fountain-count-pages is broken #124

Closed ZungBang closed 4 years ago

ZungBang commented 4 years ago

fountain-count-pages fails with the following error message and: Wrong type argument: number-or-marker-p, fountain-fill-action

Backtrace:

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p fountain-fill-action)
  fountain-move-to-fill-width(action)
  fountain-forward-page()
  fountain-get-page-count()
  fountain-count-pages()
  funcall-interactively(fountain-count-pages)
  call-interactively(fountain-count-pages nil nil)
  command-execute(fountain-count-pages)

Tried to fix this myself, but it turned out to be a deeper rabbit hole than I expected ...

M-x emacs-version
GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.14) of 2020-03-26, modified by Debian
M-x fountain-version
Fountain Mode 3.2.1
rnkn commented 4 years ago

Should be fixed now in master. This is a regression that seems to have been introduced in v3.

ZungBang commented 4 years ago

OK, so now it just hangs emacs at my end. It's stuck until I hit C-g.

I'm testing this on the sample screenplay (Big Fish) from fountain.io.

On a related note (I think) - fountain-goto-page does not match the actual pdf (I'm using the default export profile afterwriting-usletterpdf-doublespace, with afterwriting v1.12.9). It starts to lose sync at page 4 (point is moved to a line that is on the previous page in the pdf).

rnkn commented 4 years ago

Counting pages is very computationally expensive. Big Fish takes a few seconds to count on my MacBook Pro.

Page count is only intended as approximate (as noted in the doc string). It's not really feasible to make it completely accurate within Emacs. Probably easier to just export a PDF.

ZungBang commented 4 years ago

Well, your MacBook Pro is very fast, since it's definitely an endless loop at my end :-)

When fountain-forward-page starts from the first line of the last page (CUT TO BLACK in our case), it stays put, so point never advances and fountain-get-page-count never stops since we don't get to point-max. So, either fountain-forward-page should reach the end of the buffer, or the stopping condition in fountain-get-page-count should be modified.

rnkn commented 4 years ago

Ah I see. It's because the version of Big Fish from fountain.io has no newline at the end of file. I'll get this fixed when I get a chance.

rnkn commented 4 years ago

This would actually be a great PR. As you've discovered, not many people use the count pages feature so if it's important to you a PR would be most welcome.

ZungBang commented 4 years ago

See PR #127. Was kinda tricky to fix. Please review.

rnkn commented 4 years ago

Shall we close this? The infinite looping is fixed, the accuracy is another story.

ZungBang commented 4 years ago

Sure.

This should let me estimate screen time while writing without breaking flow. I half expected it to not be accurate, but looking at the code, it just seemed complex enough to maybe be accurate. Thanks.

rnkn commented 4 years ago

I'd give it about a 3% margin of error.

rnkn commented 4 years ago

Just noticed that afterwriting breaks pages within sentences, whereas fountain-mode avoids breaking sentences. Might add an option to control this.

rnkn commented 4 years ago

p.s. You've inspired me to try to improve the page counting code. I pushed a bunch of changes over the weekend to use text properties instead of recounting pages every time. Given you're familiar with this part of the code, could you do me a favour and take a look?

ZungBang commented 4 years ago

Aw shucks - was never accused of inspiring anyone before :-)

Played around with this feature a bit - way fast! way cool! Thanks!

One thing I noticed is that going to any page in Big-Fish gets you to the first character of the next page, and the page count reports the position correctly as the next page (e.g. goto page 3, count pages - page 4 of 121). Maybe you need to subtract 1 from the user entered page number?

rnkn commented 4 years ago

Cool, thanks!

rnkn commented 4 years ago

Page counting is now what I'd call accurate. Using the Big Fish script, some pages are off by a paragraph here and there, but overall calling fountain-goto-page will get you to the same page in the PDF and in Emacs.