C Comment in Emacs - Linux Kernel Style v2

I got an answer about C Comment in Emacs - Linux Kernel Style , which works fine, but

enter image description here

when comments emacs ( comment-dwim) fills the second line * long_function_name_variand last */with spaces (before the comment), and not tabs, as I configured it. How to avoid this?

And how easy is it to make a comment using this style?

    /* void main()
     * {
     *  int i;
     *  int b;
     *  printf("format string");
     * }
     */
+2
source share
2 answers

A custom variable is comment-styledefined in newcomment.el. ...

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

...

which should deliver the desired IIUC result.

, , , , . , . .

+2

, newcomment.el , .

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

Source: https://habr.com/ru/post/1537215/


All Articles