Skip to content

Commit 0e9437d

Browse files
committed
Remove the LOGGING property logic
Remove the LOGGING property logic from the sections and the file-level.
1 parent 4595195 commit 0e9437d

File tree

1 file changed

+12
-62
lines changed

1 file changed

+12
-62
lines changed

lua/orgmode/org/mappings.lua

+12-62
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ local ts_org = require('orgmode.treesitter')
1515
local ts_table = require('orgmode.treesitter.table')
1616
local EventManager = require('orgmode.events')
1717
local Promise = require('orgmode.utils.promise')
18-
local TodoConfig = require('orgmode.parser.todo-config')
1918
local events = EventManager.event
2019
local Link = require('orgmode.objects.link')
2120

@@ -387,8 +386,6 @@ end
387386
function OrgMappings:_todo_change_state(direction)
388387
local headline = ts_org.closest_headline()
389388
local _, old_state, was_done = headline:todo()
390-
--- @cast old_state -nil
391-
--- @cast was_done -nil
392389
local changed = self:_change_todo_state(direction, true)
393390
if not changed then
394391
return
@@ -406,53 +403,9 @@ function OrgMappings:_todo_change_state(direction)
406403
return dispatchEvent()
407404
end
408405

409-
local new_state = item.todo_keyword.value
410-
411-
-- Determine which configuration to use
412-
local global_config = config.org_log_done
413-
414-
--- @type nil | false | 'time' | 'note'
415-
local section_config
416-
local logging_prop = item.properties.items.logging
417-
if logging_prop == 'nil' then
418-
section_config = false
419-
elseif logging_prop ~= nil then
420-
local todoConfig = TodoConfig:parse(logging_prop)
421-
if todoConfig ~= nil then
422-
section_config = todoConfig:get_logging_behavior(old_state, new_state)
423-
else
424-
-- TODO: Report invalid config?
425-
section_config = nil
426-
end
427-
else
428-
section_config = nil
429-
end
430-
431-
-- @type nil | false | 'time' | 'note'
432-
local user_config
433-
if config.org_todo_keywords ~= nil then
434-
local todoConfig = TodoConfig:parse(table.concat(config.org_todo_keywords, ' '))
435-
if todoConfig ~= nil then
436-
user_config = todoConfig:get_logging_behavior(old_state, new_state)
437-
else
438-
-- TODO: Report invalid config?
439-
user_config = nil
440-
end
441-
else
442-
user_config = nil
443-
end
444-
445-
-- Use the most locally available log config
446-
--- @type false | 'time' | 'note'
447-
local log_config
448-
if section_config ~= nil then
449-
log_config = section_config
450-
elseif user_config ~= nil then
451-
log_config = user_config
452-
else
453-
log_config = global_config
454-
end
455-
406+
local log_note = config.org_log_done == 'note'
407+
local log_time = config.org_log_done == 'time'
408+
local should_log_time = log_note or log_time
456409
local indent = config:get_indent(headline:level() + 1)
457410

458411
local get_note = function(note)
@@ -470,12 +423,11 @@ function OrgMappings:_todo_change_state(direction)
470423

471424
local repeater_dates = item:get_repeater_dates()
472425
if #repeater_dates == 0 then
473-
-- If going from "not done" to "done", set the closed date and add the note/time
474-
if log_config ~= false and item:is_done() and not was_done then
426+
if should_log_time and item:is_done() and not was_done then
475427
headline:set_closed_date()
476428
item = Files.get_closest_headline()
477429

478-
if log_config == 'note' then
430+
if log_note then
479431
dispatchEvent()
480432
return self.capture.closing_note:open():next(function(note)
481433
local valid_note = get_note(note)
@@ -486,9 +438,7 @@ function OrgMappings:_todo_change_state(direction)
486438
end)
487439
end
488440
end
489-
490-
-- If going from "done" to "not done", remove the close date
491-
if log_config ~= false and not item:is_done() and was_done then
441+
if should_log_time and not item:is_done() and was_done then
492442
headline:remove_closed_date()
493443
end
494444
return dispatchEvent()
@@ -500,19 +450,19 @@ function OrgMappings:_todo_change_state(direction)
500450

501451
self:_change_todo_state('reset')
502452
local state_change = {
503-
string.format('%s- State "%s" from "%s" [%s]', indent, new_state, old_state, Date.now():to_string()),
453+
string.format('%s- State "%s" from "%s" [%s]', indent, item.todo_keyword.value, old_state, Date.now():to_string()),
504454
}
505455

506456
dispatchEvent()
507457
return Promise.resolve()
508458
:next(function()
509-
if log_config == 'time' then
459+
if not log_note then
510460
return state_change
511-
elseif log_config == 'note' then
512-
return self.capture.closing_note:open():next(function(closing_note)
513-
return get_note(closing_note)
514-
end)
515461
end
462+
463+
return self.capture.closing_note:open():next(function(closing_note)
464+
return get_note(closing_note)
465+
end)
516466
end)
517467
:next(function(note)
518468
headline:set_property('LAST_REPEAT', Date.now():to_wrapped_string(false))

0 commit comments

Comments
 (0)