I would like to configure neovim (0.7.0) with lua, without plugins.
I've configured line number via vim.wo.number = true. I guess it would similarly works if I use vim.o.statusline = "%F" to let the statusline show file name / path.
However, my neovim's statusline is still empty. How can I change my init.lua, to let the statusline show filepath?
Currently the init.lua is:
vim.wo.number = true
vim.o.smarttab = true
vim.bo.expandtab = true
vim.bo.shiftwidth = 4
vim.bo.tabstop = 4
vim.o.statusline = "%F"
vim.wo.statusline = '%F'
vim.o.laststatus = 2
According to :help
The value of this option influences when the last window will have a
status line:
0: never
1: only if there are at least two windows
2: always
The screen looks nicer with a status line if you have several
windows, but it takes another screen line. status-line
Related
I tried to use this simple script (its not from me) for simple reading a file and adding its content to a plugin called projectionist: https://github.com/tpope/vim-projectionist
(The original script: https://github.com/andyl/vim-projectionist-elixir/blob/master/ftdetect/elixir.vim)
I didn't find any api for reading a file in lua nvim. The error in the picture targets the line let l:json = readfile(s:proj_jsn) so I assume that this api is not available by lua?
if vim.g.loaded_vim_projectionist then
return
end
vim.g.loaded_vim_projectionist = 1
vim.api.nvim_exec([[
let s:base_dir = resolve(expand("<sfile>:p:h"))
let s:proj_jsn = s:base_dir . "/projections.json"
function! s:setProjections()
let l:json = readfile(s:proj_jsn)
let l:dict = projectionist#json_parse(l:json)
call projectionist#append(getcwd(), l:dict)
endfunction
call s:setProjections()
]], false)
The error message (picture)
I checked a several times if the file projections.json is in the right place, so this is not the mistake.
Thank you all in advance.
This code is for a modding engine, Unitale base on Unity Written in Lua
So I am trying to use a Boolean Variable in my script poseur.lua, so when certain conditions are met so I can pass it to the other script encounter.lua, where a engine Predefined functions is being uses to make actions happens base on the occurring moment.
I tried to read the engine documentation multiple times, follow the exact syntax of Lua's fonction like GetVar(), SetVar(), SetGobal(),GetGlobal().
Searching and google thing about the Language, post on the subreddit and Game Exchange and tried to solve it by myself for hours... I just can't do it and I can't understand why ?
I will show parts of my codes for each.
poseur:
-- A basic monster script skeleton you can copy and modify for your own creations.
comments = {"Smells like the work\rof an enemy stand.",
"Nidhogg_Warrior is posing like his\rlife depends on it.",
"Nidhogg_Warrior's limbs shouldn't\rbe moving in this way."}
commands = {"GREET", "JUMP", "FLIRT", "CRINGE"}
EndDialougue = {" ! ! !","ouiii"}
sprite = "poseur" --Always PNG. Extension is added automatically.
name = "Nidhogg_Warrior"
hp = 99
atk = 1
def = 1
check = "The Nidhogg_Warrior is\rsearching for the Nidhogg"
dialogbubble = "rightlarge" -- See documentation for what bubbles you have available.
canspare = false
cancheck = true
GreetCounter = 5
Berserk = false
encounter:
-- A basic encounter script skeleton you can copy and modify for your own creations.
encountertext = "Nidhogg_Warrior is\rrunning frantically"
nextwaves = {"bullettest_chaserorb"}
wavetimer = 5.0
arenasize = {155, 130}
music = "musAncientGuardian"
enemies = {"poseur"}
require("Monsters.poseur")
enemypositions = {{0, 0}}
-- A custom list with attacks to choose from.
-- Actual selection happens in EnemyDialogueEnding().
-- Put here in case you want to use it.
possible_attacks = {"bullettest_bouncy", "bullettest_chaserorb", "bullettest_touhou"}
function EncounterStarting()
-- If you want to change the game state immediately, this is the place.
Player.lv = 20
Player.hp = 99
Player.name = "Teemies"
poseur.GetVar("Berserk")
end
Thank you for reading.
The answer to my problem was to use SetGobal(), GetGobal().
For some reasons my previous attempt to simply use SetGobal()Resulted in nil value despite writing it like that SetGobal("Berserk",true) gave me a nill value error, as soon as I launch the game.
But I still used them wrong. First I needed to put it SetGobal() at the end of the condition instead of at the start of the the poseur.lua script because the change of value... for some reasons was being overwritten by it first installment.
And to test the variable in the function in my encounter.lua, I needed to write it like that
function EnemyDialogueStarting()
-- Good location for setting monster dialogue depending on how the battle is going.
if GetGlobal("Jimmies") == true then
TEEEST()
end
end
Also any tips an suggestions are still welcome !
Well firstly, in lua simple values like bool and number are copied on assignment:
global={}
a=2
global.a=a--this is a copy
a=4--this change won't affect value in table
print(global.a)--2
print(a)--4
Secondly,
SetGobal and the other mentioned functions are not part of lua language, they must be related to your engine. Probably, they use word 'Global' not as lua 'global' but in a sense defined by engine.
Depending on the engine specifics these functions might as well do a deep copy of any variable they're given (or might as well not work with complicated objects).
I'm having a problem where I can do every single function in a command line version of lua however, when I run the program it won't throw any errors it just ends.I'm not sure how to diagnose this but I have tried getting an error to be thrown a couple times for different things and it will error and print the error.
power = peripheral.wrap("bottom")
mon = peripheral.wrap("top")
x,y = mon.getSize()
clearTerm = function()
term.clear()
term.setCursorPos(1,1)
end
clearBoth = function()
clearMon()
clearTerm()
end
intLen = function(bar)
tab = tostring(bar)
tab = string.len(tab)
return tab
end
checkPower = function()
total = power.getMaxEnergyStored()
local til = intLen(total)
local yy = math.floor(y/2)
local tol = math.floor(x-til)
mon.setCursorPos(yy+0,tol/2)
for z=1,til do mon.write("-") end
mon.setCursorPos(yy-1,tol/2)
mon.write(total)
while true do
current = power.getEnergyStored()
local cil = intLen(current)
local col = math.floor(x-cil)
mon.setCursorPos(yy+1,col/2)
mon.write(current)
sleep(1)
end
end
I'll leave a link to the pastebin of the full program here too.
First of all, you can add some outputs to your code. Just add stuff like
print "1" -- debug output
...
print "2" -- debug output
...
-- don't forget to remove these after you're done debugging!
to your code and see how many of them you see when running the program, this way you can narrow down when exactly the program crashes.
Also, I cannot find where the function clearMon() is defined, might that be source the problem, or is it defined elsewhere?
when using this very short script on the lua console on BizHawk (it's an emulator), Both the LUA console and BizHawk crashes at the same time.
I'd like to know if the error comes from my script or from BizHawk, her's the script: (What it is supposed to do is check if the player is not moving for a certain time period [TimeoutConstant] and if he is [cause he's dead, stuck or afk] the script loads a saved state called Filename and it starts again. Here's the script:
Filename = "yolo.state"
TimeoutConstant = 80
rightmost = 0
timeout = TimeoutConstant
function initializeRun()
savestate.load(Filename)
rightmost = 0
timeout = TimeoutConstant
end
function getPositions()
marioX = memory.read_s16_le(0x94)
marioY = memory.read_s16_le(0x96)
local layer1x = memory.read_s16_le(0x1A);
local layer1y = memory.read_s16_le(0x1C);
screenX = marioX-layer1x
screenY = marioY-layer1y
end
initializeRun()
while true do
getPositions()
if marioX > rightmost then
rightmost = marioX
timeout = TimeoutConstant
end
if timeout <= 0 then
initializeRun()
end
timeout = timeout - 1
end
I assume by "crash" you mean "freeze" which is not at all the same thing. It's freezing because your script is putting the emulator into a busy loop. You didn't do anything to advance time in the emulator. The final two lines of your script need to be:
emu.frameadvance();
end
BTW, with emulator lua scripts, the name of the game being scripted is essential information.
I need help with opening the result of my mail merge operations directly in an new writer document.
Object mailMergeService = mcf.createInstanceWithContext(mailMergePackage, context);
XPropertySet mmProperties = UnoRuntime.queryInterface(XPropertySet.class, mailMergeService);
mmProperties.setPropertyValue("DocumentURL", templatePath);
mmProperties.setPropertyValue("DataSourceName", dbName);
mmProperties.setPropertyValue("CommandType", mmCommandType);
mmProperties.setPropertyValue("Command", mmCommand);
mmProperties.setPropertyValue("OutputType", mmOutputType);
// mmProperties.setPropertyValue("OutputURL", templateDirectory);
// mmProperties.setPropertyValue("FileNamePrefix", mmFileNamePrefix);
// mmProperties.setPropertyValue("SaveAsSingleFile", mmSaveAsSingleFile);
The mmOutputType is set as MailMergeType.SHELL
The LibreOffice API documentation says
"The output is a document shell.
The successful mail marge returns a XTextDocument based component."
So I've tried something like this
XJob job = UnoRuntime.queryInterface(XJob.class, mailMergeService);
Object mergedTextObject = job.execute(new NamedValue[0]);
String url = "private:factory/swriter";
loader.loadComponentFromURL(url, "_blank", 0, new PropertyValue[0]);
XTextDocument mergedText = UnoRuntime.queryInterface(XTextDocument.class, mergedTextObject);
XTextCursor cursor = mergedText.getText().createTextCursor();
cursor.setString(mergedText.getText().getString());
I guess I have to pass the XTextDocument component to the url-argument of the loadComponentFromURL method but I didnt find the right way to do that.
When I change the OutputType to MailMergeType.FILE the result is generated in a given directory and I can open the file and see that the mail merge succeeded. But this is not what my application should do.
Does someone know how I can open the result of the mail merge directly in an new writer document without saving the result to the hard drive?
Sincerly arthur
Hey guys I've found a simple way to open the result of my mail merge process directly.
The relevant snippets are these
XJob job = UnoRuntime.queryInterface(XJob.class, mailMergeService);
Object mergedTextObject = job.execute(new NamedValue[0]);
XTextDocument mergedText = UnoRuntime.queryInterface(XTextDocument.class, mergedTextObject);
mergedText.getCurrentController().getFrame().getContainerWindow().setVisible(true);
The last line of code made the window appear with the filled mail merge result.
I also don't need this line anymore
loader.loadComponentFromURL("private:factory/swriter", "_blank", 0, new PropertyValue[0]);
The document opens as a new instance of a swriter document. If you want to save the result as a file you can do this
mergedText.getCurrentController().getFrame().getContainerWindow().setVisible(true);
XStorable storeMM = UnoRuntime.queryInterface(XStorable.class, mergedText);
XModel modelMM = UnoRuntime.queryInterface(XModel.class, mergedText);
storeMM.storeAsURL(outputDirectory + outputFilename, modelMM.getArgs());
Sincerly
Arthur
What version of LO are you using? The SHELL constant has only been around since LO 4.4, and it is not supported by Apache OpenOffice yet, so it could be that it isn't fully implemented. However this code seems to show a working test.
If it is returning an XTextDocument, then normally I would assume the component is already open. However it sounds like you are not seeing a Writer window appear. Did you start LO in headless mode? If not, then maybe the process needs a few seconds before it can display.
Object mergedTextObject = job.execute(new NamedValue[0]);
Thread.sleep(10000);
Anyway to me it looks like your code has a mistake in it. These two lines would simply insert the text onto itself:
XTextCursor cursor = mergedText.getText().createTextCursor();
cursor.setString(mergedText.getText().getString());
Probably you intended to write something like this instead:
XTextDocument mergedText = UnoRuntime.queryInterface(XTextDocument.class, mergedTextObject);
String url = "private:factory/swriter";
XComponent xComponent = loader.loadComponentFromURL(url, "_blank", 0, new PropertyValue[0]);
XTextDocument xTextDocument = (XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, xComponent);
XText xText = (XText)xTextDocument.getText();
XTextRange xTextRange = xText.getEnd();
xTextRange.setString(mergedText.getText().getString());
One more thought: getString() might just return an empty string if the entire document is in a table. If that is the case then you could use the view cursor or enumerate text content.
EDIT:
To preserve formatting including tables, you can do something like this (adapted from https://blog.oio.de/2010/10/27/copy-and-paste-without-clipboard-using-openoffice-org-api/):
// Select all.
XController xMergedTextController = mergedText.getCurrentController();
XTextViewCursorSupplier supTextViewCursor =
(XTextViewCursorSupplier) UnoRuntime.queryInterface(
XTextViewCursorSupplier.class, xMergedTextController);
XTextViewCursor oVC = supTextViewCursor.getViewCursor();
oVC.gotoStart(False) // This would not work if your document began with a table.
oVC.gotoEnd(True)
// Copy and paste.
XTransferableSupplier xTransferableSupplier = UnoRuntime.queryInterface(XTransferableSupplier.class, xMergedTextController);
XTransferable transferable = xTransferableSupplier.getTransferable();
XController xController = xComponent.getCurrentController();
XTransferableSupplier xTransferableSupplier_newDoc = UnoRuntime.queryInterface(XTransferableSupplier.class, xController);
xTransferableSupplier_newDoc.insertTransferable(transferable);