2011-02-23 2 views
13

필자는 emacs 23 (python.el)을 한 달 넘게 사용하여 기본 자동 들여 쓰기 설정에 만족하지 않습니다.emacs 23 python.el 자동 들여 쓰기 스타일 - 이것을 구성 할 수 있습니까?

다음과 같이 현재 내 파이썬 파일은 자동 들여 쓰기 : 나는 자동 들여 쓰기 설정을 할 수 있다면 동일한 코드는 쉽게 포맷 할 수 있도록

x = a_function_with_dict_parameter({ 
            'test' : 'Here is a value', 
            'second' : 'Another value', 
            }) 
a_function_with_multiline_parameters(on='First', line='Line', 
            now_on='Second', next_line='Line', 
            next='Third', finally='Line') 

내가 선호하는 것 :

x = a_function_with_dict_parameter({ 
    'test' : 'Here is a value', 
    'second' : 'Another value', 
}) 
a_function_with_multiline_parameters(on='First', line='Line', 
    now_on='Second', next_line='Line', next='Third', finally='Line') 

자동 들여 쓰기를 수행하는 방법에 대한 논리는 다음과 같습니다.

이전 줄의 마지막 문자 (주석/공백이 아닌)가 :이면 들여 쓰기 레벨을 1 씩 변경하십시오. 그렇지 않으면 동일한 들여 쓰기 레벨을 사용하십시오.

그러나 논리를 사용하면 TAB은 실제로 현재 줄의 들여 쓰기 수준을 높여야합니다. (현재, TAB 만 자동 들여 쓰기 수준으로 이동합니다)

원하는 스타일을 얻기 위해 이맥스 자동 들여 쓰기를 어떻게 수정할 수 있습니까?

답변

1

마지막 fgallina의 python.el 버전을 사용해보십시오. 그것은 많은 다른 improvements을 포함합니다.

이 버전을 사용하고 TAB에는 원하는 동작이 있지만 python.el을 여러 번 수정하여 동일한 동작을 얻게 될지 확신 할 수 없습니다. 그렇다면 알려주세요. 이 같은 지금

(require 'python) 

; indentation 
(defadvice python-calculate-indentation (around outdent-closing-brackets) 
    "Handle lines beginning with a closing bracket and indent them so that 
    they line up with the line containing the corresponding opening bracket." 
(save-excursion 
    (beginning-of-line) 
    (let ((syntax (syntax-ppss))) 
    (if (and (not (eq 'string (syntax-ppss-context syntax))) 
      (python-continuation-line-p) 
      (cadr syntax) 
      (skip-syntax-forward "-") 
      (looking-at "\\s)")) 
     (progn 
      (forward-char 1) 
      (ignore-errors (backward-sexp)) 
      (setq ad-return-value (current-indentation))) 
     ad-do-it)))) 

(ad-activate 'python-calculate-indentation) 

, 간단한 파이썬 딕셔너리 : 당신은 코드의 평화를 시도 할 수 있습니다

+0

불행히도 이것은 내가 묘사 한 것처럼 작동하지 않습니다. 자동 들여 쓰기가 끝나면 "TAB"을 계속 누르면 라인이 음수 (여백쪽으로) 들여 쓰기 레벨을 스크롤합니다. 또한 들여 쓰기 수준을 수동으로 조작하면 후속 줄이 같은 수준에 머 무르지 않습니다. 좋은 소식은 python.el 소스를 검토하고 어떻게 작동하는지 파악하고 잠재적으로 직접 수정하는 방법을 알아낼 수 있는지 확인하는 것입니다. – brildum

-1

MX 사용자 그룹 RET 파이썬 RET

a = {'foo': 'bar', 
    'foobar': 'barfoo' 
    } 

이된다 .. .

a = {'foo': 'bar', 
    'foobar': 'barfoo' 
} 
3

+0

이 질문에 emacs 24 업데이트가있을 수 있습니까? 함수'python-calculate-indentation'은 더 이상 존재하지 않습니다. 가장 가까운 대체물은'python-indent-calculate-indentation'처럼 보이지만이 함수의 작동 방식은 변경된 것 같습니다. – barik

관련 문제