neorg icon indicating copy to clipboard operation
neorg copied to clipboard

Promo promote and demote commands do not reindent non-child-heading content of the focal heading

Open mikemc opened this issue 6 months ago • 0 comments

Prerequisites

  • [X] I am using the latest stable release of Neovim
  • [X] I am using the latest version of the plugin

Neovim Version

NVIM v0.9.4

Neorg setup

  use {
    "nvim-neorg/neorg",
    config = function()
      require('neorg').setup {
        load = {
          ["core.defaults"] = {}, -- Loads default behaviour
          ["core.concealer"] = { config = { icon_preset = "diamond" } },
          ["core.dirman"] = { -- Manages Neorg workspaces
            config = {
              workspaces = {
                notes = "~/Dropbox (Personal)/notes/neorg",
              },
              default_workspace = "notes"
            },
          },
          ["core.export"] = {},
          ["core.export.markdown"] = {},
          ["core.manoeuvre"] = {},
          ["core.summary"] = {},
          -- ["core.ui.calendar"] = {},
          ["external.doom"] = {},
          ["core.keybinds"] = {
            -- see https://github.com/nvim-neorg/neorg/wiki/User-Keybinds#setting-up-a-keybind-hook
            config = {
              hook = function(keybinds)
                keybinds.map("norg", "i", "<C-CR>", "<cmd>Neorg keybind norg external.doom.insert-item-below<CR>")
                keybinds.map("norg", "n", "<C-CR>", "i<cmd>Neorg keybind norg external.doom.insert-item-below<CR>")
                keybinds.map("norg", "i", "<C-S-CR>", "<cmd>Neorg keybind norg external.doom.insert-item-above<CR>")
                keybinds.map("norg", "n", "<C-S-CR>", "i<cmd>Neorg keybind norg external.doom.insert-item-above<CR>")
                keybinds.map("norg", "n", "<A-l>", "<cmd>Neorg keybind norg external.doom.demote<CR>")
                keybinds.map("norg", "n", "<A-h>", "<cmd>Neorg keybind norg external.doom.promote<CR>")
                keybinds.map("norg", "n", "<A-S-l>", "<cmd>Neorg keybind norg external.doom.demote-subtree<CR>")
                keybinds.map("norg", "n", "<A-S-h>", "<cmd>Neorg keybind norg external.doom.promote-subtree<CR>")
                keybinds.map("norg", "n", "<A-j>", "<cmd>Neorg keybind norg external.doom.move-subtree-down<CR>")
                keybinds.map("norg", "n", "<A-k>", "<cmd>Neorg keybind norg external.doom.move-subtree-up<CR>")
              end,
            }
          }
        },
      }
    end,
    run = ":Neorg sync-parsers",
    requires = {"nvim-lua/plenary.nvim", "~/projects/neovim/neorg-doom"}
  }

Actual behavior

Example norg file,

* Heading 1
  Some content
** Heading 2

Running the promote command from core.promo (either by :Neorg norg keybind core.promo.promote or using the default keybind >.) will change Heading 1 from a level 1 to a level 2 heading and leave Heading 2 unchanged, as expected. However, it will not increase the indentation level of "Some content" accordingly - the heading content is only reindented when the >> and << keybinds are used, which promote/demote and reindent the entire subtree.

Expected behavior

I expect that promo.promote and promo.demote to reindent the content of the focal heading ('Some content' in the example) even when not affecting the children headings.

Steps to reproduce

Described above.

Potentially conflicting plugins

No response

Other information

The problem seems to be the return statement at https://github.com/nvim-neorg/neorg/blob/a489e7c4f9d7edb3caa04250d07bb6c6a5b9b890/lua/neorg/modules/core/promo/module.lua#L229 which causes, when affect_children is false, that we return before doing any reindentation of the heading's content. I believe that before returning we instead want to reindent the heading content, something like

        if not affect_children then
            adjust_prefix(root_prefix_node)
            if reindent_children then
                -- TODO: Get start and end of content before the next heading
                reindent_range(indent_row_start, indent_row_end)
            end
            return
        end

Help

Yes

Implementation help

I believe I can make a pull request to fix this without any help, but there are different options about how to arrange the control statements for reindent_children and affect_children and where to move the reindent_range() definition that I expect that the author of promo's promote_or_demote() would have an opinion on. Another question for the promo author is the intended interpretation of the reindent_children argument, particularly in the case where affect_children is false. It seems clear that affect_children refers to child heading nodes, but perhaps reindent_children should also control reindentation of non-child-heading text like 'Some content' above.

mikemc avatar Jan 04 '24 23:01 mikemc