emacs 23 python.el auto-indent style -- can this be configured? -
i have been using emacs 23 (python.el) on month , i'm unhappy default auto-indentation settings.
currently, python files auto-indented follows:
x = a_function_with_dict_parameter({ 'test' : 'here value', 'second' : 'another value', }) a_function_with_multiline_parameters(on='first', line='line', now_on='second', next_line='line', next='third', finally='line')
i prefer if set auto-indentation settings same code formatted:
x = a_function_with_dict_parameter({ 'test' : 'here value', 'second' : 'another value', }) a_function_with_multiline_parameters(on='first', line='line', now_on='second', next_line='line', next='third', finally='line')
it seems logic how i'd auto-indentation perform be:
if last character (non-comment/whitespace) of previous line :, increase indent-level 1. else, use same indentation level.
but using logic, tab
need increase indent-level of current line. (currently, tab
moves line auto-indent level)
does know how can modify emacs auto-indentation achieve desired style?
you can try peace of code :
(require 'python) ; indentation (defadvice python-calculate-indentation (around outdent-closing-brackets) "handle lines beginning closing bracket , indent them line line containing 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)
now, simple python dict :
a = {'foo': 'bar', 'foobar': 'barfoo' }
becomes...
a = {'foo': 'bar', 'foobar': 'barfoo' }
Comments
Post a Comment