martineausimon / nvim-lilypond-suite

Neovim plugin for writing LilyPond scores, with asynchronous make, midi/mp3 player, fast syntax highlighting, "hyphenation" function, and support for LaTex and Texinfo files
GNU General Public License v3.0
130 stars 11 forks source link

fix(make): escape file path when running lilypond #33

Closed suiso67 closed 1 month ago

suiso67 commented 1 month ago

I noticed that if I run compile lilypond command when:

, then the compiled pdf/midi files are saved under /foo/bar(/foo/bar/main.pdf, /foo/bar/main.midi), not under /foo/bar baz

I'm not really familiar with lilypond command so I don't know why it doesn't have the same problem when I don't set lilypond.options.include_dir, but nonetheless the path should be escaped.

martineausimon commented 1 month ago

Thank you! It's perfect and respects the way the plugin is written. However, I should take some time to modify the make function and replace the shellescape() command with a simple %q in string.format, like for example:

string.format('lilypond %s %s -f %s -o %q %s', C.backend, C.include, C.output_fm, Utils.joinpath(folder, name), C.main)

I wasn't aware of this possibility when I created this function...

martineausimon commented 1 month ago

I took a closer look, and your solution causes an issue for files whose names contain a space because the filename is already escaped.

I think the error comes from here:

local C = Config.fileInfos()
local folder = vim.fn.expand(C.folder)

The value of C.folder is already in the correct format, and it's the vim.fn.expand function that removes the escaped values.

This should be good :

local folder = C.folder
suiso67 commented 1 month ago

You're right, I didn't notice that. IMHO it would be nice to know whether a path or file name is escaped or not by reading it's name. Like adding _path to the end of escaped/safe path string, such as C.folder_path.

Anyway, sorry for the oversight, and thank you for the quick patch. Now I can keep transcribing.