Skip to content

Commit d86a138

Browse files
Use bufname instead of nvim_buf_get_name to properly resolve symlinks
1 parent a47492f commit d86a138

File tree

9 files changed

+13
-13
lines changed

9 files changed

+13
-13
lines changed

DOCS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ require('orgmode').setup({
216216
f = {
217217
label = 'Export to RTF format',
218218
action = function(exporter)
219-
local current_file = vim.api.nvim_buf_get_name(0)
219+
local current_file = vim.fn.bufname()
220220
local target = vim.fn.fnamemodify(current_file, ':p:r')..'.rtf'
221221
local command = {'pandoc', current_file, '-o', target}
222222
local on_success = function(output)

doc/orgmode.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ For example, lets add option to export to `rtf` format via `pandoc`:
400400
f = {
401401
label = 'Export to RTF format',
402402
action = function(exporter)
403-
local current_file = vim.api.nvim_buf_get_name(0)
403+
local current_file = vim.fn.bufname()
404404
local target = vim.fn.fnamemodify(current_file, ':p:r')..'.rtf'
405405
local command = {'pandoc', current_file, '-o', target}
406406
local on_success = function(output)

lua/orgmode/capture/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function Capture:_get_refile_vars()
134134
local template = vim.api.nvim_buf_get_var(0, 'org_template') or {}
135135
local file = vim.fn.fnamemodify(template.target or config.org_default_notes_file, ':p')
136136
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, true)
137-
local org_file = File.from_content(lines, 'capture', vim.api.nvim_buf_get_name(0))
137+
local org_file = File.from_content(lines, 'capture', vim.fn.bufname())
138138
local item = nil
139139
if org_file then
140140
item = org_file:get_headlines()[1]
@@ -242,7 +242,7 @@ function Capture:_refile_to(file, lines, item, destination_line)
242242
return false
243243
end
244244

245-
local is_same_file = file == vim.api.nvim_buf_get_name(0)
245+
local is_same_file = file == vim.fn.bufname()
246246
local cur_win = vim.api.nvim_get_current_win()
247247

248248
if is_same_file and item then

lua/orgmode/capture/templates.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ local expansions = {
2626
return string.format('[%s]', Date.now():to_string())
2727
end,
2828
['%a'] = function()
29-
return string.format('[[file:%s +%s]]', vim.api.nvim_buf_get_name(0), vim.api.nvim_win_get_cursor(0)[1])
29+
return string.format('[[file:%s +%s]]', vim.fn.bufname(), vim.api.nvim_win_get_cursor(0)[1])
3030
end,
3131
}
3232

lua/orgmode/clock/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function Clock:org_clock_goto()
6868
utils.echo_info('No running clock, this is the most recently clocked task')
6969
end
7070

71-
if vim.api.nvim_buf_get_name(0) ~= active_headline.file then
71+
if vim.fn.bufname() ~= active_headline.file then
7272
vim.cmd('edit ' .. vim.fn.fnameescape(active_headline.file))
7373
end
7474
vim.fn.cursor({ active_headline.range.start_line, 0 })

lua/orgmode/export/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ end
9292

9393
---@param extension string
9494
function Export.pandoc(extension)
95-
local file = vim.api.nvim_buf_get_name(0)
95+
local file = vim.fn.bufname()
9696
local target = vim.fn.fnamemodify(file, ':p:r') .. '.' .. extension
9797
if vim.fn.executable('pandoc') ~= 1 then
9898
return utils.echo_error('pandoc executable not found. Make sure pandoc is in $PATH.')
@@ -104,7 +104,7 @@ end
104104
---@param format string
105105
---@param extension string
106106
function Export.emacs(format, extension)
107-
local file = vim.api.nvim_buf_get_name(0)
107+
local file = vim.fn.bufname()
108108
local target = vim.fn.fnamemodify(file, ':p:r') .. '.' .. extension
109109
local emacs = config.emacs_config.executable_path
110110
local emacs_config_path = config.emacs_config.config_path

lua/orgmode/org/syntax.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local Files = require('orgmode.parser.files')
22
local config = require('orgmode.config')
33

44
local function load_code_blocks()
5-
local file = vim.api.nvim_buf_get_name(0)
5+
local file = vim.fn.bufname()
66
if not file or file == '' then
77
return
88
end

lua/orgmode/parser/files.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ end
119119

120120
---@return File
121121
function Files.get_current_file()
122-
local name = vim.api.nvim_buf_get_name(0)
122+
local name = vim.fn.bufname()
123123
local has_capture_var, is_capture = pcall(vim.api.nvim_buf_get_var, 0, 'org_capture')
124124
if has_capture_var and is_capture then
125125
return File.from_content(vim.api.nvim_buf_get_lines(0, 0, -1, false))
@@ -160,7 +160,7 @@ function Files.update_file(filename, action)
160160
if not file then
161161
return Promise.resolve()
162162
end
163-
local is_same_file = filename == vim.api.nvim_buf_get_name(0)
163+
local is_same_file = filename == vim.fn.bufname()
164164
local cur_win = vim.api.nvim_get_current_win()
165165
if is_same_file then
166166
return utils.promisify(action(file)):next(function(result)

tests/plenary/ui/clock_spec.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ describe('Clock', function()
103103

104104
it('should jump to the clocked out headline from anywhere', function()
105105
helpers.load_file(files[1])
106-
assert.are.same(files[1], vim.api.nvim_buf_get_name(0))
106+
assert.are.same(files[1], vim.fn.bufname())
107107
vim.cmd([[norm ,oxj]])
108-
assert.are.same(files[3], vim.api.nvim_buf_get_name(0))
108+
assert.are.same(files[3], vim.fn.bufname())
109109
assert.are.same(3, vim.fn.line('.'))
110110
end)
111111

0 commit comments

Comments
 (0)