Hi,
I ran into an issue with company-mode's new icon support which seems to be caused by how straight builds packages. I did manage to fix it, but I'm not entirely sure it's the right way to fix it, so I was hoping I could get some support and find out whether it's correct or not. I reported this in company-mode's repo with the fix I found and was also made aware that someone else had already provided another fix.
In short, the issue is that company can't find the icon files it's looking for. They're located in an icons directory in the root directory of the package. When building the package, straight doesn't copy these files by default. The fix seems to be
(use-package company
:straight (company :files (:defaults "icons")))
So 2 questions:
straight-default-files-directive? Of course, I do not have enough context to know whether that is the right thing or not and there may well be better ways to handle it, but it strikes me as a potentially easy fix. Though, of course, it might be undesirable in other cases.Thanks for listening and helping me out!
Is this the right way to do it? If not, what's the recommended approach?
Yes, that looks correct to me.
Would it be worth considering adding "icons" to straight-default-files-directive?
I don't think this is the proper solution. It would make more sense for the MELPA recipe for company mode to be updated to include the "icons" directory, if possible.
See, for example, the MELPA recipe for lsp-java:
https://github.com/melpa/melpa/blob/74f79dc5db5246a2f70e4d4ad76601be8b5c79d8/recipes/lsp-java
Very good. Is straight not picking up the new recipe, then?
If you try M-x straight-pull-package melpa then M-x straight-get-recipe company, do you get the following recipe?:
(company :type git :flavor melpa :files (:defaults "icons" "company-pkg.el") :host github :repo "company-mode/company-mode")
Ah, yes, I do, at least.
(sorry: clicked send before I was done writing)
Nice; so it should work automatically from now on, as long as everything is updated?
I did the above on my system and it seems to build correctly.
Nice; so it should work automatically from now on, as long as everything is updated?
So long as the recipe isn't overridden in your init, then you should be good to go.
Ah, that's nice. I wasn't aware of that; thanks for explaining :pray:
I'll close this issue, then. It seems that as long as the user updates Melpa, things should work as expected. I'm not sure whether that could've been made any more obvious in any way or not. It's not like the readme isn't excellent already, and it's mentioned under updating recipe repositories, for instance. I just didn't realize that was an issue, but that might be related to my lack of experience with Melpa recipes etc.
Anyway, thanks for helping me out! I'll make sure this is outlined in the company mode thread I linked too.
We should arguably treat the recipe repository as a "dependency" of each package for which it provides a recipe, for the purposes of package upgrades. I.e., when you ask to upgrade Company, straight.el should say: "I see that we retrieved the recipe for Company from MELPA; therefore, when upgrading Company, we should first upgrade MELPA, to make sure that we have the latest recipe for Company to go along with the latest version of Company itself". See also #323, and the function M-x straight-pull-package-and-deps (which should probably be the default behavior of M-x straight-pull-package, with an option to override).
If I understand correctly, does that mean that straight-pull-package-and-deps should _ideally_ pull the recipe repos and use the updated recipes to build packages, but it doesn't at the moment? Anyway, I agree that checking for updated recipes and then using the updated recipe would make the most sense as an end user :smile: 馃憤馃従
Also, if you don't mind helping me out a bit: what's the 'right' way of updating and rebuilding (and re-evaluating) a package with Straight?
I tried pulling package and deps for Company on a different machine, and while the recipe said that it included icons, the build directory did not contain the icons directory. After pulling the package, I also tried straight-check-package. I managed to somehow make it build in the end by opening a new instance of Emacs, but I'm not exactly sure what I did or why I had to do that. I thought straight was supposed to rebuild a package if the recipe changed and expected that to also add the icons directory. Is that not correct or did I do something wrong?
If I understand correctly, does that mean that
straight-pull-package-and-depsshould ideally pull the recipe repos and use the updated recipes to build packages, but it doesn't at the moment?
Yes, that's exactly right.
what's the 'right' way of updating and rebuilding (and re-evaluating) a package with Straight?
You run M-x straight-pull-package-and-deps to update the repository itself. Then, restarting Emacs should automatically cause straight.el to rebuild the package at next init, and you'll be running the new code. Alternatively, you can reload your init-file manually, which should also trigger a rebuild. Or, you can manually invoke M-x straight-rebuild-package. The advantage of restarting Emacs is that you'll actually load the new code: by default, Emacs won't load an Elisp file twice, even if the contents have changed. But you can always navigate to the file manually with M-x find-library and then run M-x eval-buffer if you really want to update package code in place without restarting Emacs.
After pulling the package, I also tried
straight-check-package. I managed to somehow make it build in the end by opening a new instance of Emacs
Running M-x straight-check-package should have been sufficient, but you may have encountered a bug in the modification detection system (perhaps #291, for example). In such cases you can manually force a rebuild with M-x straight-rebuild-package.
straight was supposed to rebuild a package if the recipe changed and expected that to also add the icons directory
Yes, that all sounds correct. Recipe changes should always force a rebuild, and the latest version of recipe from disk should always be used, except in the case of a bug.
Ah, but there is an addendum. If the recipe has changed, you need to follow an additional step: explicitly M-x straight-pull-package on the recipe repository (melpa in this case), before restarting Emacs so that the new recipe is in memory when straight.el rebuilds the package.
If you just pulled MELPA and then ran M-x straight-check-package, then straight.el would not have read the recipe from disk again though it was updated.
Got it! Thanks for the thorough explanation :pray: I'll try and remember this the next time I run into a similar situation.
Most helpful comment
We should arguably treat the recipe repository as a "dependency" of each package for which it provides a recipe, for the purposes of package upgrades. I.e., when you ask to upgrade Company,
straight.elshould say: "I see that we retrieved the recipe for Company from MELPA; therefore, when upgrading Company, we should first upgrade MELPA, to make sure that we have the latest recipe for Company to go along with the latest version of Company itself". See also #323, and the functionM-x straight-pull-package-and-deps(which should probably be the default behavior ofM-x straight-pull-package, with an option to override).