开发者

Emacs: How to indent multiline statement by one tab only, when not first statement on a line?

I am not sure how to tell Emacs to indent code similar to the following, as shown: (the tab width is 2开发者_StackOverflow社区)

gotoxy(1, 2); cout << "one";
gotoxy(3, 4); cout << "this is "
  "split over two lines";
gotoxy(5, 6); cout << "three";

The 'statement-cont' variable is set to '+', indicating that I want a single indent, but I end up with this:

gotoxy(1, 2); cout << "one";
gotoxy(3, 4); cout << "this is "
                "split over two lines";
gotoxy(5, 6); cout << "three";

It is performing the single indent from the start of the statement instead of the start of the line.

How can I tell Emacs to start its indents from the beginning of the previous line rather than whatever column the statement started at?


This might not be the answer you are looking for... Anyway, as the gotoxy function apparently is doing something to cout, why don't you wrap it into a manip function and include it in the stream, that way you will 1) one statement on each line, which could be indented properly, 2) get the ability to have longer lines, as you don't have to stop at each gotoxy, and 3) it gives you the ability to apply gotoxy on any stream.

For example:

cout << gotoxy(1, 2) << "one";
cout << gotoxy(3, 4) << "this is "
  "split over two lines";
cout << gotoxy(5, 6) << "three";

Or, even simpler:

cout << gotoxy(1, 2) << "one"
     << gotoxy(3, 4) << "this is "
  "split over two lines"
     << gotoxy(5, 6) << "three";

Both sections were indented in Emacs, by the way.

You can read more about stream manip functions, for example, here: http://www.devarticles.com/c/a/Cplusplus/Custom-Stream-Manipulation-in-C/2/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜