org-fc icon indicating copy to clipboard operation
org-fc copied to clipboard

Command to quickly turn region to a cloze hole.

Open c1-g opened this issue 2 years ago • 4 comments

This is a command that helps me quickly make clozes.

c1-g avatar Jan 09 '22 12:01 c1-g

This looks like an useful feature!

One concern is that you're also adding the cloze hole ID, I think it would be better to use org-fc-update for this. Cloze cards keep track of the next hole ID in a headline property and org-fc-update makes sure this ID is used for the new hole and the property is updated.

E.g. if you start with a card {{foo}@0} {{bar}@1}, delete the first hole foo {{bar}@1}, then add a new hole, foo {{bar}@1} {{baz}}, from my understanding your code would give the new hole ID 1 whereas org-fc-update would use ID 2. (Unless he ID passed in as a prefix argument, but I don't see where this would be useful).

And thing-at-point requires thingatpt which might need to be loaded at the beginning of the file.

l3kn avatar Jan 14 '22 12:01 l3kn

I'm only using this command to make cloze before running org-fc-type-cloze-init so I don't understand the use case you've just described. Another thing to point out, this command has a really simple mechanism to determine the hole index by counting regexp I'm not sure on how to extend it to cover your example.

I guess not indexing the hole at all and just insert "{{" and "}}" to enclose the region then add some logic to call org-fc-update when the entry has been initialized as a flashcard at the end seems like a more flexible option.

On thingatpt, I don't think we have to load the whole library just to use a function. So we would be better off just using forward-word and backward-word to get the bound of a word at point.

c1-g avatar Jan 15 '22 01:01 c1-g

I made some changes to use org-fc-update as you've described. Now it doesn't index holes by default unless given a prefix argument and it uses only the bounds-of-thing-at-point function of thingatpt since the function will probably be better than any thing I come up with. I use declare-function for this so no need to load the library.

c1-g avatar Jan 16 '22 01:01 c1-g

Added (require 'thingatpt) in case declare-function isn't enough.

c1-g avatar Jan 16 '22 01:01 c1-g

Sorry for taking so long to get to this, I've made merged this into the develop branch and made some changes.

For now, the function is called org-fc-type-cloze-dwim so it's consistent with the file it's defined in. There are some cases where marking cloze holes (without IDs) is useful for other card types and once that's implemented, the function can be moved and renamed.

l3kn avatar May 24 '23 11:05 l3kn

Hi @c1-g, I got a bit distracted by some other changes to org-fc but now I'm in the process of merging completed parts into the main branch. I'd like to credit you for this feature, is it alright for you if I mention you in the Changelog?

l3kn avatar Dec 31 '23 14:12 l3kn