C Comment in Emacs - Linux Kernel Style v2

断了今生、忘了曾经 提交于 2019-12-23 22:22:24

问题


I received an answer about C Comment in Emacs - Linux Kernel Style that works great but

when emacs comments (comment-dwim) it's padding the second * long_function_name_vari and last */ lines with spaces (before the comment) not tabs like I have configured it. How to avoid that?

And how easily to make a comment using this style?

    /* void main()
     * {
     *  int i;
     *  int b;
     *  printf("format string");
     * }
     */

回答1:


Customizable variable comment-style is defined in newcomment.el saying ...

(extra-line t   nil t   t
            "One comment for all lines, end on a line by itself")

...

which should deliver the wanted result IIUC.

Current implementation however is two-extra-lines, the opening newline undocumented so far. Please file a feature request resp. docu-bug report.




回答2:


Well, after seek the newcomment.el I could understand how to tweak that behavior.

(defun my-c-comment-dwim (tabify delete-trailing)      
  (interactive)
  (let (beg end)
    (if (region-active-p)
        (progn
          (setq beg (region-beginning)
                end (region-end))
          (if (comment-only-p beg end)
              (uncomment-region beg end)
            (progn
              (comment-region beg end)
              (when (equal comment-style 'extra-line)
                (save-excursion
                  (goto-char end)
                  (forward-line 2)
                  (setq end (line-end-position))))
              (when tabify
                (tabify beg end))
              (when delete-trailing
                (delete-trailing-whitespace beg end)))))
      (comment-indent))))

(global-set-key [remap comment-dwim] (lambda ()
                                       (interactive)
                                       (my-c-comment-dwim t t)))


来源:https://stackoverflow.com/questions/34710840/c-comment-in-emacs-linux-kernel-style-v2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!