Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VimtexClean does not clean files (win10) #2139

Closed
habamax opened this issue Aug 19, 2021 · 20 comments
Closed

VimtexClean does not clean files (win10) #2139

habamax opened this issue Aug 19, 2021 · 20 comments
Labels

Comments

@habamax
Copy link
Contributor

habamax commented Aug 19, 2021

Description

When I run :VimtexClean I can see cmd window running and after it is closed no files are deleted:

Steps to reproduce

  1. <localleader>ll
  2. wait till document is created
  3. <localleader>ll
  4. :VimtexClean

Expected behavior

All(?) or some generated files are deleted.

Actual behavior

Nothing is deleted.

Do you use a latexmkrc file?

No

VimtexInfo

System info
  OS: Microsoft Windows 10 Pro (10.0.19041 N/A Build 19041)
  Vim version: VIM 8.2 (1-3358)
  Has clientserver: true
  Servername: GVIM

VimTeX project: test
  base: test.tex
  root: C:\Users\maksim.kim\temp
  tex: C:\Users\maksim.kim\temp\test.tex
  out: C:\Users\maksim.kim\temp/test.pdf
  log: C:\Users\maksim.kim\temp/test.log
  aux: C:\Users\maksim.kim\temp/test.aux
  fls: C:\Users\maksim.kim\temp/test.fls
  main parser: current file verified
  compiler: latexmk
    configuration: 
      continuous: 1
      callback: 1
      latexmk options:
        -shell-escape
        -verbose
        -file-line-error
        -synctex=1
        -interaction=nonstopmode
      latexmk engine: -lualatex
  viewer: General
  qf: LaTeX logfile
    addqflist: 70
    fix_paths: 71
    set_errorformat: 69
  document class: article
  packages:
    atbegshi-ltx
    atveryend-ltx
    auxhook
    babel
    bigintcalc
    bitset
    calc
    catchfile
    color
    etexcmds
    etoolbox
    expl3
    fancyhdr
    fancyvrb
    float
    fontenc
    fontspec
    fontspec-luatex
    framed
    fvextra
    geometry
    gettitlestring
    hycolor
    hyperref
    ifluatex
    ifplatform
    iftex
    ifthen
    ifvtex
    infwarerr
    intcalc
    isodate
    keyval
    kvdefinekeys
    kvoptions
    kvsetkeys
    letltxmacro
    lineno
    ltxcmds
    mdframed
    minted
    nameref
    needspace
    pdfescape
    pdftexcmds
    refcount
    rerunfilecheck
    shellesc
    stringenc
    substr
    textcomp
    titlesec
    uniquecounter
    upquote
    url
    xcolor
    xparse
    xstring
    zref-abspage
    zref-base
@habamax habamax added the bug label Aug 19, 2021
@lervag
Copy link
Owner

lervag commented Aug 19, 2021

That's definitely strange. Can you test this with a minimal example? I.e. use a minimal vimrc file and a minimal latex project.

@habamax
Copy link
Contributor Author

habamax commented Aug 19, 2021

sure, will try it

@habamax
Copy link
Contributor Author

habamax commented Aug 20, 2021

The same with minimal vimrc and tex file that are suggested in issue creation -- nothing is deleted.

minimal.tex

\documentclass{minimal}
\begin{document}
Hello world!
\end{document}

min.vimrc

set nocompatible
let &runtimepath  = '~/vimfiles/pack/plug/start/vimtex,' . &runtimepath
let &runtimepath .= ',~/vimfiles/pack/plug/start/vimtex/after'
filetype plugin indent on
syntax enable
" Add relevant options and VimTeX configuration below.
let g:vimtex_compiler_latexrun_engines = {'_': 'lualatex'}
let g:vimtex_compiler_latexmk_engines = {'_': '-lualatex'}
let g:vimtex_compiler_latexmk = {
            \ 'build_dir': {-> expand("%:t:r")},
            \ 'options' : [
                \   '-shell-escape',
                \   '-verbose',
                \   '-file-line-error',
                \   '-synctex=1',
                \   '-interaction=nonstopmode',
                \ ],
                \}

let g:vimtex_syntax_packages = {'minted': {'load': 1}}

vim start

gvim -Nu min.vimrc
  1. VimtexCompile -- I can see all the generated files in a minimal subdirectory
  2. VimtexCompile -- to stop cont. mode
  3. VimtexClean -- All the files are in place in a minimal subdirectory

If I remove build_dir from the settings, all the files are in the same directory and still are not deleted after VimtexClean.

@habamax
Copy link
Contributor Author

habamax commented Aug 20, 2021

Probably this is an issue :)

function! s:compiler.clean(...) abort dict " {{{1
  let l:files = ['synctex.gz', 'toc', 'out', 'aux', 'log']

  " If a full clean is required
  if a:0 > 0 && a:1
    call extend(l:files, ['pdf'])
  endif

  call map(l:files, {_, x -> printf('%s/%s.%s',
        \ self.build_dir, fnamemodify(self.target_path, ':t:r:S'), x)})
  call vimtex#process#run('rm -f ' . join(l:files))       <------------------- `del /F` in widnows
  call vimtex#log#info('Compiler clean finished')
endfunction

Edit by @lervag: For reference, the above function is here:

function! s:compiler.clean(...) abort dict " {{{1
let l:files = ['synctex.gz', 'toc', 'out', 'aux', 'log']
" If a full clean is required
if a:0 > 0 && a:1
call extend(l:files, ['pdf'])
endif
call map(l:files, {_, x -> printf('%s/%s.%s',
\ self.build_dir, fnamemodify(self.target_path, ':t:r:S'), x)})
call vimtex#process#run('rm -f ' . join(l:files))
call vimtex#log#info('Compiler clean finished')
endfunction
" }}}1

@habamax
Copy link
Contributor Author

habamax commented Aug 20, 2021

And for me it looks like this function is never called.

I have put there some message, both with echom and vimtex#log#info -- nogthing was in :message and :VimtexLog:

09:25:41: info
  #1 C:\Users\maksim.kim\vimfiles\pack\plug\start\vimtex\autoload\vimtex\log.vim:16
  In vimtex#log#info
    call s:logger.add(a:000, 'info')
  #2 C:\Users\maksim.kim\vimfiles\pack\plug\start\vimtex\autoload\vimtex\compiler\latexmk.vim
  In 54
    call vimtex#log#info('Compiler clean finished' . (a:full ? ' (full)' : ''))
  #3 C:\Users\maksim.kim\vimfiles\pack\plug\start\vimtex\autoload\vimtex\compiler.vim:259
  In vimtex#compiler#clean
    call b:vimtex.compiler.clean(a:full)
  Compiler clean finished

I couldn't find definition of b:vimtex.compiler.clean though :)

@habamax
Copy link
Contributor Author

habamax commented Aug 20, 2021

I found the command that is run on clean:

cd /D "C:\Users\maksim.kim\temp" & latexmk -c  -outdir=minimal "minimal.tex"

And it works
image

Files are deleted:
image

@lervag
Copy link
Owner

lervag commented Aug 20, 2021

The same with minimal vimrc and tex file that are suggested in issue creation -- nothing is deleted.

Very good; basing things on a minimal example makes it much simpler for me to help!

min.vimrc

I would assume the issue persists without changing the _engines options and also without adding the -verbose flag. I.e., I propose the following minimal vimrc file (please confirm):

set nocompatible
let &runtimepath  = '~/vimfiles/pack/plug/start/vimtex,' . &runtimepath
let &runtimepath .= ',~/vimfiles/pack/plug/start/vimtex/after'
filetype plugin indent on
syntax enable

let g:vimtex_compiler_latexmk = {'build_dir': {-> expand("%:t:r")}}

If I remove build_dir from the settings, all the files are in the same directory and still are not deleted after VimtexClean.

Is this still true with the proposed minimal vimrc?

I couldn't find definition of b:vimtex.compiler.clean though :)

b:vimtex.compiler.clean is the same as the s:compiler.clean in latexmk.vim, i.e.:

function! s:compiler.clean(full) abort dict " {{{1
let l:restart = self.is_running()
if l:restart
call self.stop()
endif
" Define and run the latexmk clean cmd
let l:cmd = (has('win32')
\ ? 'cd /D "' . self.root . '" & '
\ : 'cd ' . vimtex#util#shellescape(self.root) . '; ')
\ . self.executable . ' ' . (a:full ? '-C ' : '-c ')
if !empty(self.build_dir)
let l:cmd .= printf(' -outdir=%s ', fnameescape(self.build_dir))
endif
let l:cmd .= vimtex#util#shellescape(self.target)
call vimtex#process#run(l:cmd)
call vimtex#log#info('Compiler clean finished' . (a:full ? ' (full)' : ''))
if l:restart
let self.silent_next_callback = 1
silent call self.start()
endif
endfunction

I found the command that is run on clean:
...
And it works

How did you find it? And with "it works", you mean it works when you run it in your own terminal?

@habamax
Copy link
Contributor Author

habamax commented Aug 20, 2021

The command that is being used by vimtex is actually this one:

"start /b cmd /s /c "cd /D "C:\Users\maksim.kim\temp" & latexmk -c  -outdir=minimal "minimal.tex" >nul""

And if I run it from within my home directory (which I am in when I do clean up call for vimtex):

image

It fails to actually goto the specified dir.

@lervag
Copy link
Owner

lervag commented Aug 20, 2021

You have the same problem also without the build_dir option, right? If so, please simplify and let's focus on the most basic errors first.

A major problem here is that I don't use Windows. I don't test on Windows. So it is very hard for me to fix issues like this. I've relied on help from the community to figure out how to fix and implement things on Windows. Still, as far as I know, there are several VimTeX users on Windows, so it is surprising if this is a problem even with a fully minimal example! It makes it appear to me that something that works for many people suddenly is not working for you. 😕

@habamax
Copy link
Contributor Author

habamax commented Aug 20, 2021

You have the same problem also without the build_dir option, right? If so, please simplify and let's focus on the most basic errors first.

Yes indeed.

I don't test on Windows. So it is very hard for me to fix issues like this.

I can totally understand it, no problem here.

It makes it appear to me that something that works for many people suddenly is not working for you. 😕

Or

  • they never tried cleanup :).
  • their cwd is in the same as tex file cwd

While writing the last bullet -- it striked me -- I have always run :VimtexClean from the CWD which is not CWD of the tex file :).

Have just tried to run it from the same CWD -- it works!

But looking at the source code and the command that should delete all the stuff, I can see it tries to goto the directory of the tex file to clean things up. It just fails to go there in the first place and latexmk then "cleans up" things from non tex file path.

I have tried that command that Vimtex uses

"start /b cmd /s /c "cd /D "C:\Users\maksim.kim\temp""

on a cmd.exe and it fails with The system cannot find the path specified

@habamax
Copy link
Contributor Author

habamax commented Aug 20, 2021

Next command works for me:

start /D "C:\Users\maksim.kim\temp" cmd /c "latexmk -c  -outdir=minimal "minimal.tex"" >nul

Note

  • there is no " " for the whole start command, otherwise it can't find directory specified.
  • /D is used to specify path for a start command

@habamax
Copy link
Contributor Author

habamax commented Aug 20, 2021

Actually, existing command also works if you remove "" over full command:

start /b cmd /s /c "cd /D "C:\Users\maksim.kim\temp" & latexmk -c  -outdir=minimal "minimal.tex" >nul"

Actual "as-of-now" command used by vimtex:

"start /b cmd /s /c "cd /D "C:\Users\maksim.kim\temp" & latexmk -c  -outdir=minimal "minimal.tex" >nul""
^ <-- this "                                                                           and that -->    ^                                                                                                                            

@habamax
Copy link
Contributor Author

habamax commented Aug 20, 2021

So, if I change these lines from process.vim lines 170-174:

    if self.silent && self.output ==# 'null'
      let self.prepared_cmd = '"' . l:cmd . '"'
    else
      let self.prepared_cmd = l:cmd
    endif

to

      let self.prepared_cmd = l:cmd

then VimtexClean works for me :)

@habamax
Copy link
Contributor Author

habamax commented Aug 24, 2021

@lervag could you tell me how can I tell vimtex that I want neither silent nor output != 'null?

I don't want to create and sync my own fork only for this change :)

PS, I am not sure what windows version would work with the command that is constructed in the end.

@lervag
Copy link
Owner

lervag commented Aug 24, 2021

I don't test on Windows. So it is very hard for me to fix issues like this.

I can totally understand it, no problem here.

Glad to hear that.

It makes it appear to me that something that works for many people suddenly is not working for you. confused

Or

  • they never tried cleanup :).

  • their cwd is in the same as tex file cwd

Yes, that might also be true.

While writing the last bullet -- it striked me -- I have always run :VimtexClean from the CWD which is not CWD of the tex file :).

Have just tried to run it from the same CWD -- it works!

Interesting!

But looking at the source code and the command that should delete all the stuff, I can see it tries to goto the directory of the tex file to clean things up. It just fails to go there in the first place and latexmk then "cleans up" things from non tex file path.

I have tried that command that Vimtex uses ...
...
Actually, existing command also works if you remove "" over full command:

Interesting, I'm glad that you are working on this and investigating!

So, if I change these lines from process.vim lines 170-174:

...

then VimtexClean works for me :)

Ok! I'm tempted to simply make that change. However, there's a small chance that it will break something. This worries me.

@lervag could you tell me how can I tell vimtex that I want neither silent nor output != 'null?

I don't believe there is a simple way to do that; sorry! Also, I would prefer to fix things instead of adding options, if that is possible.

I don't want to create and sync my own fork only for this change :)

PS, I am not sure what windows version would work with the command that is constructed in the end.

Would you mind if I called your attention if, after making this change, someone reports an issue that seems related to this change?

@habamax
Copy link
Contributor Author

habamax commented Aug 24, 2021

Would you mind if I called your attention if, after making this change, someone reports an issue that seems related to this change?

Sure, would be glad to help!

@lervag
Copy link
Owner

lervag commented Aug 24, 2021

From git blame, I find that the relevant code was changed due to #1256. I'm not sure if @vanabel is still active and still uses VimTeX. But if that's the case, then it seems useful to provide this notification.

@lervag
Copy link
Owner

lervag commented Aug 24, 2021

Reading #1256, I get the impression that the fix implemented there was not really very well justified. So I'll revert it for now. If @vanabel or anyone else then has an issue similar to #1256, then I could help investigate it and perhaps also ask you to assist.

So, with that: I'll push the change asap.

lervag added a commit that referenced this issue Aug 24, 2021
This reverses the fix from #1256.

refer: #2139, #1256
@habamax
Copy link
Contributor Author

habamax commented Aug 25, 2021

Works like a charm now, thank you!

@lervag
Copy link
Owner

lervag commented Aug 25, 2021

Glad to hear it!

@lervag lervag closed this as completed Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants