GithubHelp home page GithubHelp logo

to_hex transform about lush.nvim HOT 3 CLOSED

rktjmp avatar rktjmp commented on June 12, 2024
to_hex transform

from lush.nvim.

Comments (3)

rktjmp avatar rktjmp commented on June 12, 2024

Hmm.

hsl types will convert to hex when they're coerced into strings, so I would opt to call tostring in apply_template automatically. Any value you pass in you explicitly want as a string in the template, and this lets other types with a tostring work automatically too.

local function apply_template(template, map)
  -- ensure that each replacement value is a string
  local replacements = {}
  for key, val in pairs(map) do
    replacements[key] = tostring(val)
  end
  local output = string.gsub(template, "$([%w%d_]+)", replacements)
  return output
end

This does mean if you pass in a table you'll get table 0xdeadbeef instead of a lua invalid replacement error, but I think it's probably the right step anyway.

Wonder if it's worth checking for table|function 0x\d+ as a value and warning. People who want that value explicitly could pass that in as a string if they really want it. Sometimes that kind of "smarts" can be annoying though, especially if it's applied inconsistently.

from lush.nvim.

rktjmp avatar rktjmp commented on June 12, 2024

Fixed (?) in rktjmp/shipwright.nvim@114c3a1

Not sure if it's still worth having a to_hex transform if having templates work automatically probably covers most use cases?

If there was some other internal transform you had to do, I think you'd be operating at a point where you're already looping a whole spec and can just add .hex to that function, or it might be working automatically if you're doing some kind of Normal.fg .. "-something-something"?

Not a no, but a concrete usecase might be needed.

from lush.nvim.

mcchrish avatar mcchrish commented on June 12, 2024

Not sure if it's still worth having a to_hex transform if having templates work automatically probably covers most use cases?

No need I think and the current solution is better imo.

from lush.nvim.

Related Issues (20)

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.