Git Product home page Git Product logo

Comments (4)

Guldoman avatar Guldoman commented on August 13, 2024 1

Starting from the example in the README:

local core = require "core"
local command = require "core.command"
local keymap = require "core.keymap"
local console = require "plugins.console"

command.add("core.docview", {
  ["project:build-project"] = function()
    core.log "Building..."
    local build_command
    if string.match(core.active_view.doc.filename, "%.lua$") then
      build_command = "./build_lua.sh"
    elseif string.match(core.active_view.doc.filename, "%.c$") then
      build_command = "./build_c.sh"
    else
      return
    end
    console.run {
      command = build_command,
      file_pattern = "(.*):(%d+):(%d+): (.*)$",
      cwd = ".",
      on_complete = function(retcode) core.log("Build complete with return code "..retcode) end,
    }
  end
})

keymap.add { ["ctrl+b"] = "project:build-project" }

this will run build_lua.sh if you're currently in a Lua file, or build_c.sh if you're in a C file.

from console.

sheetcoder avatar sheetcoder commented on August 13, 2024

@Guldoman Consider this scenario, lets say I have a folder called "Project" and in that folder I have multiple python files file1.py, file2.py,.....file10.py How do I write a general build script such that when lite-xl focus file1.py it should only run that python script (ctrl+b) and if I change my focus to file3.py and run (ctrl+b) it should only run that python script.

from console.

Guldoman avatar Guldoman commented on August 13, 2024

Starting from the example I provided, add a new string.match condition that matches python files and set the build_command variable like this:

build_command = string.format("python %q", core.active_view.doc.abs_filename)

This will run python /path/to/current_file.py.

from console.

sheetcoder avatar sheetcoder commented on August 13, 2024

it worked and thank you for helping me. A suggestion if possible can you edit the readme to include this information as well, for noobs like me this is much more simpler.

local core = require "core"
local command = require "core.command"
local keymap = require "core.keymap"
local console = require "plugins.console"

command.add("core.docview", {
  ["project:build-project"] = function()
    core.log "Building..."
    local build_command
    if string.match(core.active_view.doc.filename, "%.py$") then
      build_command = string.format("python %q", core.active_view.doc.abs_filename)
    elseif string.match(core.active_view.doc.filename, "%.c$") then
      build_command = "./build_c.sh"
    elseif string.match(core.active_view.doc.filename, "%.lua$") then
      build_command = "./build_lua.sh"
    else
      return
    end
    console.run {
      command = build_command,
      file_pattern = "(.*):(%d+):(%d+): (.*)$",
      cwd = ".",
      on_complete = function(retcode) core.log("Build complete with return code "..retcode) end,
    }
  end
})

keymap.add { ["ctrl+b"] = "project:build-project" }

from console.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.