我使用的是emacs 23附带的python模式。我想定制多行语句的自动缩进。例如,目前emacs更喜欢以下内容
my_var = [
'val1',
'val2',
'val3',
]
我更喜欢
my_var = [
'val1',
'val2',
'val3',
]
此外,在创建带有尾随列表或dict的函数时,emacs首选
my_func('first_arg', 'another_arg', {
'key1': val1,
'key2': val2,
})
我想看看
my_func('first_arg', 'another_arg', {
'key1': val1,
'key2': val2,
})
是否可以在emacs中创建这些对python模式的自定义?我找不到任何创建这些定制的文档。
发布于 2010-12-03 03:56:59
也许是这样的吧?
(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)
有关此答案中使用的一些Emacs特性的讨论,请参阅this similar question。
发布于 2010-12-02 23:19:57
您需要在py-indent-line函数中查看python-mode.el。
https://stackoverflow.com/questions/4293074
复制相似问题