6

Org–Babelを使用して読み書きのできる Python を作成する場合、インデント レベルを制御できる必要があります (明示的:indentation-level 3または巧妙な指示による暗黙のいずれか)。

問題を示すサンプル ファイルを次に示します。

#+BEGIN_SRC python :tangle "sample.py"
  class Test:
      def __init__(self):
          self.a = 'a test class'
#+END_SRC
#+BEGIN_SRC python :tangle "sample.py"
      def say_hi(self):
          print 'Hi from this Test object!'
          print 'ID: {}'.format(repr(self))
          print 'Data: {}'.format(str(self.__dict__))
#+END_SRC
4

3 に答える 3

9

に設定org-src-preserve-indentationtます。

于 2014-01-03T11:50:12.540 に答える
0

望ましい解決策ではないことは承知していますが、回避策として、ソース ブロックにコメント (プログラミング言語に固有) を挿入し、そのコメントの後に目的のインデントを作成できます。これにより、終了時にインデントも保持されますedit-buffer

#+BEGIN_SRC python :tangle "sample.py"
  class Test:
      def __init__(self):
          self.a = 'a test class'
#+END_SRC
#+BEGIN_SRC python :tangle "sample.py"
  # This is my dummy python comment to keep the correct indentation 
      def say_hi(self):
          print 'Hi from this Test object!'
          print 'ID: {}'.format(repr(self))
          print 'Data: {}'.format(str(self.__dict__))
#+END_SRC
于 2016-06-28T14:55:56.210 に答える