-
Notifications
You must be signed in to change notification settings - Fork 54
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
Add groups to citar-open functions #491
Conversation
fc4fcde
to
fc1759a
Compare
fc1759a
to
80bd72a
Compare
@localauthor - I set this to merge to the
Let me know your thoughts, and if you want to make any changes here before I merge? Also, note: this now conflicts with the new base branch. You'll need to rebase and maybe fix a conflict or two. |
Hmm ... actually, I wonder: do you think we should merge this to #496? Or should we just evaluate this on its own, and if we want to merge it, then do so, and I can rebase #496 on this, which I can refocus just on Really the CR vs CRM discussion varies depending on the command in question. |
I am just starting to test this branch. Here's what you see after running Two things:
Any thoughts on the above @minad? |
- change 'citar-select-resources' to completing-read
28e96aa
to
4d5a002
Compare
Ok, I just rebased onto main. I changed As for the question of where to merge this (either to This branch changes CRM to CR in all the open functions anyway. |
- simplify 'citar-open' - edit doc strings
4d5a002
to
23fedc2
Compare
Let's keep it here for now. There are still some subtleties with |
There does seem to be a bug here though. If I only select one candidate, and then do Even if I only select one resource using |
9f9f30d
to
df3c13b
Compare
All the |
When I use |
- Let-bind 'embark-default-action-overrides' for each command - Add 'citar-open-multi' function, so files are handled appropriately when type is 'consult-multi'
Latest commit allows Each The edge case here is with Hopefully it works for you as it does for me. |
One issue with using If only |
- changes 'browse-url-default-browser' to 'browse-url', which defaults to 'browse-url-default-browser' anyway, but might be set otherwise in user's config - sets 'citar--open-note' to prompt for yes or no before creating a new note
What if you define the variable? Do you get an error, or just not the behavior? |
I say "fully" because To explain: without If, as @minad seemed to be suggesting here, |
These result in "unused lexical variable" warnings. On a separate matter, it's getting closer. But if I have this: ... and then do |
@localauthor Yes of course. We should switch to |
I'm afraid I don't know how to avoid such warnings, or what they mean really. |
I see the same, except for this last step. Maybe there's something wrong with my install of the branch. Running |
@minad - any tips? He's let-binding |
Oh. These default action overrides should not be necessary. The default file and url actions should work ootb as should all the other actions. If not something else is wrong and should be fixed. The correct approach is to define your own category if you want to overwrite or define your own actions. |
Ah I see, you have special open functions. I guess in this case the override is justified. But overriding browse-url for url and the consult-multi override should not be needed. Probably you miss a defvar to fix the lexical error? |
Yes; I just committed that change. |
(message "No associated resources")))) | ||
|
||
(defun citar-open-multi (selection) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This command is unnecessary and should be removed. Embark already dispatches consult-multi to file and url. That's the purpose of consult-multi and the corresponding Embark candidate transformer.
(let* ((key-entry-alist (citar--ensure-entries keys-entries)) | ||
(let* ((embark-default-action-overrides '((consult-multi . citar-open-multi) | ||
(file . citar-file-open) | ||
(url . browse-url))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the consult-multi override should go away and the url override probably too, in order to allow the user to customize the action on the side of Embark.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking at this, and for the comments.
Embark and consult-multi work just as you describe when it comes to categorizing files and urls, but (as I describe here) because the source of the target is minibuffer completion, Embark sets the default action for all targets, regardless of type, to the command that opened the minibuffer in the first place (per the docstring of embark-default-action-overrides
). That means that, in this case, the default action for any target type is set to citar open
, which is a function that does not take files or urls as arguments. Hence the overrides. It's a bit of a hail mary, I guess, but I'm afraid I'm running up against the limits of my lisp/emacs knowledge here. ;)
As for the citar-open-multi
function, it was only added to allow embark-act-all
to work on properly on targets of multiple types. When using embark-act
on single candidates, consult-multi works just as expected and this function isn't called. When calling embark-act-all
on targets of multiple types, they haven't been transformed by the candidate transformer yet --- so they remain typed as consult-multi
. Hence, another override. Again, bit of a hail mary -- but functional!
Thanks again for your comments. Really appreciate your taking the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, maybe I missed something here but this seems wrong. The default action is supposed to be the command that started the completion. Overriding it with something else is counterintuitive and goes against the usual Embark behavior.
Note that Embark has a minibuffer argument injection mechanism which works even if functions don't take arguments. I suggest you dig deeper into the Embark documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That means that, in this case, the default action for any target type is set to citar open, which is a function that does not take files or urls as arguments. Hence the overrides.
I am specifically referring to this. This is wrong. There is the minibuffer injection mechanism.
When calling embark-act-all on targets of multiple types, they haven't been transformed by the candidate transformer yet --- so they remain typed as consult-multi.
I will check this, but if this is the case it is a bug or issue in Embark.
I know that oantolin added some target type checking to embark-act-all and there is indeed a problem when acting on candidates of multiple categories at once. Anyways this should be handled properly by Embark itself.
EDIT: Okay, I checked Embark. Embark is doing everything alright. When you act on candidates of multiple categories at once then indeed the candidates are not transformed. Then the candidates remain consult-multi. They are only transformed if you act only on files, only on buffers or only on urls. But still, it should not be necessary to override the default action since the command itself should then be capable of handling these consult-multi candidates. You can look into consult--multi and consult-buffer as examples. There I also don't overwrite the embark default actions and everything works as expected :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I experimented a bit with removing these lines, and things seem to work fine, until I run embark-act-all
on the resulting resources. So to recap:
citar-open
- narrow candidates and then
embark-act-all
- from there I get a list of resources, if I run
embark-act-all
, I then get the error below:
embark PCH: (user-error "No target found")
... which is I think why he introduced the citar-open-multi
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you load embark-consult? I don't know what is wrong here exactly, but the override should not be needed due to the design of embark. consult-buffer also works without override.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you load embark-consult?
I did require it now, and get:
(execute-extended-command nil "citar-open" nil)
I don't know what is wrong here exactly, but the override should not be needed due to the design of embark. consult-buffer also works without override.
I'll take another look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bdarcus What's the status here? Did you figure out the issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you figure out the issues?
Not yet. Likely in the next few days.
@bdarcus As a small demonstrator, this works for me: (require 'embark-consult)
(defun open-example ()
(interactive)
(let* ((candidates
(list (propertize "init.el" 'consult-multi
'(file . "~/.config/emacs/init.el"))
(propertize "emacs.org" 'consult-multi
'(url . "https://www.gnu.org/software/emacs/"))))
(result (completing-read "Open: "
(lambda (str pred action)
(if (eq action 'metadata)
'(metadata (category . consult-multi))
(complete-with-action action candidates str pred)))
nil t)))
(pcase (get-text-property 0 'consult-multi (car (member result candidates)))
(`(url . ,url) (eww url))
(`(file . ,file) (find-file file))))) |
Changes:
Adds
completing-read
tocitar--open-note
, for when multiple notes existChanges
citar-select-files
tocitar-select-resources
, and calls the new function in bothcitar-open
andcitar-open-library-files
Adds group-function,
citar-select-group-related-resources
, tocitar-select-resources
, to group candidates by typeThe result of calling
citar-open
on an entry with associated files, notes, and a link (the following showsvertico
with theconsult-completing-read-multiple
interface):Selecting multiple file types, a note and a file:
Todo:
- Somehow set proper category metadata for links incitar-select-resources
. I'm actually not sure if this is possible.- Note that prior to this PR,
citar-open
did not add any metadata to candidates, soembark-act
'ing on a file candidate did not make embark file functions available. Now embark file functions are available, but on both files and links. Neither case seems optimal, if it's not possible (or easy) to set category metadata by group.Question:
- Does this work as expected withembark-act-all
? I've not used that enough to properly test it.