[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC] Do indent-region only on editable buffers

From: Kaushal Modi
Subject: [RFC] Do indent-region only on editable buffers
Date: Mon, 07 Aug 2017 17:36:10 +0000

indent-region is an act of editing a buffer. So before attempting to do that, it should be checked if the buffer is editable.

Bug#22819[1] raises that point.

The proposal is to call (barf-if-buffer-read-only) before attempting to do the indent.

Motive for this change:

The act of indenting is an editing action. So the buffer should be checked if it's editable before attempting an indent. If the buffer is read-only and no indentation change is required, then good. But what if indentation change is required? Here's what's will happen: 1. User: Try indentation (C-x h M-x indent-region) 2. User: Could take several seconds or few minutes (depending on major mode and file size) 3. Emacs: "Bummer, couldn't save all that indentation because the buffer is read-only". 4. User: Make buffer editable. It's not a simple act of chmod. In my case, the buffer was read-only because the file is part of a centralized version control system (Cliosoft SOS). In "checked in" state, the file is just a symlink to the cached version in server, and thus read-only. To make it editable, I need to "check out" the file. That act replaces the symlink link with a physical file copy. 5. User: Re-do that several seconds/minutes long indentation.

So the motive is to save time and alert user of their pilot error before attempting to do an operation that would go to waste (in this case, doing indent, and then waste all those CPU cycles because the changes couldn't get saved to the file).

Question to the list:

- Are there any objections to doing the buffer read-only check before doing the indent?

(PS: If user's still want to do indentation on read-only buffers, then can always do C-x C-q (toggle read-only-mode) and then proceed to indent the buffer.)

[1]: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=22819

Kaushal Modi

reply via email to

[Prev in Thread] Current Thread [Next in Thread]