Skip to content

Commit 54b17c1

Browse files
Fix filetags to use colon instead of comma. Closes #25.
1 parent 5f81be7 commit 54b17c1

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

lua/orgmode/org/autocompletion.lua

+17-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ local Autocompletion = {}
1313

1414
local directives = { rgx = vim.regex([[^\#+\?\w*$]]), line_rgx = vim.regex([[^\#\?+\?\w*$]]), list = data.directives }
1515
local begin_blocks = { rgx = vim.regex([[\(^\s*\)\@<=\#+\?\w*$]]), line_rgx = vim.regex([[^\s*\#\?+\?\w*$]]), list = data.begin_blocks }
16-
local properties = { rgx = vim.regex([[\(^\s*\)\@<=:\w*$]]), list = data.properties }
16+
local properties = {
17+
line_rgx = vim.regex([[\(^\s\+\|^\s*:\?$\)]]),
18+
rgx = vim.regex([[\(^\|^\s\+\)\@<=:\w*$]]),
19+
list = data.properties,
20+
}
1721
local links = {
1822
line_rgx = vim.regex([[\(\(^\|\s\+\)\[\[\)\@<=\(\*\|\#\)\?\(\w\+\)\?]]),
1923
rgx = vim.regex([[\(\*\|\#\)\?\(\w\+\)\?$]]),
@@ -28,6 +32,17 @@ local tags = {
2832
end, Files.get_tags())
2933
end,
3034
}
35+
36+
local filetags = {
37+
line_rgx = vim.regex([[^\#+FILETAGS:\s\+]]),
38+
rgx = vim.regex([[:\([0-9A-Za-z_%@\#]*\)$]]),
39+
fetcher = function()
40+
return vim.tbl_map(function(tag)
41+
return ':'..tag..':'
42+
end, Files.get_tags())
43+
end,
44+
}
45+
3146
local todo_keywords = {
3247
rgx = vim.regex([[\(^\(\*\+\s\+\)\?\)\@<=\w*$]]),
3348
line_rgx = vim.regex([[^\*\+\s\+\w*$]]),
@@ -39,6 +54,7 @@ local todo_keywords = {
3954
local contexts = {
4055
directives,
4156
begin_blocks,
57+
filetags,
4258
properties,
4359
links,
4460
metadata,

lua/orgmode/parser/root.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local Content = require('orgmode.parser.content')
33
local Config = require('orgmode.config')
44
local Types = require('orgmode.parser.types')
55
local Range = require('orgmode.parser.range')
6+
local utils = require('orgmode.utils')
67

78
---@class Root
89
---@field lines string[]
@@ -129,8 +130,9 @@ end
129130
---@return string
130131
function Root:process_root_content(content)
131132
if content:is_keyword() and content.keyword.name == 'FILETAGS' then
132-
for _, tag in ipairs(vim.split(content.keyword.value, '%s*,%s*')) do
133-
if tag:find('^[%w_%%@#]+$') and not vim.tbl_contains(self.tags, tag) then
133+
local filetags = utils.parse_tags_string(content.keyword.value)
134+
for _, tag in ipairs(filetags) do
135+
if not vim.tbl_contains(self.tags, tag) then
134136
table.insert(self.tags, tag)
135137
end
136138
end

tests/plenary/org/autocompletion_spec.lua

+11
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ describe('Autocompletion', function()
183183
{ menu = "[Org]", word = ":PRIVATE:" },
184184
}, result)
185185

186+
mock_line(api, '#+FILETAGS: ')
187+
result = Autocompletion.omni(0, '')
188+
assert.are.same({}, result)
189+
190+
mock_line(api, '#+FILETAGS: :')
191+
result = Autocompletion.omni(0, ':')
192+
assert.are.same({
193+
{ menu = "[Org]", word = ":OFFICE:" },
194+
{ menu = "[Org]", word = ":PRIVATE:" },
195+
}, result)
196+
186197
-- TODO: Add hyperlinks test
187198

188199
mock.revert(api)

tests/plenary/parser/content_parser_spec.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('Content parser', function()
2020

2121
it('should parse keyword', function()
2222
local content = Content:new({
23-
line = ' #+FILETAGS: Tag1, Tag2',
23+
line = ' #+FILETAGS: :Tag1:Tag2:',
2424
lnum = 1,
2525
parent = { id = 0, level = 0 },
2626
})

tests/plenary/parser/parser_spec.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ local config = require('orgmode.config')
77
describe('Parser', function()
88
it('should parse filetags headline', function()
99
local lines = {
10-
'#+FILETAGS: Tag1, Tag2',
10+
'#+FILETAGS: :Tag1:Tag2:',
1111
'* TODO Something with a lot of tags :WORK:'
1212
}
1313

0 commit comments

Comments
 (0)