termpdf.py icon indicating copy to clipboard operation
termpdf.py copied to clipboard

Auto-refresh on file change

Open slarwise opened this issue 5 years ago • 5 comments

Hi!

Would it be possible to have termpdf refresh the current pdf when the file is updated? #10 solves this using the workflow described there but having an option for auto-refresh on file change would make it simpler to use in any workflow.

slarwise avatar May 27 '20 09:05 slarwise

Okay. This feature is now implemented. I don't have any proper asynchronic control in the script, so I can't make it refresh completely automatically: most of the time, it is waiting for a keypress, and I don't know how to interrupt that when a file changes.

For now, it checks to see if the file has changed after each key press. If the file has changed, the keypress is swallowed and the document is refreshed. Does that seem right to you?

dsanson avatar May 27 '20 20:05 dsanson

Thanks, that was fast! It seems to be working well.

I was looking for refreshing without even having to touch termpdf. I usually write latex in neovim, have latexmk continuously compiling in the background and view the pdf in Skim which refreshes the document when it's been updated. So I never have to go into the pdf viewer unless I need to change page. This implementation definitely helps though.

So since the main loop is waiting for keypresses, you would need another thread that watches the file to make this work?

slarwise avatar May 28 '20 08:05 slarwise

I think that's right. I have no experience with multiple threads in Python. Features I'd like to have that require it:

  • [ ] proper autorefresh
  • [ ] controlling termpdf from other programs
    • navigation without leaving vim
    • adding citation to current page of document without leaving vim
    • support for synctex
  • [ ] opening new files in a running instance of termpdf

At some point, I need to sit down and read through some tutorials on threading in python, and get this implemented!

dsanson avatar May 28 '20 15:05 dsanson

Okay. I reimplemented autorefresh using threading. This is still probably not the right thing to do. I just have a loop that pools os.path.getmtime() every .5 seconds. The correct solution is to use the watchdog module, but I couldn't figure out how to get that to work.

dsanson avatar May 29 '20 00:05 dsanson

Those features sound awesome, especially navigation from vim.

Tried the new version with the threading, it doesn't seem to work for me. I open the pdf with termpdf, make a change in the tex-code and compile it with latexmk. After that termpdf closes with no error message. Let me know if you want more details.

slarwise avatar May 29 '20 08:05 slarwise