Skip to content

[FR]: Add SCSendFile command #263

@madskjeldgaard

Description

@madskjeldgaard

SCSendFile is a command that without arguments evaluates the currently open file, and optionally it can be run with the path for a file. In either case it will send the contents of that file to the running sclang instance controlled by scnvim. This is useful in creating automated startups etc with scnvim (for me personally for making a nice setup with tidal).

This is what I have in my personal config file for scnvim, but I realized it may be universally useful. Should I make a PR @davidgranstrom ?

-- Send a whole file to the sclang process
      local function send_whole_file_raw(opts)
        local scnvim = require'scnvim'

        -- Read the file directly from disk to get raw content
        local filename = opts.args ~= "" and opts.args or vim.api.nvim_buf_get_name(0)

        local file = io.open(filename, "r")
        if not file then
          vim.notify("Could not read file: " .. filename, vim.log.levels.ERROR)
          return
        end

        local code = file:read("*a")
        file:close()

        -- Send the raw file content
        scnvim.send(code)
      end

      -- Create command with optional file argument
      vim.api.nvim_create_user_command('SCSendFile', send_whole_file_raw, {
        nargs = '?',  -- Optional argument
        complete = 'file',  -- File path completion
      })

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions