Skip to content
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

Set default vaule of consult-org-heading to current heading #366

Closed
Dima-369 opened this issue Jul 23, 2021 · 6 comments
Closed

Set default vaule of consult-org-heading to current heading #366

Dima-369 opened this issue Jul 23, 2021 · 6 comments

Comments

@Dima-369
Copy link

It would be amazing if (consult-org-heading) would set the current org heading as its default value.

I tried to mess around with :default "..." regardless what I set in there, I was never able to pre-select any org-heading correctly.

How would one implement this? I often have large org files and if this is implemented, I would be able to quickly skim the file like a TOC.

I think sometimes I got it to work but it moves the default value as the very first index which also breaks the correct file ordering (though it might be because I am using ivy and selectrum, not sure if anyone else has the same issue) .

@Dima-369
Copy link
Author

I found out that this is already implemented in counsel via (counsel-org-goto).

With the code below live-preview as also enabled:

  (ivy-configure 'counsel-org-goto
    :update-fn 'auto)

@minad
Copy link
Owner

minad commented Jul 23, 2021

Related issue #287

I found out that this is already implemented in counsel via (counsel-org-goto).

Counsel is a different library than Consult, which is tied to Ivy and is constructed differently than Consult/Vertico/Selectrum etc. You can use Counsel/Ivy if that ecosystem works better for you.

I think sometimes I got it to work but it moves the default value as the very first index which also breaks the correct file ordering (though it might be because I am using ivy and selectrum, not sure if anyone else has the same issue) .

If you pass a default candidate, the candidate will be moved to the top in Vertico/Selectrum. This is by construction since the first candidate is selected automatically when no other input has been made. There are two possibilities to solve this:

  1. Move the headlines above the current headline to the end (wrap-around), such that the current (default) headline comes first. This is the behavior currently implemented in consult-line, but not in consult-outline, consult-org-heading etc.

  2. upport a special mode in the completion UI, which does not move the default candidate and which preserves the starting point during filtering. This special mode could set in automatically in the completion UI, if sorting is disabled (display-sort-function=identity) and if a default value is specified.

With Selectrum you can disable the movement of the default candidate like this:

(advice-add #'consult-org-heading :around
            (lambda (orig)
              (let ((selectrum-move-default-candidate nil))
                (funcall orig))))

However this Selectrum feature is incomplete in my opinion, since the starting position is not preserved as soon as one starts filtering. But generally I think he issue should be solved in the completion UI. I move this issue to minad/vertico#92 to track this and close this issue here.

@Dima-369
Copy link
Author

Thanks for the thorough explanation!

I actually noticed the same issue in counsel-org-goto that the starting point is not preserved correctly, but here I was able to patch it with :unwind on (ivy-read) and then restoring the original point on quitting out of ivy-read via escape.

@minad
Copy link
Owner

minad commented Jul 23, 2021

I actually noticed the same issue in counsel-org-goto that the starting point is not preserved correctly, but here I was able to patch it with :unwind on (ivy-read) and then restoring the original point on quitting out of ivy-read via escape.

This is not what I am talking about, after quitting the point should of course be preserved. This is easy to solve by correct unwinding as you point out.

The main complication is the preservation of the starting point when you filter. The optimal (complicated) solution looks like this:

1       ==filtering==>       1
2                            x <- removed by filtering
3 <- default/selected        x <- removed by filtering
4                            4 <- selected after filtering
5                            5

@minad
Copy link
Owner

minad commented Jul 23, 2021

For completeness, with wrap around (option 1. from my comment above), the order is preserved naturally:

3 <- default/selected       x <- removed by filtering
4                           4 <- selected after filtering
5        ==filtering==>     5
1                           1 
2                           x <- removed by filtering

@minad
Copy link
Owner

minad commented Jul 23, 2021

And Selectrum does this, which is not optimal (1 is selected instead of 4, which comes after the default 3)

1       ==filtering==>       1 <- selected after filtering
2                            x <- removed by filtering
3 <- default/selected        x <- removed by filtering
4                            4
5                            5

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

No branches or pull requests

2 participants