Skip to content

fix: avoid E490 when using move_subtree_up and move_subtree_down #1013

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MarkSverdlov
Copy link

Summary

This PR contains two commits - the first fix inconsequentaial probable type regarding the cursor positioning after calling move_subtree_up and move_subtree_down. The second add additional condition to the end of these functions to ensure E490 Fold not found is not raised.

Related Issues

Related #899 - I believe this issue is caused by the same underlying reason, of nvim failing to understand the updated fold structure after the rearranging of lines.

Changes

commit MarkSverdlov/orgmode@5bfa7f3

Patch a bug where E490: No fold found is raised when executing move_subtree_up or move_subtree_down in some scenarios. A minimal example is:

* a
* b
** c

In that case, if foldlevel=0 (i.e. ** c isn't visible) and the cursor is on * b, then using <leader>oK may raise E490. This doesn't happen on the first execution of this function after loading the buffer, but does happen consistently on the next executions of the function.

The adds additional condition for the last part of these functions (the parts that conditionally calls vim.fn.cmd([[norm!zc]])), that checks whether the fold exists. This guarantees the problematic instruction won't be called in these scenarios.

It's important to note that this patch doesn't solve the underlying bug - the conditioned suite shouldn't be executed to begin with unless foldclosed > -1, which suggests that before the rearranging of lines, the predecessor of the offending line had a positive foldlevel (and the offending line should have too), but since nvim doesn't agree with it, this patch at least circumvent the red error message.

Commit MarkSverdlov/orgmode@fdcfdca

This changes the column coordinate of the placement of the cursor after the rearranging of lines. Before, the column was pos[2], which is the line number of the previous location. Now, the column coordinate is set to be pos[3] which is the column number of the previous position. This change is quite inconsequential, but it's an easy fix.

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.

The column coordinate of the cursor is given by
vim.fn.getcurpos()[3], and not vim.fin.getcurpos()[2].
In some cases, executing org-subtree-up-or-down would causes E490 No
fold found error when the functional calls vim.cmd([[norm!zc]]).
This extra condition gurantees this error won't be thrown.
@MarkSverdlov
Copy link
Author

Hi,
Regarding the failed checks - I read the logs, and it seems like that the failures happened in clock-related checks i.e. clock should clock out and entry when its marked as done, since a minute ended just when the check happened:
passed in:

CLOCK: [2025-07-12 Sat 20:59]--[2025-07-12 Sat 21:00] => 0:01'

expected

CLOCK: [2025-07-12 Sat 21:00]--[2025-07-12 Sat 21:00] => 0:00

and not due to my patch. I tried to rerun the tests but didn't manage to find how to do it.

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.

1 participant