0

I'm currently facing an issue where I am trying to save a file, but some save hook is triggering an auto formatting the file in a way that I do not want. I am not sure how to debug this issue. Ideally, I would be able to see all the events being executed when the save-hook is triggered.

Specifically, I want to edit a config file that looks something like this

#
# my_config
#
SOMETHING=foo

When I save this file, emacs autoformats the document and adds a space before and after =. I do not want this behavior and I am trying to figure out why on earth it's happening.

example gif of this issue: enter image description here

I am opening the buffer in text-mode. These are the minor mode emacs reports are enabled:

Enabled minor modes: Auto-Composition Auto-Compression Auto-Encryption
Auto-Insert Blink-Cursor Column-Number Company Dap Dap-Auto-Configure
Dap-Tooltip Dap-Ui Dap-Ui-Controls Dap-Ui-Many-Windows Electric-Indent
File-Name-Shadow Flx-Ido Flycheck Flyspell Font-Lock Global-Auto-Revert
Global-Company Global-Eldoc Global-Flycheck Global-Font-Lock Global-Git-Commit
Ido-Everywhere Ido-Vertical Line-Number Lsp-Treemacs-Sync Magit-Auto-Revert
Mouse-Wheel Projectile Recentf Save-Place Savehist Shell-Dirtrack Show-Paren
Tooltip Transient-Mark Treemacs-Filewatch Treemacs-Follow
Treemacs-Fringe-Indicator Treemacs-Git Visual-Line Which-Key Yas Yas-Global

I am at a loss as to how I can debug this issue. Is there a clever way to see what emacs is doing when the save-hook is triggered?

2
  • Please show your relevant code. Do you see the same problem if you start Emacs with emacs -Q (no init file)? If not, bisect your init file to find the culprit.
    – Drew
    Sep 28 at 22:17
  • What save-hook are you referring to? Some variable? (Defined where?)
    – Drew
    Sep 28 at 22:18
1

The main save hooks are before-save-hook and after-save-hook. You can see the current value of these via e.g. C-h v before-save-hook. You may see something useful in the resulting output that you can search for in your config. You may also find your problem by search through your configuration for the names of the hooks themselves.

Beyond that, you may need to bisect your config to narrow down the source of the problem, as described in this question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.