Skip to content

Commit 93cd1ae

Browse files
committed
Allow configurable org tags column
1 parent d86a138 commit 93cd1ae

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

DOCS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,15 @@ Example value: `{'agenda-archives'}`
368368

369369
### Tags settings
370370

371+
#### **org_tags_column**
372+
*type*: `number`
373+
*default value*: `80`
374+
The column to which tags should be indented in a headline.
375+
If this number is positive, it specifies the column.
376+
If it is negative, it means that the tags should be flushright to that column.
377+
For example, -80 works well for a normal 80 character screen.
378+
When 0, place tags directly after headline text, with only one space in between.
379+
371380
#### **org_use_tag_inheritance**
372381
*type*: `boolean`
373382
*default value*: `true`

doc/orgmode.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ CONTENTS *orgmode-content
4141
1.2.2.11. org_agenda_skip_deadline_if_done.|orgmode-org_agenda_skip_deadline_if_done|
4242
1.2.2.12. org_agenda_text_search_extra_files.|orgmode-org_agenda_text_search_extra_files|
4343
1.2.3. Tags settings...............................|orgmode-tags_settings|
44-
1.2.3.1. org_use_tag_inheritance.....|orgmode-org_use_tag_inheritance|
45-
1.2.3.2. org_tags_exclude_from_inheritance.|orgmode-org_tags_exclude_from_inheritance|
44+
1.2.3.1. org_tags_column.....................|orgmode-org_tags_column|
45+
1.2.3.2. org_use_tag_inheritance.....|orgmode-org_use_tag_inheritance|
46+
1.2.3.3. org_tags_exclude_from_inheritance.|orgmode-org_tags_exclude_from_inheritance|
4647
1.3. Mappings...............................................|orgmode-mappings|
4748
1.3.1. Global mappings...........................|orgmode-global_mappings|
4849
1.3.1.1. org_agenda...............................|orgmode-org_agenda|
@@ -566,6 +567,16 @@ Example value: `{'agenda-archives'}`
566567

567568
TAGS SETTINGS *orgmode-tags_settings*
568569

570+
ORG_TAGS_COLUMN *orgmode-org_tags_column*
571+
572+
type: `number`
573+
default value: `80`
574+
The column to which tags should be indented in a headline.
575+
If this number is positive, it specifies the column.
576+
If it is negative, it means that the tags should be flushright to that column.
577+
For example, -80 works well for a normal 80 character screen.
578+
When 0, place tags directly after headline text, with only one space in between.
579+
569580
ORG_USE_TAG_INHERITANCE *orgmode-org_use_tag_inheritance*
570581

571582
type: `boolean`

lua/orgmode/config/defaults.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ return {
2121
org_priority_default = 'B',
2222
org_priority_lowest = 'C',
2323
org_archive_location = '%s_archive::',
24+
org_tags_column = 80,
2425
org_use_tag_inheritance = true,
2526
org_tags_exclude_from_inheritance = {},
2627
org_hide_leading_stars = false,

lua/orgmode/org/mappings.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,16 @@ function OrgMappings:_set_headline_tags(headline, tags_string)
868868
local line_without_tags = headline.line
869869
:gsub(vim.pesc(utils.tags_to_string(headline:get_own_tags())) .. '%s*$', '')
870870
:gsub('%s*$', '')
871-
local spaces = 80 - math.min(vim.api.nvim_strwidth(line_without_tags), 79)
871+
872+
local to_col = config.org_tags_column
873+
if to_col < 0 then
874+
local tags_width = vim.api.nvim_strwidth(tags)
875+
to_col = math.abs(to_col) - tags_width
876+
end
877+
878+
local line_width = vim.api.nvim_strwidth(line_without_tags)
879+
spaces = math.max(to_col - line_width, 1)
880+
872881
local new_line = string.format('%s%s%s', line_without_tags, string.rep(' ', spaces), tags):gsub('%s*$', '')
873882
return vim.fn.setline(headline.range.start_line, new_line)
874883
end

0 commit comments

Comments
 (0)