Python 缩进问题

这里按backspace键,就跑到上一行的结尾处了,咋办,

而我想要的是按backspace变成这样的

1 个赞

关掉 hungry-delete? (大概是这个名字

我试过了,不是这个的问题,

默认(emacs -Q)就是你想要的结果,因此你需要自己排查你自己的配置。

我刚刚删除了个插件,但是出现了新的问题,还是缩进问题,以前遇到过,实在不知道怎么解决, 这个问题,不是插件的问题,我把.emacs.d这个文件删了,就是最原始的情况 看楼下问题

这光标在这里

按enter跳到下一行,就变成了这样.

而我想到的是这样,就和pycharm一样的效果

咋办??:joy::joy:

根据 C-h k RET,你可以按 C-jelectric-newline-and-maybe-indent)或者把 electric-indent-mode 关掉(默认是开着的)。


RET (translated from <return>) runs the command newline (found in
global-map), which is an interactive compiled Lisp function in
`simple.el'.

It is bound to RET.

(newline &optional ARG INTERACTIVE)

Insert a newline, and move to left margin of the new line if it's blank.
If option `use-hard-newlines' is non-nil, the newline is marked with the
text-property `hard'.
With ARG, insert that many newlines.

If `electric-indent-mode' is enabled, this indents the final new line
that it adds, and reindents the preceding line.  To just insert
a newline, use M-x electric-indent-just-newline.

最新解决方式,群里大神给的

(defun python-return()
  (interactive)
  (if (= (point) (point-at-bol))
      (insert "\n")
    (newline)
    (indent-for-tab-command)))

(defun vmacs-python-mode-hook ()
  ;; (when (fboundp 'jedi:setup) (jedi:setup))
  (define-key python-mode-map  (kbd "RET") 'python-return))

(add-hook 'python-mode-hook 'vmacs-python-mode-hook)

完美.

你是不是开着 aggressive-indent-mode 了? 可以用 describe-mode 命令查看。如果是的话,关掉就行了,没必要另外再写函数

如果是 spacemacs 的话,可以用 SPC t I 打开或关闭。

emacs 本身就这样,看楼上的解决方案:grinning: