Note that there are some explanatory texts on larger screens.

plurals
  1. POemacs C/C++ indentation: different for pre and post comments // or: how can I make certain comments like //^ be indented extra?
    text
    copied!<p>BRIEFEST:</p> <p>The original question boiled down to:</p> <p>Many if not most emacs c indentation styles make comments on a line by themselves, e.g. </p> <pre><code>// ... </code></pre> <p>indent to match the surrounding code.</p> <p>I want to make comments that look like //+ or //- be indented one or more indent settings more than the surrounding code.</p> <p>I usually think of this in terms of having same-indentation-level comments apply to the next lines of code, and extra-indentation-level comments apply to preceding lines of code. But that's just style.</p> <p>BRIEF:</p> <p>Are there (reasonably standard) emacs settings to obtain different indentation for C/C++ comments, depending on whether the comment is associated with the next line (in which case I want it indented appropriately for the syntax) or whether the comment is associated with the previous line (in which case I want it indented an additional level)?</p> <p>E.g.</p> <pre><code>int foo() { // this comment is for the variable bazz below int bazz; //- this comment is for the variable bazz,on the line above. //- I want it indented an extra level, which I will do by hand here. // this comment is for the next variable, biff int biff; int example; /* comment * on multiple lines * but this can be too much indented */ int example_of_a_really_long_name_that_can_produce_excessive_indentation; /* comment * on multiple lines * but this can be too much indented */ } </code></pre> <p>The comments beginning //and //- are pretty much what I want. // is indented along with the surrounding code. This is what emacs gives me.</p> <p>I would like //- to be indented an extra indentation level. Or //+,or whatever, if there is a convention. Sounds like a job for a regexp.</p> <p>I provide examples of what I know how to do for // and /<em>. The /</em> comments get spread over multiple lines, but can be excessively indented.</p> <p>DETAIL:</p> <p>I am just now installing emacs 24.1 - or at least I hope I am installing it, the systems at work have very old and crankly distros. But if something works on older emacs, such as 21.4.1, I'd e even happier - avoiding the hassle of having to install emacs on many different systems.</p> <p>================================</p> <p>By the way, I already know about c-indent-comment-syntactically, and much of cc-mode.el.</p> <p>In particular, c-indent-comment-syntactically gives me:</p> <pre><code>int foo() { // this comment is for the variable bazz below int bazz; //- this comment is for the variable bazz,on the line above. //- I want it indented an extra level, which I will do by hand here. // this comment is for the next variable, biff int biff; int example; /* comment * on multiple lines * but this can be too much indented */ int example_of_a_really_long_name_that_can_produce_excessive_indentation; /* comment * on multiple lines * but this can be too much indented */ if( foo ) // comment bar(); if( foo ) { // comment bar(); } } </code></pre> <p>This is not what I want. I want the //- comment lines to be indented an extra indent level.</p> <p>Heck, why not something like elisp:</p> <p>/// &lt;-- start in columno 0</p> <p>// indented syntactically (pertaining to next line of code)</p> <p>or perhaps //^ (the ^ indicates "above".</p> <p>//- or //^ - indented an extra indent level (pertaining to previous line of code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload