Skip to content
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

Closed
mcandre opened this issue Mar 17, 2016 · 7 comments
Closed

Apply editorconfig settings to shebang'ed files sans extensions #75

mcandre opened this issue Mar 17, 2016 · 7 comments

Comments

@mcandre
Copy link

mcandre commented Mar 17, 2016

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).

@10sr
Copy link
Member

10sr commented Mar 19, 2016

Thanks!
IMO we should discuss this in editorconfig/editorconfig issue tracker instead of here 😃

@xuhdev
Copy link
Member

xuhdev commented Mar 23, 2016

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.

@xuhdev
Copy link
Member

xuhdev commented Nov 8, 2016

Does custom hook solve your problem?

@10sr
Copy link
Member

10sr commented Nov 11, 2016

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 [{*.bash*}], for this case, from custom hook...
I think we have to hack core libraries to get indent_size = 4 for #!/bin/bash files.

@hlissner
Copy link
Contributor

hlissner commented Dec 8, 2017

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)

@cxw42
Copy link
Member

cxw42 commented Sep 28, 2019

See ongoing discussion in editorconfig/editorconfig#404

@10sr
Copy link
Member

10sr commented Oct 23, 2019

Closing this, please proceed discussion in ☝️

@10sr 10sr closed this as completed Oct 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants