Giter Club home page Giter Club logo

Comments (9)

baod-rate avatar baod-rate commented on July 20, 2024 2

deleted my comment on accident, but it said:

string.match(buffer.name:reverse(), "^(%a+)"):reverse()

should be

string.match(buffer.name:reverse(), "^([^./]+)"):reverse()

or it'll break on extensions with numbers

this is also equivalent:

string.match(vim.api.nvim_buf_get_name(0), "^.+[./](.+)$")

of course vim.fn.expand("%:e") is easier than all of that, lol

from nvim-web-devicons.

hkupty avatar hkupty commented on July 20, 2024 1

Seems fair. I've actually encounter another compelling reason to map filetype and extension (when limiting search to files of the same file type), so I've created a separate plugin for this.

I guess this can be considered solved then. Thanks for the consideration nonetheless.

Best regards,

from nvim-web-devicons.

kyazdani42 avatar kyazdani42 commented on July 20, 2024

that's a good suggestion. Although it would probably slow down the plugin, because the filetype is given for a buffer and not for a file. I don't know if there is an existing vim function to get the filetype of a file.

from nvim-web-devicons.

hkupty avatar hkupty commented on July 20, 2024

🤔 Maybe we can have a mapping from extension to ft for those cases. My usecase is to have the icon+highlight in the statusbar, so it's easier if I use the - already available - filetype. :)

from nvim-web-devicons.

akinsho avatar akinsho commented on July 20, 2024

@hkupty I currently use this in my statusline with

let extension = fnamemodify(bufname(), ':e')

To pass the extension in to the get_icon function. If that helps 🤷🏿‍♂️ .

from nvim-web-devicons.

hkupty avatar hkupty commented on July 20, 2024

I use something similar for now:

          local extension = string.match(buffer.name:reverse(), "^(%a+)"):reverse()
          local ok, icon, hl = pcall(require("nvim-web-devicons").get_icon, buffer.name, extension)

The thing is, some files like bash scripts don't have extensions. Also, you can manually force a filetype with a modeline, so I guess it'd be more resilient if relying on the filetype instead.

from nvim-web-devicons.

kyazdani42 avatar kyazdani42 commented on July 20, 2024

this would slow down the whole process... i think most plugins use this small library to enhance the ui of their file display, which in most case, requires a good performance. Adding a layer for the filetype would probably make those plugin authors not really happy. You can map you filetypes on files withouth an extension to return an extension for your statusbar, and fall back to the file extension otherwise, which would help displaying the right icon !
like so:

local mapFtToExt = { sh = "sh", python = "py" }
local filetype = api.nvim_buf_get_option(0, "ft")
let extension = fnamemodify(bufname(), ':e')
require"nvim-web-devicons".get_icon(buffer.name, mapFtToExt[filetype] or extension)

from nvim-web-devicons.

kyazdani42 avatar kyazdani42 commented on July 20, 2024

or we could add definitions and you could pass extension or filetype to the extension param.

from nvim-web-devicons.

hkupty avatar hkupty commented on July 20, 2024

Thanks for the heads up. That didn't cross my mind.

from nvim-web-devicons.

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.