From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: newline-and-indent vs. electric-indent-mode Date: Fri, 22 Jan 2021 17:05:41 -0500 Message-ID: References: <87wnw5yt58.fsf@hajtower> <87o8hgzrzi.fsf@hajtower> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40714"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Emacs Developer List To: haj@posteo.de (Harald =?windows-1252?Q?J=F6rg?=) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Jan 22 23:06:51 2021 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 1l34Zu-000AUt-W3 for ged-emacs-devel@m.gmane-mx.org; Fri, 22 Jan 2021 23:06:51 +0100 Original-Received: from localhost ([::1]:60878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l34Zt-0001XW-WB for ged-emacs-devel@m.gmane-mx.org; Fri, 22 Jan 2021 17:06:50 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l34Yu-00011Y-8V for emacs-devel@gnu.org; Fri, 22 Jan 2021 17:05:48 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:5851) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l34Yr-0003Gu-EY for emacs-devel@gnu.org; Fri, 22 Jan 2021 17:05:47 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 4FD6C80DFB; Fri, 22 Jan 2021 17:05:44 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 72F6B8070D; Fri, 22 Jan 2021 17:05:42 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1611353142; bh=r3vk6yCbTbIxU1jYoi9wf2ZDlQVWsjZTBUtjmjudiHM=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=FFP51d50ZP6ir41/WOOxxqRzn6AgSuD4O5+DAqeas4tCX09WmaJEZa+wPLfhcoYHW GtpS+mfOZLy28ASF51ptnm0ctxT+Ug0D+1C1G3aCPm6kvdeffY9yDlE3uqolouYbq4 XdseiarYUsOVQX38jcIb6z3umoKvly5otRa6UKLht4EScI9P6kiR/CGoV/Mb9qLKcP jsOo/QAt3nNpbUyT4vyJLOWDrxFwDiwUuqNRazLioLJrIsf27mQwoK3q2+YIr0dYli kYzrbcfUb8aB09LgJP+ESL+2PRr1ZM0Hxco6QCTBOsHogLOU69NkItcM97qfrVnJh5 M5X+K4LJ9rOfg== Original-Received: from alfajor (65-110-220-188.cpe.pppoe.ca [65.110.220.188]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 4A4131201F1; Fri, 22 Jan 2021 17:05:42 -0500 (EST) In-Reply-To: <87o8hgzrzi.fsf@hajtower> ("Harald =?windows-1252?Q?J=F6rg=22?= =?windows-1252?Q?'s?= message of "Fri, 22 Jan 2021 20:33:37 +0100") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.io gmane.emacs.devel:263285 Archived-At: >>> Many (almost all?) modes bind RET to newline-and-indent, >> Any mode which does that should be fixed. > Ouch... I see now that my "observation" was plain wrong. Yes and now: historically, it's been quite common for major modes to do that kind of thing. I've been fighting it for many years now (even long before `electric-indent-mode`) since it's usually the reflection of the major mode's author's preference, rather than something directly linked to the major mode (there are several other examples of this behavior: setting `comment-column` in the major mode is another similar example). >> Whether RET indents or not is a user preference, not something that >> should depend on the kind of language you're editing. > For most programming and markup languages indenting makes sense, but > less so for other modes. Concrete examples would be helpful and could be reported as bugs (I have made efforts to setup `electric-indent-mode` such that it tries not to get in the way in "plain text" modes, but of course that's no guarantee that it catches all relevant cases). > I guess it wouldn't hurt to add a sentence to the docstring of > electric-indent-mode how it should be managed for a single buffer. The > method with an extra variable (electric-indent-inhibit, works only to > disable a globally enabled mode) or an extra mode > (electric-indent-local-mode, works both ways) is somewhat nonstandard > and the question seems to pop up occasionally on various platforms. `electric-indent-inhibit` doesn't inhibit auto-indentation. It inhibits auto-*re*indentation. I know it takes many people by surprise (because the choices are more refined than just "on or off" and they don't expect that), but I find it hard to improve the docs to guide the users/programmers. >> It sounds like a bug indeed. I think both having two calls (one for >> each line) or having one call (for the new line) could arguably be >> correct, but three calls is indeed an error. > So... I guess newline-and-indent could suppress the call to > indent-line-function for the new line if electric-indent-mode is t and > electric-indent-inhibit is nil and ?\n is in electric-indent-chars? That would be one way, tho I find it fairly ugly. Another might be to temporarily disable `electric-indent-mode`. The more I think about it, the more I think this is the better choice. > Just for the record: The results are correct, and the delay isn't > noticeable even with the convoluted indenting routines of CPerl mode. Usually indentation of a single line is very quick so doing twice is indeed lost in the noise. Of course, there are corner cases where indentation can take a non-negligible amount of time, in which case doubling it can be noticed (but still isn't a main worry: even if it increases the runtime from 30s to 1min it's not that significant since 30s is really not all that much better than 1min). Still counts as a performance bug to me. > It is just a bit annoying when you are tracing through the routines > trying to figure out where to fix a bug. I suspect that there are cases where it really does introduce bugs beyond a (minor) performance impact, e.g. in some of the major modes where repeated TABs cycle between different indentation points. In any case, I pushed a change to `master` to disable `electric-indent-mode` in `newline-and-indent`, so this should hopefully be fixed now. > In CPerl mode, the remaining issue is actually the other way around. > You can activate cperl-electric-linefeed via customize to do > newline-and-indent. More or less. `cperl-mode` intends to offer basically 3 different options: plain newline, newline+indent, and newline+indent+fancystuff. And these are bound be default resp. to RET, LFD, and C-c LFD. Then `cperl-electric-linefeed` lets you swap the last two. Of course, with `electric-indent-mode` RET ends up doing (more or less) what LFD does. IMO keybindings is more harmful than anything here, so a better choice would be to offer only plain newline and newline+indent+fancystuff, bind them to RET and LFD, let `electric-indent-mode` control which of RET and LFD does which, and let `cperl-electric-linefeed` control whether fancystuff is done at all. Stefan