我正在使用 emacs 23 附带的 python 模式。我想自定义多行语句的自动缩进。例如目前 emacs 更喜欢以下内容
my_var = [
'val1',
'val2',
'val3',
]
我更愿意
my_var = [
'val1',
'val2',
'val3',
]
此外,当创建带有尾随列表或字典的函数时,emacs 更喜欢
my_func('first_arg', 'another_arg', {
'key1': val1,
'key2': val2,
})
我想看看
my_func('first_arg', 'another_arg', {
'key1': val1,
'key2': val2,
})
是否可以在 emacs 中为 python 模式创建这些自定义项?我找不到任何创建这些自定义项的文档。
最佳答案
也许是这样的?
(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)
参见 this similar question讨论此答案中使用的一些 Emacs 功能。
关于python - 在emacs python-mode中自定义多行语句缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4293074/