-
Notifications
You must be signed in to change notification settings - Fork 107
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
Apply editorconfig settings to shebang'ed files sans extensions #75
Comments
Thanks! |
Would a custom hook help here? I like the suggestion but I doubt whether it's easy to add it to the whole EditorConfig framework. But for Emacs, one should be able to write a custom hook for this. |
Does custom hook solve your problem? |
Unn... I dont think custom hook works for this case. A custom hook works after an editorconfig-core library is called, so there is no way to access properties under |
If it's any help to other Emacs users, I've used the following for the past couple of months with no issue: Expand code ;; editorconfig cannot procure the correct settings for extension-less files.
;; Executable scripts with a shebang line, for example. So why not use Emacs'
;; major mode to drop editorconfig a hint? We temporarily append an extension
;; to `buffer-file-name' when talking to editorconfig.
(defvar doom-editorconfig-mode-alist
'((sh-mode . "sh")
(python-mode . "py")
(ruby-mode . "rb")
(perl-mode . "pl")
(php-mode . "php")))
(defun doom*editorconfig-smart-detection (orig-fn)
"Retrieve the properties for the current file. If it doesn't have an
extension, try to guess one."
(let ((buffer-file-name
(if (and (not (bound-and-true-p org-src-mode))
(file-name-extension buffer-file-name))
buffer-file-name
(format "%s%s" buffer-file-name
(if-let* ((ext (cdr (assq major-mode +editorconfig-mode-alist))))
(concat "." ext)
"")))))
(funcall orig-fn)))
(advice-add #'editorconfig-call-editorconfig-exec :around #'doom*editorconfig-guess-extension) |
See ongoing discussion in editorconfig/editorconfig#404 |
Closing this, please proceed discussion in ☝️ |
Please apply editorconfig settings such as
[{*.bash*}] indent_size = 4
to buffers that have an interpreter mode (shebang like#!/bin/bash
), but no file extension (post-merge-checkout-hook
).The text was updated successfully, but these errors were encountered: