create lua autocommand to make mason window transparent - lua

I want to make the Mason window transparent, in neovim, using lua.
Here was suggested to set winbled locally as autocommand but its not using the newer lua api: https://github.com/williamboman/mason.nvim/discussions/355.
autocmd FileType mason setlocal winblend=10
I am trying to do the same with lua:
vim.api.nvim_create_autocmd("FileType", {
pattern = "mason",
callback = function() vim.opt_local.winblend = 10 end,
})
Nothing is happening after sourcing this. No error and no transparent window.

Related

LibreOffice: embed script in script URL

In LibreOffice, It is possible to run python scripts like this:
sURL = "vnd.sun.star.script:file.function?language=Python&location=document"
oScript = scriptProv.getScript(sURL)
x = oScript.Invoke(args, Array(), Array())
In that example 'file' is a filename, and 'function' is the name of a function in that file.
Is it possible to embed script in that URL? sURL="vnd.." & scriptblock & "?language.."
(It seems like the kind of thing that might be possible with the correct URL, or might not be possible if just not supported).
We can use Python's eval() function. Here is an example inspired by JohnSUN's explanation in the discussion. Note: xray() uses XrayTool to show output, but you could replace that line with any output method of your choosing, such as writing to a file.
def runArbitraryCode(*args):
url = args[0]
codeString = url.split("&codeToRun=")[1]
x = eval(codeString)
xray(x)
Now enter this formula in Calc and Ctrl+click on it.
=HYPERLINK("vnd.sun.star.script:misc_examples.py$runArbitraryCode?language=Python&location=user&codeToRun=5+1")
Result: 6
Obligatory caveat: Running eval() on an unknown string is about the worst idea imaginable in terms of security. So hopefully you're the one controlling the URL and not some black hat hacker!

Neovim lua cannot change color in autocmd

I'm transitioning my neovim configuration from vimscript to lua. The following code is intended to change the color of the message area as the mode changes, as I did in the old configuration, but it is having no effect.
Changing the MsgArea any color I want outside the autocmd works fine
These debug messages print as expected when I change mode, so I know the autocmd is working
The MsgArea color does not change with the mode
I'm new to lua. Can you identify a syntax or conceptual problem here?
local normal_fg="#00ff00"
local normal_bg="#202020"
local insert_fg="#202020"
local insert_bg="#00ff00"
vim.api.nvim_set_hl(0,'MsgArea',{fg=normal_fg,bg=normal_bg,bold=true}) -- works fine
vim.api.nvim_create_autocmd( "InsertEnter",{ pattern="*",
callback=function()
vim.api.nvim_set_hl(0,'MsgArea',{fg=insert_fg,bg=insert_bg,bold=true}) -- no effect
print("inverted the colors") -- works fine
end
})
vim.api.nvim_create_autocmd( "InsertLeave",{ pattern="*",
callback=function()
vim.api.nvim_set_hl(0,'MsgArea',{fg=normal_fg,bg=normal_bg,bold=true}) -- no effect
print("back to normal") -- works fine
end
})
NVIM v0.7.2

Migrate Vim/Vimscript for asynchronously running external editors to Lua/Neovim

In my Vim's configuration file init.vim I am using code, that sets a default viewer for practically any kind of file suffix. Here I will demonstrate only an example for .md files:
let g:netrw_browsex_viewer="-"
function! NFH_md(f)
call asyncrun#run("", "cwd", "typora " . a:f)
endfunction
First paragraph makes sure to choose the function based on suffix of the file ("URI under cursor"). Second paragraph shows a function whose name i.e. NFH_md implies that this is the function opened when .md file is in the "URI under the cursor". Inside this function there is an call that opens an external program typora asynchronously so that I am still able to continue using Vim.
If you want to know more use :help netrw_browsex_viewer.
I tried porting the mentioned Vim script to Neovim & Lua but I only managed to port first line:
vim.g.netrw_browsex_viewer="-"
For I don't know, how to properly port the second paragraph. This is why for now I just use Vimscript source code like this:
vim.api.nvim_exec(
[[
function! NFH_md(f)
call asyncrun#run("", "cwd", "marktext " . a:f)
endfunction
]],
false
)
But I would love to translate all the code to Lua - Could anyone help a bit to translate this remaining Vimscript code to Lua?

Ghostscript with a Zebra ZM600

I have created a program which takes a PDF and prints it using Ghostscript.NET.
The printer in question is a Zebra ZM600, and the printing works fine. However I would like to do some adjustments to the labels, and this can be done using the driver. When I print using Adobe Reader, the adjustments work, but when I use the program which I have created to print the file, it seems like GhostScript.NET does something with the properties as this doesn't work at all (it is printed but the adjustments doesn't work).
using (GhostscriptProcessor processor = new GhostscriptProcessor())
{
List<string> switches = new List<string>();
switches.Add("-empty");
switches.Add("-dPrinted");
switches.Add("-dBATCH");
switches.Add("-dNoCancel");
switches.Add("-dNOPAUSE");
switches.Add("-dNOSAFER");
switches.Add("-dNumCopies=1");
switches.Add("-sDEVICE=mswinpr2");
switches.Add("-sOutputFile=%printer%" + printerName);
switches.Add("-f");
switches.Add(path);
processor.StartProcessing(switches.ToArray(), null);
_logger.Info("After starting process");
}
The question is, does anybody know if there is a way to force Ghostscript to use the adjustments on the printer driver? Or if there are any better alternatives for printing PDFs on a label printer?

Setting a file path as text to clipboard in LUA

I am a total noob to LUA.
I need a script that will just copy a file path as text to the clipboard. That's it. I absolutely cannot figure it out. I keep getting the error:
attempt to call a nil value (global 'set_clipboard')
Here is the file path I am trying to copy to the clipboard:
D:_Google Drive_Acting\VO\Room Tone\roomtone.wav
This must be a simple script, right?
For Windows you can do this:
filename = 'my_filename.txt'
io.popen('clip','w'):write(filename):close()
There is no built-in function for that.
In Mac OS, you can do this
function set_clipboard(text)
io.popen('pbcopy','w'):write(text):close()
end
Apparently, in Windows you can use clip instead of pbcopy. I don't know about Linux.

Resources