Closed haze closed 1 month ago
Could you explain more what you're trying to achieve? Apheleia already has support for Prettier formatting.
Aphelia's integration works by executing prettier on the CLI. I'd instead like to use the long lived process prettier.el spins up to format the buffer instead of shelling out to the CLI.
OK, but why do you want to integrate the two, can't you just use prettier.el for some buffers and Apheleia for others?
I could. I'm finding less and less reason to. I think I want apheleia to be the driver (so I can keep the global mode on, since it works with way more kinds of buffers.) I don't mind keeping them separate. I wonder if using with-current-buffer
as the scratch provided buffer from apheleia
would work without any modifications to prettier.el...
Ah, I see now what you're aiming for. I think this is more a question for the Apheleia guys then, i.e. how do you hook into their save process to do something other than invoking an external command? From there you should get pretty far with prettier-prettify
as long as you copy major-mode from the main buffer.
I tried hooking the two together, but I can't seem to get prettier-prettify
to work with a buffer that isn't saved to disk.
Here's my integration
(cl-defun haze--apheleia-prettier-el-wrapper (&key buffer scratch callback &allow-other-keys)
"Wrapper function for Apheleia that uses prettier.el underneath.
Use prettier.el to format BUFFER.
Calls CALLBACK once completed."
(with-current-buffer scratch
(funcall (with-current-buffer buffer major-mode)) ; copy major-mode from buffer to scratch
(setq-local exec-path (with-current-buffer buffer exec-path)) ; copy exec-path to find prettier
(set-visited-file-name (with-current-buffer buffer buffer-file-name) t) ; copy file path so we don't try and find a global prettier
(goto-char (point-min))
(prettier-prettify)
(set-visited-file-name nil)
(funcall callback)))
Amazing, glad you got it working, and thanks for sharing it here!
For the record, the integration posted above has hiccups when the buffer has errors in it, but I haven't had the time to make it resilient
Is your feature request related to a problem? Please describe. I'd like to use
apheleia
with prettier.el. is that possible?Describe the solution you'd like The ability to supply a
prettier.el
function to apheleia that formats the buffer.Describe alternatives you've considered For the time being I've disabled apheleia in the buffers that matter, but it would be nice if I could integrate the two.
Additional context I tried modifying
prettier.el
to accept a buffer to write the changes to but I got distracted and didn't get very far. Is that a viable path forward?