Skip to content

feat(todos): support file-specific todo definitions #956

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

Merged
merged 5 commits into from
Apr 4, 2025

Conversation

seflue
Copy link
Contributor

@seflue seflue commented Apr 3, 2025

While emacs orgmode actually supports multiple todo keyword sequences, this implementation explicitly focuses on one sequence, because the plugin currently also supports only one sequence to be defined in the configuration.

To support the full emacs functionality this needs to be extended later.

Summary

Support to overwrite the globally defined todo keywords with a file specific one.

Related Issues

Related #

#250

Closes #

#185

Changes

  • parses todo keywords from #+todo: when defined
  • falls back to todo keywords defined in config
  • when changing todo keyword state, retrieve it from the current org-file (and rely on the fallback) instead of using the config directly
  • add tests to validate the new behavior

Checklist

I confirm that I have:

  • Followed the
    Conventional Commits
    specification
    (e.g., feat: add new feature, fix: correct bug,
    docs: update documentation).
  • My PR title also follows the conventional commits specification.
  • Updated relevant documentation, if necessary.
  • Thoroughly tested my changes.
  • Added tests (if applicable) and verified existing tests pass with
    make test.
  • Checked for breaking changes and documented them, if any.

Support to overwrite the globally defined todo keywords with a file
specific one.

While emacs orgmode actually supports multiple todo keyword sequences,
this implementation explicitly focuses on one sequence, because the
plugin currently also supports only one sequence to be defined in the
configuration.

To support the full emacs functionality this needs to be extended later.
Copy link
Member

@kristijanhusak kristijanhusak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good as a starting point into this feature. There are few more usages of config:get_todo_keywords() across mappings.lua file where we can use the file level ones with self.files:get_current_file():get_todo_keywords().

seflue and others added 2 commits April 3, 2025 16:47
Co-authored-by: Kristijan Husak <[email protected]>
Co-authored-by: Kristijan Husak <[email protected]>
@seflue
Copy link
Contributor Author

seflue commented Apr 3, 2025

@kristijanhusak I a trying to tackle a more fundamental issue, where I might need your help: The custom keywords are currently not correctly highlighted. I try to understand, how the highlighting of keywords works in general and why the custom keywords are currently ignored.

Here a screenshot. Only CANCELED is currently part of my globally defined keywords - so it is correctly highlighted. All others are completely custom and ignored by the highlighting.
image

From what I learned form the code, I have the gut feeling, that the highlight definitions are loaded with the start of the plugin and to highlight the custom words correctly those highlighting informations need to be updated, when a file is loaded. Is my hypothesis correct? Do you have a suggestion how to fix the issue?

@kristijanhusak
Copy link
Member

@seflue highlighting of the keywords is done through a custom ts predicate. Currently, it figures out if the match is a todo keyword by checking config:get_todo_keywords().

I assumed you want to do this in the next PR that's why I didn't mention it.
Basically, some refactoring will be needed where this predicate can have access to orgmode.files, and then we can get the file using the source parameter on the predicate, which is a buffer number. So, something like this will be an improvement to have the highlighting work:

  vim.treesitter.query.add_predicate('org-is-todo-keyword?', function(match, _, source, predicate)
    local node = match[predicate[2]]
    node = node and node[#node]
    if node then
      --- Assume predicate have `self.files` instance of `OrgFiles`
	  --- I'm not sure if getting a buffer name can cause some performance issues, so we might need 
	  --- to cache the bufnr -> org_file.
      local todo_keywords = self.files:get(vim.api.nvim_buf_get_name(source)):get_todo_keywords()
      local text = vim.treesitter.get_node_text(node, source)
      return todo_keywords[text] and todo_keywords[text].type == predicate[3] or false
    end

    return false
  end, { force = true, all = true })

@seflue
Copy link
Contributor Author

seflue commented Apr 3, 2025

@kristijanhusak I just found the code you mentioned and also saw, that some refactoring would be needed. Because it would be nice, if the highlighting updates on changing the #+todo: definition it might be a bit more complex - so I agree, it is easier to defer fixing the highlighting to a future PR.

@seflue seflue requested a review from kristijanhusak April 3, 2025 16:47
@seflue
Copy link
Contributor Author

seflue commented Apr 3, 2025

Looks good as a starting point into this feature. There are few more usages of config:get_todo_keywords() across mappings.lua file where we can use the file level ones with self.files:get_current_file():get_todo_keywords().

I also integrated the feature to all mappings using config:get_todo_keywords() (hope I didn't miss any).

Copy link
Member

@kristijanhusak kristijanhusak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@kristijanhusak kristijanhusak merged commit 689f20a into nvim-orgmode:master Apr 4, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants