From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Steinar Bang Newsgroups: gmane.emacs.help Subject: Re: Need assistance in figuring out what reformats my code on save Date: Mon, 06 Sep 2021 16:26:25 +0200 Message-ID: <86bl55lqzy.fsf@dod.no> References: <86wnnvl1kz.fsf@dod.no> <87k0juc0y7.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37284"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (windows-nt) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 06 16:27:18 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mNFaf-0009XC-VU for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 06 Sep 2021 16:27:17 +0200 Original-Received: from localhost ([::1]:36512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNFaf-0002gK-0e for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 06 Sep 2021 10:27:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNFa8-0002fy-Uz for help-gnu-emacs@gnu.org; Mon, 06 Sep 2021 10:26:44 -0400 Original-Received: from cadalora.default.sbang.uk0.bigv.io ([46.43.15.90]:41068) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNFa5-0004Ub-5K for help-gnu-emacs@gnu.org; Mon, 06 Sep 2021 10:26:43 -0400 Original-Received: from mccoy (unknown [84.210.87.211]) by cadalora.default.sbang.uk0.bigv.io (Postfix) with ESMTPSA id 968A2CD3B6 for ; Mon, 6 Sep 2021 15:26:24 +0100 (BST) In-Reply-To: <87k0juc0y7.fsf@gnu.org> (Tassilo Horn's message of "Sun, 05 Sep 2021 20:43:43 +0200") Received-SPF: none client-ip=46.43.15.90; envelope-from=sb@dod.no; helo=cadalora.default.sbang.uk0.bigv.io X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:132924 Archived-At: >>>>> Tassilo Horn : > I'd try evaluating > (add-hook 'before-change-functions #'debug nil t) > in a buffer where that formatting before save happens and then save. > That should put you in the debugger and the backtrace will hopefully > show you who and from where the formatting is triggered. Thanks! That worked! I did `M-: (add-hook 'before-change-functions #'debug nil t) RET` in a .tsx buffer in a restarted emacs with nil before-save-hook and I found that the reformatting is done by web-mode-on-post-command and is run immediately after my change, and not just before save. web-mode-on-post-command is run from the post-command-hook, and runs indent-region on the buffer when the command is a yank https://github.com/fxbois/web-mode/blob/master/web-mode.el#L2918 The formatting done by tide-format-before-save is different from the formatting done by indent-region in web-mode-on-post-command, and with tide-format-before-save in place, it's the tide-format-before-save formatting that wins. (In case someone finds this when googling: making tsfmt, or making web-mode, format exactly like prettier, both seemed like too much work. So I removed tide formatting from web-mode and used "prettier-js for emacs" instead. See https://github.com/ananthakumaran/tide/discussions/434#discussioncomment-1285992 for details)