Reputation: 66214
In Emacs, how can I enforce a maximum line length of, say, 80 characters? I want it to insert proper line breaks in my code, much like fill-paragraph
for text, if possible, with the correct insertion of the second part of the line.
Here a little example:
LongNameType<PrettyLong, AlsoLong> doSomethingWithLongFunctionName(int a, int b);
foo();
If I actually do fill-paragraph
it becomes:
LongNameType<PrettyLong, AlsoLong>
doSomethingWithLongFunctionName(int a, int b); foo();
whereas I'd prefer this:
LongNameType<PrettyLong, AlsoLong>
doSomethingWithLongFunctionName(int a, int b);
foo();
Upvotes: 23
Views: 17097
Reputation: 542
You could use the more advanced clang-format package.
(setq clang-format-style "file")
or add to custom-set-variables
'(clang-format-style "file")
.clang-format -style=gnu -dump-config > .clang-format
then place into your project's root.ColumnLimit: 120
to 80 or whatever value you want.That would force column limit using clang-format tool.
Reference: ClangFormatStyleOptions. Related question
Upvotes: 0
Reputation: 469
Try
'(c-max-one-liner-length 80)
'(fill-column 80)
'(c-ignore-auto-fill (quote (string cpp)))
Hope it helps.
Upvotes: 0
Reputation: 26227
You should check out one of the many "vertical line" libraries for Emacs. Some keep a vertical highlight line over the entire buffer at point at all times (not really what you want) but other libraries put the vertical highlight on a fix column at all times, which is not really what you want, but you can immediately see when you ought to be wrapping lines.
Upvotes: 1
Reputation: 74460
There are a number of packages which warn you of line length limits. Personally, I use wide-column, which changes the cursor color depending on its current column.
Upvotes: 6
Reputation: 316
fill-paragraph and auto-fill-mode deliberately don't wrap code. There are just too many ways to do it and it'd probably get it wrong. They will wrap comments, but that doesn't help you here.
The only way I've ever done it to to explicitly put the where I want the text to break. Then the auto-indent should put the broken line in the right place.
Are you trying to reflow a large body of existing code? Or trying to have auto-fill work on code you are writing now?
Upvotes: 4
Reputation: 15836
I use modeline-posn package. It highlights column number in the modeline if it's greater than specified value.
Upvotes: 1
Reputation: 45132
Not really an emacser, but what happens if you turn on auto-fill-mode while in c++-mode?
C++ mode should give you auto-indent, and auto-fill-mode gives you line-wrapping....
Upvotes: 2