nvim-orgmode/orgmode

Context is lost when archiving headline with level >1

Closed this issue · 2 comments

Describe the bug

Archiving a headline should add context, that is, the various ARCHIVE_ properties defined in

local archive_props = {
('%s:ARCHIVE_TIME: %s'):format(indent, Date.now():to_string()),
('%s:ARCHIVE_FILE: %s'):format(indent, file.filename),
('%s:ARCHIVE_CATEGORY: %s'):format(indent, headline:get_category()),
('%s:ARCHIVE_TODO: %s'):format(indent, headline:get_todo() or ''),

Since edc3ceb, this does not work anymore for headlines of level 2 or greater. It seems the culprit is

if destination_headline or opts.source_headline:get_level() > 1 then
lines = self:_adapt_headline_level(opts.source_headline, target_level, false)
end
- the original lines including the archive props is overwritten with (promoted) lines based on the headline only, so the archive prop lines are lost.

Steps to reproduce

  1. Open nvim (with the minimal init.lua)
  2. Create the file foo.org containing
    * bar
    ** TODO baz
    
  3. If it is not already there, move the cursor into the second line (the "baz" line)
  4. Press <Leader>o$ to trigger archiving the baz-headline.
  5. Open foo.org_archive. It contains
    * TODO baz
    

Expected behavior

foo.org_archive should contain

* TODO baz
  :PROPERTIES:
  :ARCHIVE_TIME: <current timestamp>
  :ARCHIVE_FILE: </path/to/foo.org>
  :ARCHIVE_CATEGORY: foo'
  :ARCHIVE_TODO: TODO'
  :END:

Emacs functionality

I have not tested this, but presume since it worked previously with nvim-orgmode, it works in Emacs as it had worked in nvim-orgmode.

Minimal init.lua

(Just the provided template)

local tmp_dir = vim.env.TMPDIR or vim.env.TMP or vim.env.TEMP or '/tmp'
local nvim_root = tmp_dir .. '/nvim_orgmode'
local lazy_root = nvim_root .. '/lazy'
local lazypath = lazy_root .. '/lazy.nvim'

-- Install lazy.nvim if not already installed
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    'git',
    'clone',
    '--filter=blob:none',
    'https://github.com/folke/lazy.nvim.git',
    '--branch=stable', -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require('lazy').setup({
  {
    'nvim-orgmode/orgmode',
    event = 'VeryLazy',
    ft = { 'org' },
    config = function()
      require('orgmode').setup()
    end,
  },
}, {
  root = lazy_root,
  lockfile = nvim_root .. '/lazy.json',
  install = {
    missing = false,
  },
})

require('lazy').sync({
  wait = true,
  show = false,
})

Screenshots and recordings

No response

OS / Distro

macOS 14.5

Neovim version/commit

0.11.0-dev-18+g63e3a63d2

Additional context

I have started writing a test to demonstrate this , it can be applied with patch -p1 < test_archiving_with_context.patch (on master as of d2fde79):
test_archiving_with_context.patch

Note the test is not complete, in particular, the precise content of the archive properties is not checked. But at least it should be sufficient to demonstrate the problem.

Edit: Fix links to code

Thanks for reporting. Should be fixed on latest master.

Thank you for the fast response, I can confirm it works now. 👍