-
Notifications
You must be signed in to change notification settings - Fork 75
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
Using an expression to generate command #156
Comments
I think you would use something like this: (setf (alist-get 'black apheleia-formatters) '((get-command))) If the value is a symbol then Apheleia assumes it is a function that defines an Elisp-based formatter. You instead want a list to use a regular command formatter. If an element of the list is not a string then it is evaluated to get a string or list of strings. In this case the sole list element is the form You could also put the logic in an external shell script and add that to |
I get the following error when I do it:
Code I am using: (defun compro/black ()
(when-let* ((root (pet-virtualenv-root))
(executable (concat root "/bin/black"))
(exists (file-exists-p executable)))
executable))
(setf (alist-get 'black apheleia-formatters) '((compro/black))) |
Odd, I don't know why that error is even in there, although I added it. Fixed in the linked commit. |
Thanks, that worked. I am currently using: (defun compro/black ()
(when-let* ((root (pet-virtualenv-root))
(executable (concat root "/bin/black"))
(exists (file-exists-p executable)))
`(,executable "-")))
(setf (alist-get 'black apheleia-formatters) '((compro/black))) I am going to close this issue but I will ask for another small feature as its not fixed completely yet. I get the following error when black is not installed in the virtualenv:
Instead of showing an error, either fail silently or show a message stating that |
Hmmm. I'm not necessarily sure it would be correct to handle the function returning nil. After all, the interface here is that you have |
Thanks! That does solve the problem. But don't you think using If this is okay then documenting it as an option would be a plus. |
I think it's reasonable to request a way that a dynamically generated formatter command could signal that no command is to be run. One reasonable way to implement that might be to have a special symbol Let's track that feature, if desired, in a separate issue. |
When I do
it works. But I have different projects where I don't want to run black if its not installed in the virtualenv. So, I want to use a function to get the command dynamically per file and disable it where not available:
Here,
get-command
function will return the command based on virtualenv and nil when executable wasn't found there. What is the best way to accomplish this?The text was updated successfully, but these errors were encountered: