0

Is there a way to specify the same settings for c-mode and c++-mode without repeating the alist? I have:

((c-mode . ((comment-start . "/* ")
            (comment-end . " */")
            (comment-padding . 0))))

and would like to avoid:

((c-mode . ((comment-start . "/* ")
            (comment-end . " */")
            (comment-padding . 0)))

 (c++-mode . ((comment-start . "/* ")
              (comment-end . " */")
              (comment-padding . 0))))
3

Not as such (AFAIK).

However, both those modes derive from prog-mode which might be fine to target for this directory.

((prog-mode . ((comment-start . "/* ")
               (comment-end . " */")
               (comment-padding . 0))))

Or you could even use nil, which applies to every mode (again, maybe that's ok in practice).

((nil . ((comment-start . "/* ")
         (comment-end . " */")
         (comment-padding . 0))))

Otherwise, I think you just have to live with the duplication.

Unless it's just for you, in which case you might be happy with

((c-mode . ((eval . (my-comment-settings))))
 (c++-mode . ((eval . (my-comment-settings)))))

calling some my-comment-settings function defined in your init file.

(defun my-comment-settings ()
  "My comment settings."
  (setq-local comment-start "/* ")
  (setq-local comment-end " */")
  (setq-local comment-padding 0))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.