简体   繁体   English

Emacs为内联(行尾)注释设置间距

[英]Emacs set spacing for inline (end of line) comments

In the PEP 8 style guide for python, it is recommended that inline comments are separated by the rest of the line by two spaces . 在python的PEP 8样式指南中,建议内联注释由行的其余部分分隔两个空格 However, the default in Emacs is that running comment-dwim or indent-for-comment puts only one space between the end of the line and the comment. 但是,Emacs中的默认值是运行comment-dwimindent-for-comment只会在行尾和注释之间放置一个空格。 Is there a way to change this default behavior in emacs? 有没有办法在emacs中更改此默认行为?

I am running Emacs 23.3.1 我正在运行Emacs 23.3.1

This should do what you want: 这应该做你想要的:

   (add-hook 'python-mode-hook
      (lambda () (set (make-local-variable 'comment-inline-offset) 2)))

You can check emacs's documentation by Ch v RET comment-inline-offset , then you will find the answer as @And said. 您可以通过Ch v RET comment-inline-offset检查emacs的文档,然后您将找到@And所说的答案。

Here's a simplified version: 这是一个简化版本:

(add-hook 'python-mode-hook
  (lambda () (setq-local comment-inline-offset 2)))

尝试将comment-start设置为" # " (之前一个空格,一个之后)。

M-x set-variable comment-start " # "

I think this might do what you want: 我想这可能会做你想要的:

(defun my-comment-indent ()
  (interactive)
  (end-of-line)
  (let ((comment-column (+ 2 (current-column))))
    (comment-indent)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM