Subject: Re: bug#78097: 30.1; editorconfig can pass nil to file-name-directory

From: Stefan Monnier <[email-masked]>
Date: Mon, 05 May 2025 09:55:56 -0400

>> FWIW, the fact that `editorconfig-get-local-variables-functions' is run
>> when there are no `.editorconfig` files is an accident.
> The reason I was using `editorconfig-get-local-variables-functions' is
> because both `editorconfig-after-apply-functions' and
> `editorconfig-hack-properties-functions' are documented to behave that
> way but are deprecated and `editorconfig-hack-properties-functions'
> reports that `editorconfig-get-local-variables-functions' should be used
> instead.
> If none of these hooks are available for this purpose can you recommend
> a way that I can achieve my goal?

I'm afraid I don't have a ready answer for it.
Maybe something like:

    (add-hook 'change-major-mode-after-body-hook #'my-global-file-defaults)
    (defun my-global-file-defaults ()
      (when buffer-file-name
        (add-hook 'before-save-hook
                  #'editorconfig--delete-trailing-whitespace nil t)))

Obviously, Emacs lacks an official "delete-trailing-whitespace mode":
the above should not have to rely on an editorconfig-specific function.
🙁

> No.  I was starting to suspect that it wasn't working and after seeing
> your patch I now know it's most definitely not working!  I was so deep
> in the weeds trying to fix the "stringp nil" issue that I never went
> back to see if my fix actually worked.  Sorry about that.

We've all been there.  🙂
Thanks for confirming my suspicion.

        Stefan