Functions builtin.file and builtin.file_relative return full path
PanagiotisS opened this issue · comments
Problems summary
The functions builtin.file
and builtin.file_relative
return the full path.
I do not know if this intentional, however, given that builtin.file_relative = builtin.file
, I assume that we would like the relative path, similar to statusline=%f
, as also the line commented line 12 hints.
If the above assumption is wrong, please ignore and close the report.
Environment Information
-
neovim version:
neovim-0.4.4.0.git.14889.c6ccdda26
-> neovim/neovim@c6ccdda -
plenary version: nvim-lua/plenary.nvim@c8287c3
-
express_line version: 903dc60
Minimal init.vim
set encoding=utf-8
scriptencoding utf-8
" Dein
let s:path = expand(stdpath('config') . '/bundle')
let &runtimepath .= ',' . expand(stdpath('config') . '/bundle/repos/github.com/Shougo/dein.vim/')
if dein#load_state(s:path)
call dein#begin(s:path, [expand('<sfile>'),])
call dein#add('Shougo/dein.vim',)
call dein#add('nvim-lua/plenary.nvim')
call dein#add('tjdevries/express_line.nvim')
call dein#end()
call dein#save_state()
endif
filetype plugin indent on
syntax enable
set number
set nowrap
set bg=light
lua << EOF
local generator = function()
local el_segments = {}
-- This will return the full path - see screenshot 1
local builtin = require('el.builtin')
table.insert(el_segments, builtin.file)
-- This will return the relative path - see screenshot 2
-- table.insert(el_segments, '%f')
return el_segments
end
-- The setup is commented so I can call each setup each time
-- to ensure that the screenshot contains all the relevant information
-- require('el').setup{generator = generator}
EOF
How to reproduce the problem
Screenshot 1 (problematic case)
Using table.insert(el_segments, builtin.file)
Screenshot 2 (OK)
Using table.insert(el_segments, '%f')
Screenshot 3 (OK)
Screenshot 4 (OK)
Using table.insert(el_segments, builtin.full_file)
Screenshot 5 (OK)
Using table.insert(el_segments, '%F')
Screenshot 6 (OK)
We would expect cases/screenshots 1, 2, and 3 to have the same result in the same way as cases/screenshots 4, 5, and 6 have the same result.
Well, cases/screenshots 4, 5, and 6 have a difference that the home path is displayed in full using full_file
and with ~
when using %f
so not exactly the same.
Discussion
My knowledge of lua is limited so here we go,
The function builtin.file
is using buffer.name
(if buffer.name is not empty).
The buffer.name
is set using nvim_buf_get_name
.
However, nvim_buf_get_name
returns the full path.
In the above example using :lua print(vim.api.nvim_buf_get_name(0))
returns /home/ps/Documents/codes/python/empty.py
Using :help nvim_buf_get_name
or looking at the source code we have /// Gets the full file name for the buffer
.
I assume what here full file name
means is the file name including the full path.
In contrast, :help buffname
returns the name of the file using the relative path.