nvim-orgmode / orgmode

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

Scheduled/deadline entries are not parsed if keyword is on the first line after the headline #207

Closed gravndal closed 2 years ago

gravndal commented 2 years ago

Describe the bug

The parses doesn't appear to understand the SCHEDULED and DEADLINE keywords when they appear on the first line after the headline.

Steps to reproduce

With the following file added to the agenda:

* An entry with a date.
  <2022-01-10 Mon>

* A scheduled task.
  SCHEDULED: <2022-01-11 Tue>

* A scheduled task with schedule on the second line.
  Foo bar baz.
  SCHEDULED: <2022-01-12 Wed>

* A deadline.
  DEADLINE: <2022-01-13 Thu -5d>

* A deadline and scheduled entry.
  DEADLINE: <2022-01-15 Sat>
  SCHEDULED: <2022-01-14 Fri>

* A scheduled and deadline entry.
  SCHEDULED: <2022-01-16 Sun>
  DEADLINE: <2022-01-17 Mon -10d>

* Something else.
  [2022-01-20]
  SCHEDULED: <2022-01-16 Sun>

And starting neovim with $ faketime 2022-01-10 nvim [...]

The week-agenda view for fake-today is:

Week-agenda (W2):
Monday     10 January 2022
  test:       An entry with a date.
Tuesday    11 January 2022
Wednesday  12 January 2022
  test:       A scheduled task with schedule on the second line.
Thursday   13 January 2022
Friday     14 January 2022
  test:       A deadline and scheduled entry.
Saturday   15 January 2022
Sunday     16 January 2022
  test:       Something else.

Expected behavior

Agenda view matching that of emacs.

Emacs functionality

Week-agenda view:

Week-agenda (W02):
Monday     10 January 2022 W02
  test:       An entry with a date.
  test:       In   3 d.:  A deadline.
  test:       In   5 d.:  A deadline and scheduled entry.
Tuesday    11 January 2022
  test:       Scheduled:  A scheduled task.
Wednesday  12 January 2022
  test:       A scheduled task with schedule on the second line.
Thursday   13 January 2022
  test:       Deadline:   A deadline.
Friday     14 January 2022
  test:       A deadline and scheduled entry.
Saturday   15 January 2022
  test:       Deadline:   A deadline and scheduled entry.
Sunday     16 January 2022
  test:       Scheduled:  A scheduled and deadline entry.
  test:       Something else.

Minimal init.lua

I don't expect these settings to actually matter, but here you are:

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]

local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'

local function load_plugins()
  require('packer').startup {
    {
      'wbthomason/packer.nvim',
      {'nvim-treesitter/nvim-treesitter', run = ':TSUpdate'},
      {'kristijanhusak/orgmode.nvim', branch = 'master' },
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. '/plugin/packer_compiled.lua',
    },
  }
end

_G.load_config = function()
  require('nvim-treesitter.configs').setup({})

  local parser_config = require('nvim-treesitter.parsers').get_parser_configs()

  parser_config.org = {
    install_info = {
      url = 'https://github.com/milisims/tree-sitter-org',
      revision = 'f110024d539e676f25b72b7c80b0fd43c34264ef',
      files = {'src/parser.c', 'src/scanner.cc'},
    },
    filetype = 'org',
  }
  vim.cmd[[packadd nvim-treesitter]]
  vim.cmd[[TSUpdate]]

  require('orgmode').setup({
    org_agenda_files = { '~/org/**/*', },
    org_default_notes_file = '~/org/refile.org',
    mappings = {
      global = {
        org_agenda = '<Space>oa',
        org_capture = '<Space>oc',
      },
    },
  })
end

if vim.fn.isdirectory(install_path) == 0 then
  vim.fn.system { 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path }
  load_plugins()
  require('packer').sync()
  vim.cmd [[autocmd User PackerComplete ++once lua load_config()]]
else
  load_plugins()
  require('packer').sync()
  _G.load_config()
end

vim.opt.background = 'light'

P.S. There's a syntax error in the minimal_init.lua template: https://gist.github.com/kristijanhusak/a0cb5f4eb2bad3e732a1d18d311ebe2f#file-minimal_init-lua-L29

Screenshots and recordings

No response

OS / Distro

nixos unstable: 22.05.20220119.32e4b99 (Quokka)

Neovim version/commit

431915fe6

Additional context

In addition to the agenda view, this also impacts the <C-a> <C-x> mappings.

Tested Emacs was version GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.30, cairo version 1.16.0), without any configuration aside from adding the test file to the agenda.

Nearing deadlines also aren't shown for fake-today, which seems like an issue on it's own, unless I've overlooked some setting that overrides the -Nd> parts of the timestamp?

kristijanhusak commented 2 years ago

I'm not sure how faketime affects the dates in Neovim, but I don't want to worry about that. From my tests, both emacs and neovim orgmode behaves the same if I open them them without any time faking. Here are comparing screenshots:

screenshot1

screenshot2

P.S. There's a syntax error in the minimal_init.lua template:

Thanks for noticing. I fixed it.

Can you give it a test without a faketime and see how it works?

gravndal commented 2 years ago

I'm not sure how faketime affects the dates in Neovim, but I don't want to worry about that.

The use of faketime doesn't matter, all it does is intercept system calls like time(2) and fstat(2) to give you a (hopefully) reliable way to test something reproducibly for a specific date and time.

Can you give it a test without a faketime and see how it works?

I suppose I could have been more explicit: This wasn't discovered using libfaketime.

Anyway, seeing as this works for you, I'll try some things and report back.

gravndal commented 2 years ago

The issue is with the tree-sitter grammar:

False alarm I guess.