nvim-orgmode / orgmode

Orgmode clone written in Lua for Neovim 0.9+.
https://nvim-orgmode.github.io/
MIT License
2.96k stars 130 forks source link

Folding issues #524

Open jgollenz opened 1 year ago

jgollenz commented 1 year ago

This is a meta-issue for bugs with folding

jgollenz commented 1 year ago

BUG: folding fails if the body of a headline was not inserted with o key.

How to reproduce:

  1. On a blank line, enter insert mode and type * foo.
  2. Without leaving insert mode, hit enter to go to a new line and type bar.
  3. Leave insert mode, go back to the heading and try to fold it with <TAB>.

This returns [orgmode] No fold. However, if you exit insert mode after inserting the heading and then hit o to enter the newline, folding will work. This also seems to be influenced by our last line issue. Best to deal with that first.

kristijanhusak commented 1 year ago

@jgollenz can you check if this is still happening? We switched to nvim-treesitter folding some time ago, so maybe this is fixed now.

jgollenz commented 1 year ago

Nope, still happening for me

gerazov commented 1 year ago

Folding has stopped working all together (<S-Tab> doesn't cycle through folding levels, and <Tab> doesn't fold headings).

I tried reinstalling treesitter org to no avail.

kristijanhusak commented 1 year ago

@gerazov what's your foldexpr in org buffer?

gerazov commented 1 year ago

It's foldexpr=OrgmodeFoldExpr()

In the messages there is no error.

org_no_fold

kristijanhusak commented 1 year ago

We switched to treesitter based folding some time ago, you can see it being set here https://github.com/nvim-orgmode/orgmode/blob/master/ftplugin/org.vim#L19. Are you using latest version?

gerazov commented 1 year ago

Got it - works like a charm!

For some reason I had an autocommand set it to:

    vim.opt_local.foldexpr = "OrgmodeFoldExpr()"

Can't remember where I got that from :sweat_smile:

ryan77627 commented 1 year ago

I may have a misconfiguration, as I'm new to this project, but I believe I am exhibiting the same behavior here but I do not know why.

For me to reproduce:

  1. Create a .org file
  2. Create a heading, then multiple subheadings (all in insert mode) with some desecriptions, like the example snippet.
  3. I get the "[orgmode] no folds" error. If I write the file, close the buffer, then reopen the file, it works fine.

I checked, my foldexpr is set to the proper nvim_treesitter#foldexpr(). Plus, it does work fine like described above if I create new lines using o and <leader>oih, but that requires a lot of switching between Normal and Insert mode.

Example org file:

#+title: Test file

* This is a header
** This is a subheader
   Some descriptive text
** This is another subheader
   More descriptive text

I have not messed around deep in configuration yet, so this is what my vim.init file looks like:

set nu rnu
imap kj <Esc>
set ts=4
set sw=4
set sts=4
set et
set mouse=

call plug#begin(stdpath('data') . '/plugged')
"Plug 'prabirshrestha/vim-lsp'
"Plug 'mattn/vim-lsp-settings'
"Plug 'prabirshrestha/asyncomplete.vim'
"Plug 'prabirshrestha/asyncomplete-lsp.vim'
"Plug 'Yggdroot/indentLine'
Plug 'nvim-treesitter/nvim-treesitter', {'do':':TSUpdate'}
Plug 'vim-pandoc/vim-pandoc'
Plug 'vim-pandoc/vim-pandoc-syntax'
Plug 'dhruvasagar/vim-table-mode'
Plug '~/.config/nvim/after'
Plug 'skywind3000/asyncrun.vim'
Plug 'folke/tokyonight.nvim', {'branch':'main'}
Plug 'nvim-lualine/lualine.nvim'
Plug 'nvim-tree/nvim-web-devicons'
Plug 'ms-jpq/coq_nvim', {'branch':'coq'}
Plug 'ms-jpq/coq.artifacts', {'branch':'artifacts'}
Plug 'nvim-orgmode/orgmode'
call plug#end()

"Load Theme
colorscheme tokyonight-night

"Load COQ Autocomplete
let g:coq_settings = {'auto_start':'shut-up'}

"Load LuaLine, COQ, and nvim-orgmode
lua << END
require('lualine').setup()
require('coq')
require('orgmode').setup_ts_grammar()
require('nvim-treesitter.configs').setup {
    highlight = {
        enable = true,
        additional_vim_regex_highlighting = {'org'},
    },
    ensure_installed = {'org', 'vim'},
}

require('orgmode').setup({
    org_agenda_files = {'~/Sync/org/**/*'},
    org_default_notes_file = '~/Sync/org/refile.org',
})

vim.opt.conceallevel = 2
vim.opt.concealcursor = nc

--local lspconfig = require('lspconfig')
END

"asynccomplete Auto Complete Config
"inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
"inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
"inoremap <expr> <cr>    pumvisible() ? asyncomplete#close_popup() : "\<cr>"

"vim-table-mode config
let g:table_mode_corner_corner='+'
let g:table_mode_header_fillchar='='

"pandoc render and open preview
command Pv AsyncRun zathura '%:r.pdf'
command Rd silent exec "!pandoc -t pdf -o %:r.pdf --pdf-engine=xelatex --from=markdown+escaped_line_breaks -V geometry:margin=1in %"
command Rr exec "!pandoc -t pdf -o %:r.pdf --pdf-engine=xelatex --from=markdown+escaped_line_breaks -V geometry:margin=1in %"

"Auto-rerender markdown files to pdf
autocmd BufWritePost *.mkd :Rd

I should also mention the behavior is the same with nothing but the relevant treesitter and orgmode configurations within the LUA snippet present with no other plugins installed.

ryan77627 commented 1 year ago

So quick update for me, folding works fine when the file is newly opened, and I found after some searching that zx updates the folds correctly and will work, it's just a matter of the folds not being auto updated when entering/leaving insert mode occasionally for whatever reason.

lyz-code commented 7 months ago

Whenever I run org_move_subtree_up or org_move_subtree_down on an item the moved item is hidden in the fold where it was going. So if it's moved down it's hidden inside the fold of the item below itself.

lyz-code commented 7 months ago

The folding of the recurring tasks iterations is also kind of broken. For the next example

** TODO Recurring task
   DEADLINE: <2024-02-08 Thu .+14d -0d>
   :PROPERTIES:
   :LAST_REPEAT: [2024-01-25 Thu 11:53]
   :END:
   - State "DONE" from "TODO" [2024-01-25 Thu 11:53]
   - State "DONE" from "TODO" [2024-01-10 Wed 23:24]
   - State "DONE" from "TODO" [2024-01-03 Wed 19:39]
   - State "DONE" from "TODO" [2023-12-11 Mon 21:30]
   - State "DONE" from "TODO" [2023-11-24 Fri 13:10]

   - [ ] Do X

When folded the State changes is not added to the Properties fold. It's shown something like:

** TODO Recurring task
   DEADLINE: <2024-02-08 Thu .+14d -0d>
   :PROPERTIES:...                                                                                                                                                                                              

   - State "DONE" from "TODO" [2024-01-25 Thu 11:53]
   - State "DONE" from "TODO" [2024-01-10 Wed 23:24]
   - State "DONE" from "TODO" [2024-01-03 Wed 19:39]
   - State "DONE" from "TODO" [2023-12-11 Mon 21:30]
   - State "DONE" from "TODO" [2023-11-24 Fri 13:10]

   - [ ] Do X

I don't know if this is a bug or a feature, but when you have many iterations it's difficult to see the task description. So it would be awesome if they could be included into the properties fold or have their own fold.

EDIT: I've found that if you set the org_log_into_drawer = "LOGBOOK" in the config this is fixed.

LonelyMusicDisc commented 6 months ago

Exiting out of insert re-folds the heading I'm in when when in Overview mode, which is very annoying.

gerazov commented 6 months ago

So quick update for me, folding works fine when the file is newly opened, and I found after some searching that zx updates the folds correctly and will work, it's just a matter of the folds not being auto updated when entering/leaving insert mode occasionally for whatever reason.

Thanks for the tip - I was reloading the file using :e to get the folds to align ...