Skip to content

Toggle headlines #198

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 1 commit into from
Jan 17, 2022

Conversation

jgollenz
Copy link
Contributor

@jgollenz jgollenz commented Jan 6, 2022

fixes #164

todo:

  • toggle top level headlines (bug)
  • toggle plain list items
  • toggle first line of paragraph (bug)
  • add tests
  • toggle checkboxes to TODO headlines/DOCS.md#org_indent_mode)
  • add docs

@jgollenz jgollenz changed the title WIP: toggle headlines WIP: Toggle headlines Jan 6, 2022
Copy link
Contributor

@levouh levouh left a comment

Choose a reason for hiding this comment

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

Don't forget to run make format as well.

@jgollenz jgollenz marked this pull request as draft January 8, 2022 09:40
@jgollenz jgollenz changed the title WIP: Toggle headlines Toggle headlines Jan 8, 2022
@jgollenz
Copy link
Contributor Author

jgollenz commented Jan 8, 2022

@kristijanhusak the orgmode docs talk about "regions" that can be toggled as a whole. I don't use Emacs, do you know what is meant by this term? Is this something that's already used by nvim-orgmode?

@jgollenz
Copy link
Contributor Author

@kristijanhusak I'd need your opinion regarding the visual-mode mappings I mentioned in #164 (bottom) to move on with this PR ;)

@jgollenz
Copy link
Contributor Author

@kristijanhusak one last thing: I cannot detect a line that has no parent-headline with get_closest_headline(), because it will throw an error. I hacked this together:

function Files.has_headline(id)
  local current_file = Files.get_current_file()
  local msg = 'Make sure there are no errors in the document'
  if not vim.diagnostic then
    msg = string.format('%s by running :OrgDiagnostics command', msg)
  end
  if not current_file then
    error({ message = string.format('Failed to parse current file. %s.', msg) })
  end
  if not current_file:get_closest_headline(id) then
    return false
  else
    return true
  end
end

But it introduces some code duplication and I hate that. Do you have a better idea for how to check if a line even has a headline?

@kristijanhusak
Copy link
Member

@jgollenz I pushed small change where get_closest_headline() should return nil instead of throwing an error. Rebase and give it a try.

@jgollenz jgollenz force-pushed the feature/toggle-heading branch from 7c1f74a to 8d1fe36 Compare January 17, 2022 20:34
@jgollenz
Copy link
Contributor Author

@kristijanhusak works like a charm, thanks! You prefer squashing commits, right?

@jgollenz jgollenz marked this pull request as ready for review January 17, 2022 20:48
@jgollenz jgollenz force-pushed the feature/toggle-heading branch from 295463c to acf7034 Compare January 17, 2022 20:58
@kristijanhusak
Copy link
Member

@jgollenz Yeah, squashed commit is perfect.
I gave this a test, works great! Thanks!

@kristijanhusak kristijanhusak merged commit dc28ebb into nvim-orgmode:master Jan 17, 2022
@jgollenz jgollenz deleted the feature/toggle-heading branch January 17, 2022 21:54
gzagatti pushed a commit to gzagatti/orgmode that referenced this pull request Oct 19, 2022
SlayerOfTheBad pushed a commit to SlayerOfTheBad/orgmode that referenced this pull request Aug 16, 2024
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.

Implement org-toggle-heading functionality
3 participants