Skip to content

Commit 7fc6ea3

Browse files
Get full path of the current file name
1 parent d86a138 commit 7fc6ea3

File tree

7 files changed

+15
-9
lines changed

7 files changed

+15
-9
lines changed

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.fn.bufname())
137+
local org_file = File.from_content(lines, 'capture', utils.current_file_path())
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.fn.bufname()
245+
local is_same_file = file == utils.current_file_path()
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local config = require('orgmode.config')
22
local Date = require('orgmode.objects.date')
3+
local utils = require('orgmode.utils')
34
local expansions = {
45
['%f'] = function()
56
return vim.fn.expand('%')
@@ -26,7 +27,7 @@ local expansions = {
2627
return string.format('[%s]', Date.now():to_string())
2728
end,
2829
['%a'] = function()
29-
return string.format('[[file:%s +%s]]', vim.fn.bufname(), vim.api.nvim_win_get_cursor(0)[1])
30+
return string.format('[[file:%s +%s]]', utils.current_file_path(), vim.api.nvim_win_get_cursor(0)[1])
3031
end,
3132
}
3233

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.fn.bufname() ~= active_headline.file then
71+
if utils.current_file_path() ~= 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.fn.bufname()
95+
local file = utils.current_file_path()
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.fn.bufname()
107+
local file = utils.current_file_path()
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
local Files = require('orgmode.parser.files')
22
local config = require('orgmode.config')
3+
local utils = require('orgmode.utils')
34

45
local function load_code_blocks()
5-
local file = vim.fn.bufname()
6+
local file = utils.current_file_path()
67
if not file or file == '' then
78
return
89
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.fn.bufname()
122+
local name = utils.current_file_path()
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.fn.bufname()
163+
local is_same_file = filename == utils.current_file_path()
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)

lua/orgmode/utils/init.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,4 +495,8 @@ function utils.get_nearest_block_node(file, cursor, accept_at_cursor)
495495
}
496496
end
497497

498+
function utils.current_file_path()
499+
return vim.fn.fnamemodify(vim.fn.bufname(), ':p')
500+
end
501+
498502
return utils

0 commit comments

Comments
 (0)