lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.43k stars 389 forks source link

mupdf forward+inverse search not working if twice same mainfile open #94

Closed Konfekt closed 9 years ago

Konfekt commented 9 years ago

Start Vim twice in two different projects with the same main file name, say main.tex and start :VimLatexCompileToggle in both. Then :VimLatexView does not jump to the page corresponding to the cursor position in Vim.

Probably the xdo function to recognize the proper mupdf window is too simple. If there is no way to read out the full file name in xdo, perhaps the mupdf_viewer function has to keep a window ID?!

lervag commented 9 years ago

Yes, I knew this could be a problem. I'll see what I can do, but I don't have time until late next week. Feel free to investigate yourself and submit a pull request if you find a solution.

Konfekt commented 9 years ago

Ok. Just noticed that you do it in all detail for the inverse search:

 " Get window ID
let cmd = 'xdotool search '
let cmd .= '--name "' . fnamemodify(outfile, ':t') . '"'
let mupdf_ids = systemlist(cmd)
let data.mupdf_rsearch.ids = mupdf_ids
let data.mupdf_rsearch.ids_cmd = cmd
if len(mupdf_ids) != 1 | return | endif
let mupdf_id = mupdf_ids[0]

So perhaps that gets me starting (see also https://github.com/ying17zi/vim-live-latex-preview/blob/master/ftplugin/tex/live-latex-preview.vim#L83)

EDIT: Never mind. That's where the problem is actually.

Konfekt commented 9 years ago

So perhaps add mupdf_id, or more generally viewer_window_id to g:latex#data seems sensible (one viewer for each Vim instance).

Set win_id to 0 by default. -If win_id == 0, start mupdf and set win_id.
-Else check if a window with win_id still exists. --If so do forward/inverse search. --Else start mupdf and set win_id.

Konfekt commented 9 years ago

To get the win_id of the just launched mupdf viewer, take the last entry of xdotool search --class "MuPDF"

lervag commented 9 years ago

Thanks, that might be useful to know.

Konfekt commented 9 years ago

Hold on, I'm pushing.

Konfekt commented 9 years ago

Done. Works over here. Was a bit of work. Feel free to relabel and restructure.

lervag commented 9 years ago

Great, I think it looks good. I'll merge and possibly do some minor changes as soon as I have the time. However, I'm travelling right now, so I am not sure when I will get the time. Hopefully by the end of the week.

Konfekt commented 9 years ago

Made additional small adjustments.

Offtopic: How about foldmethod = syntax instead of the fold markers? Achieves the same folds with less clutter.

lervag commented 9 years ago

Interesting question. I'll try it out and see if I prefer it to the markers (which I agree do create some clutter).

Konfekt commented 9 years ago

I use

set foldmethod=syntax
let g:vimsyn_folding='af'
Konfekt commented 9 years ago

Just a small update to confirm that the commit is working fine over here the last few days since I removed the lines in latexmkrc that change mupdf's window title by xdotool.

lervag commented 9 years ago

Sorry for the delay, I've been out with a nast cold (or flu). I've merged your pull request and will be trying it out in the coming days/weeks. The code looked alright, at least, so I don't expect (m)any bugs.

lervag commented 9 years ago

It seems to work here as well, so I'll close this issue for now. Thanks!

lervag commented 9 years ago

I've looked into the syntax folding for vim, and I have one single reason I want to keep the marker folding: speed. Syntax folding, at least on my end, adds to loading and folding time much more than does marker folding. Thanks for making me aware of the settings, though. It will make it more pleasant to read vimL that do not use markers.

Konfekt commented 9 years ago

Yeah, you gotta take a look at my FastFold plugin someday :)

Konfekt commented 9 years ago

By the way, I think there's an issue that the Window numbers get reassigned when you close a mupdf window.

Both Vim instances end up forwarding to the same window instead of opening a new one without complaints. Must do that manually.

lervag commented 9 years ago

@Konfekt Perhaps you have not seen the option g:latex_fold_automatic? It was introduced some time last year and allows to turn off automatic folding, that is, use manual folding instead of expr folding. Folds may then be updated with zx. This solves the problem with folding slowdown.

About the issue: Please open a new issue with a good explanation if you find it necessary. I'll look into it later when I get the time.

Konfekt commented 9 years ago

Yes, I have seen it and we discussed it I recall. FastFold does what g:latex_fold_automatic does for every FileType. For example, for Vim syntax folding.

There is an option let g:fastfold_skipfiles = [] that you can use to enable it only for Vim filetypes.

lervag commented 9 years ago

Ah, then I understand your comment. I should of course have read it in context of my own comment above... in any case, another reason I like the markers is that they allow me to "structure" the source files and use several levels of folding (even though I don't use the latter very much (or at all) in vim-latex).

I might consider to change later on, but at the moment I am happy enough with the way it is. :)