oantolin / embark

Emacs Mini-Buffer Actions Rooted in Keymaps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`embark-org-target-element-context` is pushed to to the head of `embark-target-finders` even when it was already contained somewhere in `embark-target-finders`

talw opened this issue · comments

(Excuse me for the the long issue title)

First of all, thank you very much for this package. This issue is about a small wart that I easily avoid in my configuration but it might cause trouble to other users, so I thought of creating an issue for it.

Summary

I assume the intention is to add embark-org-target-element-context if it isn't already in embark-target-finders, and put it after embark-target-active-region if that is already in embark-target-finders.

However what about the case where the user already had embark-org-target-element-context in embark-target-finders? In that case don't we want to leave it as is? Currently it seems the behavior is to move it up to the head of embark-target-finders.

Details

I noticed that embark-org-target-element-context is first in embark-target-finders for me despite already setting it (before loading embark-org) at a very specifically chosen place in embark-target-finders.

Looking at embark-org.el:

(if-let (((not (memq 'embark-org-target-element-context embark-target-finders)))
         (tail (memq 'embark-target-active-region embark-target-finders)))
    (push 'embark-org-target-element-context (cdr tail))
  (push 'embark-org-target-element-context embark-target-finders))

The condition (not (memq 'embark-org-target-element-context embark-target-finders)), i.e. if embark-org-target-element-context wasn't already in embark-target-finders, does not apply in my since I did set it, so the nil/else branch is taken:

(push 'embark-org-target-element-context embark-target-finders)

However that just inserts a duplicate of embark-org-target-element-context in the head of the list. Perhaps the intention was to use add-to-list (as it does not add duplicates)? I can see in git blame that the diff here was due to a6ea648 whose goal was to Give org element targets lower priority than the active region which is indeed handled by the t/then branch, but perhaps the nil/else branch falsely assumes that the first condition of the if-let was t (that embark-org-target-element-context is not in embark-target-finders) and the second condition was nil (embark-target-active-region is not in embark-target-finders)? Hence the push at the head of the list?

The aforementioned code replaced (add-to-list 'embark-target-finders 'embark-org-target-element-context) which did handle correctly the case where embark-org-target-element-context was already in embark-target-finders by using add-to-list (as it does not add duplicates).

Am I mistaken about the intention here? Or is this a bug?

Definitely a bug, thanks for reporting! Also, please test the fix. :)

Definitely a bug, thanks for reporting! Also, please test the fix. :)

Thank you for the quick response!

Tested it, and it seems to be working 🎉