Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit and capture use buffer instead of file #326

Closed
3 tasks done
helmecke opened this issue Jan 22, 2022 · 9 comments
Closed
3 tasks done

Edit and capture use buffer instead of file #326

helmecke opened this issue Jan 22, 2022 · 9 comments
Labels
bug Issues related to bugs. Please attach a severity, a priority and category with this label. on hold On Hold

Comments

@helmecke
Copy link

Prerequisites

  • I have read contribution guidelines
  • I am using the latest version of the plugin
  • I am using either 0.6 stable or the latest compiled neovim version

Neovim Version

NVIM v0.6.1

Neorg setup

Config
require('neorg').setup {
  load = {
    ['core.defaults'] = {},
    ['core.keybinds'] = {
      config = {
        default_keybinds = false,
      },
    },
    ['core.norg.concealer'] = {},
    ['core.norg.completion'] = {
      config = {
        engine = 'nvim-cmp',
      },
    },
    ['core.norg.dirman'] = {
      config = {
        workspaces = {
          personal = '~/Documents/neorg',
          gtd = '~/Documents/gtd',
        },
        autochdir = true,
      },
    },
    ['core.gtd.base'] = {
      config = {
        workspace = 'gtd',
      },
    },
    ['core.integrations.telescope'] = {},
    ['core.presenter'] = {
      config = {
        zen_mode = 'zen-mode',
      },
    },
    ['core.norg.journal'] = {},
  },
  hook = function()
    local neorg_callbacks = require 'neorg.callbacks'
    local leader = '<leader>'
    local localleader = '<localleader>'

    neorg_callbacks.on_event('core.keybinds.events.enable_keybinds', function(_, keybinds)
      -- Map all the below keybinds only when the "norg" mode is active
      keybinds.map_event_to_mode('norg', {
        n = {
          -- Keys for managing TODO items and setting their states
          { localleader .. 'tu', 'core.norg.qol.todo_items.todo.task_undone' },
          { localleader .. 'tp', 'core.norg.qol.todo_items.todo.task_pending' },
          { localleader .. 'td', 'core.norg.qol.todo_items.todo.task_done' },
          { localleader .. 'th', 'core.norg.qol.todo_items.todo.task_on_hold' },
          { localleader .. 'tc', 'core.norg.qol.todo_items.todo.task_cancelled' },
          { localleader .. 'tr', 'core.norg.qol.todo_items.todo.task_recurring' },
          { localleader .. 'ti', 'core.norg.qol.todo_items.todo.task_important' },
          { '<C-Space>', 'core.norg.qol.todo_items.todo.task_cycle' },

          -- Keys for managing GTD
          { localleader .. 'te', 'core.gtd.base.edit' },
          { leader .. 'ne', 'core.gtd.base.edit' },

          -- Keys for managing notes
          { localleader .. 'nn', 'core.norg.dirman.new.note' },
          { leader .. 'nn', 'core.norg.dirman.new.note' },

          { '<CR>', 'core.norg.esupports.hop.hop-link' },
          { '<M-CR>', 'core.norg.esupports.hop.hop-link', 'vsplit' },

          { '<C-s>', 'core.integrations.telescope.find_linkable' },

          -- TODO: rebind
          -- { '<M-k>', 'core.norg.manoeuvre.item_up' },
          -- { '<M-j>', 'core.norg.manoeuvre.item_down' },
        },
        i = {
          { '<C-l>', 'core.integrations.telescope.insert_link' },
        },
        o = {
          { 'ah', 'core.norg.manoeuvre.textobject.around-heading' },
          { 'ih', 'core.norg.manoeuvre.textobject.inner-heading' },
          { 'at', 'core.norg.manoeuvre.textobject.around-tag' },
          { 'it', 'core.norg.manoeuvre.textobject.inner-tag' },
          { 'al', 'core.norg.manoeuvre.textobject.around-whole-list' },
        },
      }, {
        silent = true,
        noremap = true,
      })

      -- Map the below keys only when traverse-heading mode is active
      keybinds.map_event_to_mode('traverse-heading', {
        n = {
          -- Rebind j and k to move between headings in traverse-heading mode
          { 'j', 'core.integrations.treesitter.next.heading' },
          { 'k', 'core.integrations.treesitter.previous.heading' },
        },
      }, {
        silent = true,
        noremap = true,
      })

      -- Map the below keys on gtd displays
      keybinds.map_event_to_mode('gtd-displays', {
        n = {
          { '<CR>', 'core.gtd.ui.goto_task' },

          -- Keys for closing the current display
          { 'q', 'core.gtd.ui.close' },
          { '<Esc>', 'core.gtd.ui.close' },

          { 'e', 'core.gtd.ui.edit_task' },
          { '<Tab>', 'core.gtd.ui.details' },
        },
      }, {
        silent = true,
        noremap = true,
        nowait = true,
      })

      -- Map the below keys on presenter mode
      keybinds.map_event_to_mode('presenter', {
        n = {
          { '<CR>', 'core.presenter.next_page' },
          { 'l', 'core.presenter.next_page' },
          { 'h', 'core.presenter.previous_page' },

          -- Keys for closing the current display
          { 'q', 'core.presenter.close' },
          { '<Esc>', 'core.presenter.close' },
        },
      }, {
        silent = true,
        noremap = true,
        nowait = true,
      })

      -- Apply the below keys to all modes
      keybinds.map_to_mode('all', {
        n = {
          { localleader .. 'mn', ':Neorg mode norg<CR>' },
          { localleader .. 'mh', ':Neorg mode traverse-heading<CR>' },
          { leader .. 'nmn', ':Neorg mode norg<CR>' },
          { leader .. 'nmh', ':Neorg mode traverse-heading<CR>' },

          -- Keys for managing journal
          { localleader .. 'jm', ':Neorg journal tomorrow<CR>' },
          { localleader .. 'jt', ':Neorg journal today<CR>' },
          { localleader .. 'jy', ':Neorg journal yesterday<CR>' },
          { leader .. 'njm', ':Neorg journal tomorrow<CR>' },
          { leader .. 'njt', ':Neorg journal today<CR>' },
          { leader .. 'njy', ':Neorg journal yesterday<CR>' },

          -- Keys for managing presenter
          { localleader .. 'ps', ':Neorg presenter start<CR>' },
          { leader .. 'np', ':Neorg presenter start<CR>' },
        },
      }, {
        silent = true,
        noremap = true,
      })
    end)
  end,
}

Actual behavior

:Neorg gtd edit

[neorg] (06:45:14)                                                                                                                                                                                                  
...r/opt/neorg/lua/neorg/modules/core/gtd/ui/edit_popup.lua:18                                                                                                                                                      
No task at cursor position

:Neorg gtd capture

E5108: Error executing lua ...r/start/nvim-treesitter/lua/nvim-treesitter/ts_utils.lua:266: attempt to index local 'node_or_range' (a nil value)                                                                    
stack traceback:                                                                                                                                                                                                    
        ...r/start/nvim-treesitter/lua/nvim-treesitter/ts_utils.lua:266: in function 'get_node_range'                                                                                                               
        ...pt/neorg/lua/neorg/modules/core/gtd/queries/creators.lua:235: in function 'insert_tag'                                                                                                                   
        ...pt/neorg/lua/neorg/modules/core/gtd/queries/creators.lua:62: in function 'create'                                                                                                                        
        ...pt/neorg/lua/neorg/modules/core/gtd/ui/capture_popup.lua:77: in function <...pt/neorg/lua/neorg/modules/core/gtd/ui/capture_popup.lua:74>                                                                
        .../opt/neorg/lua/neorg/modules/core/ui/selection_popup.lua:343: in function <.../opt/neorg/lua/neorg/modules/core/ui/selection_popup.lua:329>                                                              
        .../opt/neorg/lua/neorg/modules/core/ui/selection_popup.lua:22: in function 'invoke_key_in_selection'                                                                                                       
        [string ":lua"]:1: in main chunk                                                                                                                                                                            
[neorg] (06:46:28)                                                                                                                                                                                                  
...pt/neorg/lua/neorg/modules/core/gtd/queries/creators.lua:55                                                                                                                                                      
Error in inserting new content

Expected behavior

:Neorg gtd edit should always use buffer.

:Neorg gtd capture

  • x -> Add to cursor position should always use buffer.
  • p -> Add to project should use buffer if file is open and has changes or if file is open and is current buffer.
  • <CR> -> Add to inbox should use buffer if file is open and has changes or if file is open and is current buffer.

Steps to reproduce

Open norg file with tasks. Insert empty line above task without saving. :Neorg gtd edit

Create new note with core.norg.dirman.new.note without saving. :Neorg gtd capture -> x -> Add to cursor position.

Potentially conflicting plugins

No response

Other information

No response

Help

No

Implementation help

No response

@helmecke helmecke added the bug Issues related to bugs. Please attach a severity, a priority and category with this label. label Jan 22, 2022
@danymat
Copy link
Member

danymat commented Jan 22, 2022

Hello ! I quite don't get the problem here. What do you mean that "use file instead of buffer "?

Oh i think I know what you mean there. Indeed we read the file content from file system in order to prevent creating a lot of buffers. Try to save the file before opening any view, so that you don't have any errors. Tell me if it works for you !

@helmecke helmecke changed the title [GTD] edit and capture use file instead of buffer [GTD] edit and capture use buffer instead of file Jan 22, 2022
@helmecke
Copy link
Author

Damn, I got the title reverse. I fixed it. The description was correct though.

@helmecke
Copy link
Author

It's true saving bevorhand works, but it's a workaround.

If I have a lot of buffers I would have to think before using :Neorg gtd capture. Do I have that project(file) open, did i make change. Do I have inbox.norg open with changes not saved. Even with :Neorg gtd edit I have to make a binding which saves the current buffer before executing :Neorg gtd edit.

@danymat danymat added GTD module feature Issues related to feature proposals. Please attach a module. and removed bug Issues related to bugs. Please attach a severity, a priority and category with this label. labels Jan 22, 2022
@danymat danymat changed the title [GTD] edit and capture use buffer instead of file Edit and capture use buffer instead of file Jan 22, 2022
@danymat
Copy link
Member

danymat commented Jan 22, 2022

Hello again !

Indeed, this is related to #225 and #259 (comment).

Before doing any real change, I think we need to discuss more about the potential requirement of this feature

@AckslD
Copy link
Contributor

AckslD commented May 19, 2022

I had a similar issue today, I had changed some things in my inbox.norg and then I did Neorg gtd edit and afterwards my previous edits where gone since I didn't save :/ I'm not sure I understand why using the buffer would imply creating a lot of buffers, can't you reuse the existing one?

Anyway, even if you still want to read from file I would say either:

  • Have neorg automatically save the current file before opening the Neorg gtd edit popup.
  • Don't even allow opening the Neorg gtd edit if the buffer is changed but not saved, and give an error.

@danymat
Copy link
Member

danymat commented Jul 8, 2022

I'm not sure I understand why using the buffer would imply creating a lot of buffers, can't you reuse the existing one?

We plan to rewrite GTD core with @vhyrro, so we will definitely handle this problematic

@danymat danymat added on hold On Hold bug Issues related to bugs. Please attach a severity, a priority and category with this label. and removed feature Issues related to feature proposals. Please attach a module. labels Jul 8, 2022
@AckslD
Copy link
Contributor

AckslD commented Aug 30, 2022

One other example where this is an issue:

  • do Neorg gtd capture
  • type a todo and press enter twice
  • do a new capture Neorg gtd capture
  • type a todo and press enter twice

The second todo will then overwrite the first since we didn't save in between.

@Paracelsus-Rose
Copy link

Any updates on this? Not sure how to workaround this issue, Neorg + GTD is exactly what I was looking for.

@danymat
Copy link
Member

danymat commented Dec 23, 2022

For reference: #695

@danymat danymat closed this as not planned Won't fix, can't repro, duplicate, stale Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues related to bugs. Please attach a severity, a priority and category with this label. on hold On Hold
Projects
None yet
Development

No branches or pull requests

4 participants