refactor skim viewer#2289
Conversation
Great!
Great!
Not quite sure if this has any specific merits..?
Great!
Does this sync on every callback, or just the initial one? I think there are two different scenarios here:
I don't have any opinions on this. |
autoload/vimtex/view/skim.vim
Outdated
| \ '-e ''var theLine = ' . (line('.')-1) . '''', | ||
| \ '-e ''var theSource = Path("' . expand('%:p') . '")''', | ||
| \ self.show, | ||
| \ g:vimtex_view_skim_sync ? self.sync : '', |
There was a problem hiding this comment.
Do I remember correctly that this stuff is required to force Skim to update after successful compilation? I.e., without this, Skim would still show the old version of the PDF?
If possibly, I think it would be good to add support for g:vimtex_view_automatic here similar to how it's done for Zathura and MuPDF, see here:
vimtex/autoload/vimtex/view/_template.vim
Lines 236 to 253 in f31b723
There was a problem hiding this comment.
Is it possible to implement an _exists method that would be reliable for Skim?
There was a problem hiding this comment.
No, that is for doing a forward search (syncing editor and viewer, which I know some people like). The update happens in every case (via the app.revert(theDocs) line) as I don't see any reason not to have this.
To be clear: without the sync part, the PDF would still get updated but would keep showing the same view.
There was a problem hiding this comment.
I can, however, put this behind a g:vimtex_view_automatic guard -- if there is a good reason for it?
autoload/vimtex/view/skim.vim
Outdated
| \ '-e ''app.documents[0].go({ to: app.texLines[theLine], from: theSource', | ||
| \ g:vimtex_view_skim_reading_bar ? ', showingReadingBar: true' : '', | ||
| \ '})''', | ||
| \]), |
There was a problem hiding this comment.
I think the main purpose for adding these variables as dictionary keys is to prevent duplicate code. As far as I can see, the start key is only used once. show and sync are used twice. I therefore believe it would be better to remove the start key and instead type it out verbosely (unless we end up removing the _latexmk_append_argument stuff altogether). I'm also wondering if the code could be slightly cleaner if the show and sync keys are instead changed to script variables; it would never make sense for a user outside of this scripts scope to inspect these variables, right?
There was a problem hiding this comment.
I think the main question is when the config variables are evaluated. I believe the reason to have them in the template is to allow updating it via :VimtexReload?
But this relates to the comment below: I'm happy to do the refactoring in another way; I just wanted to stay as close to the current setup as I don't fully understand the control flow here.
Makes it a bit easier to maintain (it's hard enough not to lose track of all the quotes for the embedded scripting...). An alternative would be to move the complete thing out into a (private)
It syncs on every callback. I agree that this may not be desirable (in fact, my motivation for the original refactor to get rid of |
|
I think there are three scenarios:
As far as I can tell, the current architecture doesn't allow me to easily handle 3., since VimTeX itself doesn't know about this, and the |
|
@lervag I've refactored again to extract all the common JavaScript lines into a single The |
Refactor the Skim viewer backend to * use JavaScript instead of AppleScript (nicer, and should fix #2279) * make the initial start respect `g:vimtex_view_skim_activate` (alternative to #2286) * factor out common script parts into script function * correct off-by-one line number for forward search * introduce new option `g:vimtex_view_skim_sync` to perform forward search after compilation (syncing viewer and editor), default false * change default for `g:vimtex_view_skim_reading_bar` to false (location is highlighted anyway on sync)
|
Thanks @clason! I've merged now. But please note: I've made some important general changes based on the discussion we've had. I've now forced So: Please test the latest version and let me know how it works. Especially: with the default settings with Skim, do things still work as expected? |
|
Yes, looks fine to me! Except for the reading bar, I get the same behavior as before with the default settings (and |
|
Does Skim start automatically after compilation? Also, I think we want to support |
Yes, it does.
Why (honestly asking)? From what I've seen, this is optional since for many viewers, it requires workarounds using external tools and whatnot, which may have undesired side effects (such as slowdown). However, Skim supports this out of the box with the same interface, so it's a freebie. Can you think of any situation where you would not want this? |
|
Ok, so, to be more clear about what I'm thinking about, please see how the general viewer now works wrt. callbacks: vimtex/autoload/vimtex/view/_template.vim Lines 80 to 91 in 72e6285 The callbacks are "activated" here (they are active in all cases): vimtex/autoload/vimtex/view.vim Lines 25 to 29 in 72e6285 And this shows how they are abstracted: vimtex/autoload/vimtex/view.vim Lines 50 to 66 in 72e6285 |
Yes, simple: I don't want Currently, this workflow is not possibly with Skim, because it does not support |
|
Interesting. But I don't see the issue then: Isn't it trivial to add that approach to the current callback, as in function! s:viewer.compiler_callback(outfile) dict abort " {{{1
if !g:vimtex_view_automatic
\ || has_key(self, 'started_through_callback') | return | endif
call vimtex#jobs#run(s:make_cmd_view(a:outfile, g:vimtex_view_skim_sync))
let self.started_through_callback = 1
endfunction |
|
For other people reading here - me and @clason discussed things on Gitter and I've pushed a few more updates that we believe resolve these things for now. Feel free to open new issues if something broke! |
Refactor the Skim viewer backend to
g:vimtex_view_skim_activate(alternative to add option to control whether Skim gets focus upon first open #2286, @yongrenjie )g:vimtex_view_skim_syncto perform forward search after compilation (syncing viewer and editor), default falseg:vimtex_view_skim_reading_barto false (location is highlighted anyway on sync)