From mboxrd@z Thu Jan 1 00:00:00 1970 From: Derek Feichtinger Subject: src block indentation causing problems due to tab/space mixing - proposed fix Date: Fri, 27 Jul 2018 15:22:23 +0200 Message-ID: <87zhycu834.fsf@psi.ch> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50834) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fj33X-000133-78 for emacs-orgmode@gnu.org; Fri, 27 Jul 2018 09:45:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fj33S-0003km-7V for emacs-orgmode@gnu.org; Fri, 27 Jul 2018 09:45:19 -0400 Received: from edge20.ethz.ch ([82.130.99.26]:33641) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fj33R-0003hj-Sq for emacs-orgmode@gnu.org; Fri, 27 Jul 2018 09:45:14 -0400 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: emacs-orgmode@gnu.org Dear Org developers I think that the current way of indenting source blocks (with org-src-preserve-indentation is set to nil) is not ideal in regard to languages that dislike mixing of tabs and spaces. I'm currently switching to python3 and this forbids the mixing. Setting org-src-preserve-indentation to t would basically create problems with many of my older files, and I also dislike the reduced readability resulting from the code block contents being aligned at column 0. I just checked out the org mode master f79545f and made sure that the relevant lines match my current active version of org-plus-contrib-20180709. Looking at the code: org-edit-src-exit calls org-src--contents-for-write-back for writing the contents of the source buffer. Inside of that function, all leading whitespace of each line is replaced using indent-to. This leads to mixing tabs and spaces and causes problems with python3. in org-src--contents-for-write-back: #+BEGIN_SRC elisp (when (> indentation-offset 0) (while (not (eobp)) (skip-chars-forward " \t") (unless (eolp) ;ignore blank lines (let ((i (current-column))) (delete-region (line-beginning-position) (point)) (indent-to (+ i indentation-offset)))) (forward-line))) #+END_SRC I tested this simple alternative which just uses indent-to to fill up the columns needed for the source blocks basic indentation offset, but which does not affect any leading whitespace from the code's buffer. #+BEGIN_SRC elisp (when (> indentation-offset 0) (while (not (eobp)) (unless (eolp) (indent-to indentation-offset)) (forward-line))) #+END_SRC This still allows org mode to use tabs for the block's basic indentation offset, so that the block is nicely aligned with the rest of the org buffer, but it prevents modification of the whitespace which is relevant to the block itself. I just tested it also with some tangled files, and it seems to work nicely for my test cases. Still, I may have overlooked something, and there is a deeper reason for the original implementation. Best regards, Derek -- Paul Scherrer Institut Dr. Derek Feichtinger Phone: +41 56 310 47 33 Section Head Science-IT Email: derek.feichtinger@psi.ch Building/Room No. WHGA/U126 CH-5232 Villigen PSI