~l3kn/org-fc#20: 
Move flashcard heading to center whenever reviewing a new one

I use the following keymap template to support this by triggering it whenever a flashcard is rated, but I believe it would be a nice feature to have by default:

;; modified the keymap a bit for readability purposes
(map!  "C-x C-a" (cmd!
                 (org-fc-review-rate-again)
                 (evil-scroll-line-to-center (line-number-at-pos)))
Status
REPORTED
Submitter
~xyank
Assigned to
No-one
Submitted
3 years ago
Updated
2 years ago
Labels
Bug

~l3kn 3 years ago

So you want to move the previously reviewed card to the center of the buffer? I assume you have similar bindings for the other rating functions.

~xyank 3 years ago*

Here's the full thing. The only issue with it is that when you first begin reviewing cards, the first flashcard isn't centered.

(map!
  ;; rate
  :leader "r a" (cmd!
                 (org-fc-review-rate-again)
                 (evil-scroll-line-to-center (line-number-at-pos)))
  :leader "r h" (cmd!
                 (org-fc-review-rate-hard)
                 (evil-scroll-line-to-center (line-number-at-pos)))
  :leader "r g" (cmd!
                 (org-fc-review-rate-good)
                 (evil-scroll-line-to-center (line-number-at-pos)))
  :leader "r e" (cmd!
                 (org-fc-review-rate-easy)
                 (evil-scroll-line-to-center (line-number-at-pos)))
  )

~xyank 3 years ago*

So you want to move the previously reviewed card to the center of the buffer?

Oh no, this function first rates the card, which then shows the new card, which we then "center" in the buffer, which results in the entire ancestral tree being shown on screen.

~xyank 3 years ago

Update: The keymap I have posted doesn't always work: probably because the new card isn't loaded by the time the (evil-scroll-line-to-center...) line is evaluated.

I assume that the (org-fc-review-rate.*) functions aren't blocking (the execution of the next line): are they? Forgive me, I don't know much about emacs to say anything for sure.

~l3kn 3 years ago

Your keymaps not always working might be related to the way org-fc-review-next-card and org-fc-review-rate interact.

Just to make sure I get this right:

  • you review a card which is narrowed to the level-1 parent heading
  • you rate the card and it's buffer is reset (unnarrowed, overlays are removed)
  • after unnarrowing, the heading of the card is shown in the first line of the buffer, hiding the outline / text above it
  • instead of showing the unnarrowed heading at the top, you want to show it in the center of the buffer

~xyank 3 years ago

Here is a GIF to show you my workflow when using org-fc. I have used command-log-mode to show you the keys manually pressed so you have a clear idea of what is going on.

You got the workflow correct except for a few flaws:

  1. The card is not narrowed to (as in, only showing) the level-1 parent heading.
  2. I simply want the entire ancestral tree to be shown on the screen, which doesn't occur by default (as shown in the GIF, when I first begin an org-fc session, what occurs is that the ancestor tree of the flashcard isn't seen on the screen, but it is visible in the buffer. To show the entire tree, I use evil-scroll-line-to-center. I don't want to show it at the exact center of the buffer: I just want to ensure that the entire tree is shown by default and one doesn't need to manually ensure it is shown with every flashcard that is prepared.

I guess this confusion was caused by the issue name. Forgive me: I'll take more care regarding how I report issues in the future.

~l3kn 3 years ago

In your GIF, the german cards are displayed as I'd expect, but the monkey dance card and there the ancestors are not shown.

I'm not sure what causes this, I managed to replicate this behavior in a test file but not in a consistent way. Is the card always displayed this way in your file? If so, would you mind sending it to me for testing (unless it contains personal information you'd rather not share)?

I agree that cards should be shown with their full ancestral tree, I just need some way to test if my fix works.

~xyank 3 years ago

In your GIF, the german cards are displayed as I'd expect, but the monkey dance card and there the ancestors are not shown.

Here's my explanation (based on my understanding) of what is going on: For the first flashcard created when I began the org-fc session, the ancestor tree is not hidden, it's just that the buffer has scrolled upward such that only the parent heading is seen. If you see the GIF, you'll notice I did z z which is the evil keymap for evil-scroll-line-to-center. That showed the entire buffer (which admittedly consists of very few lines.

For the next cards, I am using the keymaps I have given above, which attempt to do the evil-scroll-line-to-center thing automatically once the new flashcard is loaded. This is why you will notice that the german card and the doom keymap card is displayed as you would expect.

Of course, this doesn't happen always, which is why I posted this update - there seem to be instances where the new flashcard is not loaded by the time the evil-scroll-line-to-center is evaluated, meaning the line that is "scrolled to center" is the previous flashcard's line, which means that if the new flashcard's parent heading's line is far below the previous flashcard's line, then it will again only show the parent heading.

I'm not sure what causes this, I managed to replicate this behavior in a test file but not in a consistent way. Is the card always displayed this way in your file? If so, would you mind sending it to me for testing (unless it contains personal information you'd rather not share)?

I'm doubt it's a card specific thing, really. I have created a small test org-file and a workflow to show you how I can reproduce it in the first flashcard. For the next flashcards, I have already explained how I have created a sorta-workaround that doesn't always work.

Here is the test org file and here is an MP4 file showing how I can always ensure that the first flashcard shows only the parent on the screen, even though the entire ancestor tree is rendered in the buffer.

~l3kn 3 years ago

Thanks for the test file, I've executed the same commands as you do in your video but the card is shown with the full ancestor tree each time I try it.

Can you pull the latest version of org-fc and see if the issue persists?

~xyank 2 years ago

All right, so I pulled the latest version of org-fc[1] and I can still accomplish this using the same workflow I just showed you in the MP4 file.

The main thing you need to do to reliably replicate this using native emacs keybindings (at least according to what I know) is that you need to first move the cursor to the last line (or the line after that) of the buffer, and then press C-l C-l which could move the line itself to the top of the screen, and then begin a review session. This should always cause the first flashcard to not show the entire ancestor by default unless you scroll up in the flip mode of the flashcard.

I found an emacs native method to fix this for all possible flashcards, one that you can merge into the existing code: using recenter function.

;; center the flashcard before showing it
  (setq org-fc-after-setup-hook '(recenter))

And that's it, this problem doesn't occur at all. This is my solution, and it's not even an awkward workaround (thanks for the hooks, by the way - I forgot about them until I reread your docs).

I understand that you would need to replicate this before you would understand the need for this code being merged, so please tell me if you still have issues replicating this.

[1]: package details

    Package: org-fc
     Source: Straight
     Pinned: unpinned
      Build: HEAD -> main, origin/main, origin/HEAD 0fd72b4 2020-10-02 11:40:07 +0200
             (:host nil :repo "https://git.sr.ht/~l3kn/org-fc" :branch "main" :files
                    ("*")
                    :package "org-fc" :type git :local-repo "org-fc")
   Homepage: https://www.leonrische.me/pages/org_flashcards.html
    Modules: Declared by the following Doom modules:
             :private packages
             :private modules
    Configs: This package is configured in the following locations:

~xyank 2 years ago

Sidenote: I just realized that the "re-centering" itself is a workaround: what I really intended is the top-level heading (aka the root) to always be shown on the screen.

If we have a flashcard whose heading level is, for example, 15, then it would show that line on the center. If showing the entire tree takes up more than half of the screen vertical size, then "re-centering" would move the ancestor tree "up", meaning the root of the tree wouldn't be seen on the screen.

I don't know what's the appropriate emacs function to ensure this occurs (one could, for example, attempt to move the cursor to the bottom of the screen, which would then fix the previous example issue - but another edge case would be when the tree is so huge that it takes up more than the screen vertical size (impractical, yes, but I'm just listing out edge cases)), but I do think that the above fix is "good enough", assuming there is no issue on my end that requires me to use this.

~l3kn 2 years ago

Using a after-setup-hook is a good workaround, (add-hook 'org-fc-after-setup-hook #'recenter) is better as it doesn't overwrite existing hooks.

I think the trick is to recenter the level 1 parent headline to the top instead of recentering the card's headline to the center (default behavior of recenter), once I've figured out how to do that I'll add it to the main org-fc code.

Register here or Log in to comment, or comment via email.