From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: org-src--contents-for-write-back : preserve original major-mode, and avoid mixing tabs and spaces in org-mode buffers Date: Sat, 22 Apr 2017 10:41:33 +0200 Message-ID: <877f2cvnpe.fsf@nicolasgoaziou.fr> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1qbv-0005xK-7T for emacs-orgmode@gnu.org; Sat, 22 Apr 2017 04:41:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1qbo-0005vY-Qa for emacs-orgmode@gnu.org; Sat, 22 Apr 2017 04:41:43 -0400 Received: from relay7-d.mail.gandi.net ([2001:4b98:c:538::200]:38378) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1qbo-0005vI-KK for emacs-orgmode@gnu.org; Sat, 22 Apr 2017 04:41:36 -0400 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by relay7-d.mail.gandi.net (Postfix) with ESMTPS id 2D204D28 for ; Sat, 22 Apr 2017 10:41:35 +0200 (CEST) In-Reply-To: (Brent Goodrick's message of "Sun, 2 Apr 2017 21:15:46 -0700") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Brent Goodrick Cc: emacs-orgmode@gnu.org Hello, Brent Goodrick writes: > I found a bug in org-mode where emacs-lisp code that is in a > already-indented source block in an org-mode buffer is improperly > indented when editing it via C-c '. Take the following contrived > example emacs-lisp source code: > > 1. Here is a list item with a emacs-lisp source block: > > #+BEGIN_SRC emacs-lisp :results value > (let ((uuid "c2327c73-6da3-4421-8bda-194783a00e8f")) > (progn > (let ((xxx 'yyy)) > (let ((xxx 'yyy)) > (while t > (message "infinite loop")))))) > #+END_SRC > > > After C-c ', indenting it, and C-c ' again, it renders as > follows (tabs converted to spaces for this email, since I have > `indent-tabs-mode' set to t in my emacs-lisp mode, which > is the Emacs default): > > 1. Here is a list item with a emacs-lisp source block: > > #+BEGIN_SRC emacs-lisp :results value > (let ((uuid "c2327c73-6da3-4421-8bda-194783a00e8f")) > (progn > (let ((xxx 'yyy)) > (let ((xxx 'yyy)) > (while t > (message "infinite loop")))))) > #+END_SRC > > Notice how the indentation looks bad due to the mixture of tabs > and spaces. Indeed. Thank you. > The bug is in the `org-src--contents-for-write-back' function. It > uses a temp buffer. The temp buffer's major-mode is left to be > the default, which is fundamental-mode, which knows nothing about > how to indent lisp code properly. And it doesn't need to. This function doesn't care about the code, but indents it rigidly according to original source block. IOW, I don't think changing the major mode is required. > So in the fix below, I run the major-mode function from the original > buffer. But even with that fix, the indentation must also use spaces > in order to avoid mixing tabs and spaces in the resulting Org buffer. Why do you think it is a good thing that tabs and spaces shouldn't be mixed. For example, imagine that the source code requires `indent-tabs-mode' being non-nil, but Org source buffer indentation is space only, i.e., with `indent-tabs-mode' being nil. Shouldn't the resulting block be indented with spaces from column 0 to block boundaries' indentation, and then follow with space indentation? WDYT? Regards, -- Nicolas Goaziou