lassik / emacs-format-all-the-code

Auto-format source code in many languages with one command
https://melpa.org/#/format-all
MIT License
611 stars 106 forks source link

Is it acceptable to add new formatter for emacs-lisp, which is emacs package itself? (elisp-autofmt) #235

Open ed9w2in6 opened 1 year ago

ed9w2in6 commented 1 year ago

I have added this formatter in my own config:

(define-format-all-formatter
 elisp-autofmt
 (:executable)
 (:install "M-x package-install elisp-autofmt")
 (:languages "Emacs Lisp")
 (:features region)
 (:format
  (format-all--buffer-native
   'elisp-autofmt-mode
   (if region
       (lambda () (elisp-autofmt-region (car region) (cdr region)))
     (lambda () (elisp-autofmt-region (point-min) (point-max)))))))

I have been using this for a while, which works pretty well, and IMHO much better than the default one (Emacs).

May I ask if this is acceptable for this package to add a formatter that depends on another emacs package? And what do you expect in a pull request?

lassik commented 1 year ago

May I ask if this is acceptable for this package to add a formatter that depends on another emacs package?

Yes, absolutely. The following already supported formatters are Emacs-native:

Of these, at least ledger-mode is a third-party package that does not ship with Emacs.

For native formatters, the main thing is to use (funcall 'elisp-autofmt-region ...) instead of (elisp-autofmt-region ...). The later form assumes that the function is defined, which it won't be if the package is not installed.

We don't currently have a standard way to check whether or not a native package has been installed. I can add that at some point. For now, your code above is fine. Just do the funcall thing.