简体   繁体   中英

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 . 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. Is there a way to change this default behavior in emacs?

I am running 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.

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)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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