Skip to content

Commit 361435f

Browse files
Merge branch 'master' into fix-subtree-up-and-down
2 parents 5bfa7f3 + e16452b commit 361435f

File tree

22 files changed

+435
-53
lines changed

22 files changed

+435
-53
lines changed

README.org

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,5 +198,5 @@ issue.
198198

199199
- [[https://github.com/dhruvasagar][@dhruvasagar]] and his [[https://github.com/dhruvasagar/vim-dotoo][vim-dotoo]] plugin
200200
that got me started using orgmode. Without him this plugin would not happen.
201-
- [[https://github.com/milisims][@milisims]] for writing a treesitter parser for org
201+
- [[https://github.com/emiasims][@emiasims]] for writing a treesitter parser for org
202202
- [[https://github.com/jceb/vim-orgmode][vim-orgmode]] for some parts of the code (mostly syntax)

docs/contributing.org

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ can be installed, and exit with a success message.
9898
:PROPERTIES:
9999
:CUSTOM_ID: parser
100100
:END:
101-
Parsing is done via builtin treesitter parser and the [[https://github.com/milisims/tree-sitter-org][tree-sitter-org]] grammar.
101+
Parsing is done via builtin treesitter parser and the [[https://github.com/nvim-orgmode/tree-sitter-org][tree-sitter-org]] grammar.
102102

103103
**** Commits
104104
:PROPERTIES:

lua/orgmode/api/file.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---@diagnostic disable: invisible
22
local OrgHeadline = require('orgmode.api.headline')
3+
local utils = require('orgmode.utils')
34
local org = require('orgmode')
45

56
---@class OrgApiFile
@@ -113,7 +114,7 @@ end
113114
--- @return string
114115
function OrgFile:get_link()
115116
local filename = self.filename
116-
local bufnr = vim.fn.bufnr('^' .. filename .. '$')
117+
local bufnr = utils.get_buffer_by_filename(filename)
117118

118119
if bufnr == -1 or not vim.api.nvim_buf_is_loaded(bufnr) then
119120
-- do remote edit

lua/orgmode/api/headline.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local PriorityState = require('orgmode.objects.priority_state')
44
local Date = require('orgmode.objects.date')
55
local Calendar = require('orgmode.objects.calendar')
66
local Promise = require('orgmode.utils.promise')
7+
local utils = require('orgmode.utils')
78
local org = require('orgmode')
89

910
---@class OrgApiHeadline
@@ -276,7 +277,7 @@ end
276277
--- @return string
277278
function OrgHeadline:get_link()
278279
local filename = self.file.filename
279-
local bufnr = vim.fn.bufnr('^' .. filename .. '$')
280+
local bufnr = utils.get_buffer_by_filename(filename)
280281

281282
if bufnr == -1 or not vim.api.nvim_buf_is_loaded(bufnr) then
282283
-- do remote edit

lua/orgmode/api/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local OrgHeadline = require('orgmode.api.headline')
44
local orgmode = require('orgmode')
55
local validator = require('orgmode.utils.validator')
66
local Promise = require('orgmode.utils.promise')
7+
local utils = require('orgmode.utils')
78

89
---@class OrgApiRefileOpts
910
---@field source OrgApiHeadline
@@ -81,7 +82,7 @@ function OrgApi.refile(opts)
8182
refile_opts.destination_headline = opts.destination._section
8283
end
8384

84-
local source_bufnr = vim.fn.bufnr('^' .. opts.source.file.filename .. '$') or -1
85+
local source_bufnr = utils.get_buffer_by_filename(opts.source.file.filename)
8586
local is_capture = source_bufnr > -1 and vim.b[source_bufnr].org_capture
8687

8788
if is_capture and orgmode.capture._window then

lua/orgmode/files/file.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ end
6060
---Load the file
6161
---@return OrgPromise<OrgFile | false>
6262
function OrgFile.load(filename)
63-
local bufnr = vim.fn.bufnr('^' .. filename .. '$') or -1
63+
local bufnr = utils.get_buffer_by_filename(filename)
6464

6565
if
6666
bufnr > -1
@@ -534,7 +534,7 @@ end
534534

535535
---@return number
536536
function OrgFile:bufnr()
537-
local bufnr = vim.fn.bufnr('^' .. self.filename .. '$') or -1
537+
local bufnr = utils.get_buffer_by_filename(self.filename)
538538
-- Do not consider unloaded buffers as valid
539539
-- Treesitter is not working in them
540540
if bufnr > -1 and vim.api.nvim_buf_is_loaded(bufnr) then
@@ -546,7 +546,7 @@ end
546546
---Return valid buffer handle or throw an error if it's not valid
547547
---@return number
548548
function OrgFile:get_valid_bufnr()
549-
local bufnr = vim.fn.bufnr('^' .. self.filename .. '$') or -1
549+
local bufnr = utils.get_buffer_by_filename(self.filename)
550550
if bufnr < 0 then
551551
error('[orgmode] No valid buffer for file ' .. self.filename .. ' to edit', 0)
552552
end

lua/orgmode/org/autocompletion/_meta.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---@meta
22

3-
---@alias OrgCompletionContext { line: string, base?: string }
3+
---@alias OrgCompletionContext { line: string, base?: string, fuzzy?: boolean, matcher?: fun(value?: string, pattern?: string): boolean }
44
---@alias OrgCompletionItem { word: string, menu: string }
55

66
---@class OrgCompletionSource

lua/orgmode/org/autocompletion/blink.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function Source:get_completions(ctx, callback)
2121
local results = org.completion:complete({
2222
line = line,
2323
base = base,
24+
fuzzy = true,
2425
})
2526

2627
local cb = function(items)

lua/orgmode/org/autocompletion/cmp.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function Source:complete(params, callback)
3030
local results = org.completion:complete({
3131
line = params.context.cursor_before_line,
3232
base = base,
33+
fuzzy = true,
3334
})
3435
local items = {}
3536
for _, item in ipairs(results) do

lua/orgmode/org/autocompletion/init.lua

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ end
4444
---@return OrgCompletionItem
4545
function OrgCompletion:complete(context)
4646
local results = {}
47+
context.base = context.base or ''
48+
if not context.matcher then
49+
context.matcher = function(value, pattern)
50+
pattern = pattern or ''
51+
if pattern == '' then
52+
return true
53+
end
54+
if context.fuzzy then
55+
return #vim.fn.matchfuzzy({ value }, pattern) > 0
56+
end
57+
return value:find('^' .. vim.pesc(pattern)) ~= nil
58+
end
59+
end
4760
for _, source in ipairs(self.sources) do
4861
if source:get_start(context) then
4962
vim.list_extend(results, self:_get_valid_results(source:get_results(context), context))
@@ -53,12 +66,13 @@ function OrgCompletion:complete(context)
5366
return results
5467
end
5568

69+
---@param results string[]
70+
---@param context OrgCompletionContext
71+
---@return OrgCompletionItem[]
5672
function OrgCompletion:_get_valid_results(results, context)
57-
local base = context.base or ''
58-
5973
local valid_results = {}
6074
for _, item in ipairs(results) do
61-
if base == '' or item:find('^' .. vim.pesc(base)) then
75+
if context.matcher(item, context.base) then
6276
table.insert(valid_results, {
6377
word = item,
6478
menu = self.menu,
@@ -89,6 +103,9 @@ function OrgCompletion:omnifunc(findstart, base)
89103

90104
self._context = self._context or { line = self:get_line() }
91105
self._context.base = base
106+
if vim.tbl_contains(vim.opt_local.completeopt:get(), 'fuzzy') then
107+
self._context.fuzzy = true
108+
end
92109
return self:complete(self._context)
93110
end
94111

0 commit comments

Comments
 (0)