From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.devel Subject: How to run indent command in arbitrary buffer while respecting user settings? Date: Thu, 29 Jun 2023 19:44:44 +0000 Message-ID: <87352avys3.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18989"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Jun 29 21:45:57 2023 Return-path: Envelope-to: ged-emacs-devel@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 1qExaW-0004lQ-Hd for ged-emacs-devel@m.gmane-mx.org; Thu, 29 Jun 2023 21:45:56 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qExZV-0003W0-So; Thu, 29 Jun 2023 15:44:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qExZT-0003Vr-F2 for emacs-devel@gnu.org; Thu, 29 Jun 2023 15:44:51 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qExZP-0002GB-S7 for emacs-devel@gnu.org; Thu, 29 Jun 2023 15:44:51 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id D665324002B for ; Thu, 29 Jun 2023 21:44:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1688067885; bh=MU7FSXYPLbkKcsUiV1p8x5EYP7u+DUEtFonM9HBWMsg=; h=From:To:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=BytTnc0jQC+57bPQaYvrE4vJsQQONiJxG5le+zGqbygGXdLEg0QNOtwDYk1aEFEWq ujzC5KF6TCIdRH3KIGLT2oDQrX6rI63seJ+HzYZaaxJHiGrLTruoo8r3K6MCnL1Cjf eSP9DYj3h8X0nD33xY1xYc7OkBh4b5E/qMyAdVd24K+StkZsf8Ebbh4opYQI1jaAxf wouBRNP7Ayjrx+wlp3GM8I34chy65UQOQ92bFS45a/wt6b8h2CGcrEznPohtYZSjaK uzr0qLi2NpH5CYk7qn7MfNmsPpE4wYm4gvEbW2RUxpCXBVkHwP1433IbY9VKVm17tA CcSZJtvHJUO1A== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4QsTRx2Zrnz9rxM for ; Thu, 29 Jun 2023 21:44:45 +0200 (CEST) Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:307300 Archived-At: Hello, In Org mode, we sometimes have a need to use third-party major mode to do indentation: #+begin_src emacs-lisp (when t 'indent-me) #+end_src To do this, we currently create a major mode buffer containing the code and run whatever is bound to there. This, however, is broken when user re-binds to something else. Or when something like evil-mode re-binds (https://github.com/emacs-evil/evil/issues/1806) I am now considering running (funcall-interactively #'indent-for-tab-command) However, looking at 25 Indentation section of Elisp manual: The simplest way to perform indentation is the key. In most major modes, this runs the command =E2=80=98indent-for-tab-command=E2= =80=99. (In C and related modes, runs the command =E2=80=98c-indent-line-or-region= =E2=80=99, which behaves similarly, *note C Indent::). I noticed that C and related modes have some alternative setting for indentation. So, using `indent-for-tab-command' appear to be not as reliable, after all. Is there any reliable way to perform indentation in an arbitrary major mode programmatically? I notice that cc-mode.el has a comment that the current re-binding is at least debatable: (substitute-key-definition 'indent-for-tab-command ;; XXX Is this the right thing to do ;; here? 'c-indent-line-or-region c-mode-base-map global-map) So, should I simply ignore what cc-mode does and go ahead relying upon `indent-for-tab-command' doing the right thing? --=20 Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at