gjditchfield@rose.UUCP (05/27/87)
I am mostly pleased with the C++ mode that was posted here recently, but I did have a few problems. (If it matters, we use gnu version 17.64.) Creating a new buffer and typing if ( c ) { switch ( i ) { case 1: produced a "search failed: ":[^:]"" message when the ":" was typed. Apparently a re-search-forward call was failing when it hit the end of the buffer. Typing ESC-; on a line like something = something_else; // some comment did not reposition the comment at the comment column like C mode does; it always moved the comment one column right. C++-mode outdents "public", "private", and "protected" labels and the "case" arms of switch statements by (- c-indent-level) columns, instead of using c-label-offset. I like to have them indented just like branch labels, and in my case, c-label-offset != - c-indent-level. I altered the lisp code accordingly. The "old" style can be imitated (except for the difference between "private" and branch labels) by (setq c-label-offset (- c-indent-level)). "friend class" declarations are also outdented by (- c-indent-level) in C++ mode. I like them indented just like members. I decided to add a constant to control friend class indentation. It's default value gives the same behavior as the "old" C++ mode. Here's the output of "diff old-version new-version". ------- cut here. (check for a .signature too) -------- 57a58,59 > (defconst c++-friend-offset -4 > "*Offset of C++ friend class declarations relative to member declarations.") 144c146 < (let ((cur-col (current-column))) --- > (let (cur-col) 146,147c148,150 < (forward-line -1) < (end-of-line 1) --- > (skip-chars-backward " \t") > (setq cur-col (current-column)) > (end-of-line 0) 151d153 < (progn (match-beginning 0) 153,158c155,157 < (max (1+ cur-col) (current-column)))) < ; Else indent at comment column, except leave at least one space. < (forward-line 1) < (end-of-line 1) < (skip-chars-backward " \t") < (max (1+ cur-col) comment-column))))) --- > (max (1+ cur-col) (current-column))) > ; Else indent at comment column, except leave at least one space. > (max (1+ cur-col) comment-column))))) 256,257c255,258 < (setq indent (- indent c-indent-level))) < ((and (looking-at "[A-Za-z]") --- > ; (setq indent (- indent c-indent-level))) > (setq indent (+ indent c-label-offset))) > ((or (looking-at "case\\b") > (and (looking-at "[A-Za-z]") 260c261 < (looking-at ":[^:]"))) --- > (looking-at ":[^:]")))) 262,263c263,264 < ((looking-at "case\\b") < (setq indent (- indent c-indent-level))) --- > ; ((looking-at "case\\b") > ; (setq indent (- indent c-indent-level))) 269c270,271 < (setq indent (- indent c-indent-level))) --- > (setq indent (+ indent c++-friend-offset))) > ; (setq indent (- indent c-indent-level))) 371c373 < (re-search-forward ":[^:]")))) --- > (re-search-forward ":[^:]" nil 'move)))) -- Glen Ditchfield {watmath,utzoo,ihnp4}!watrose!gjditchfield Dept of Computer Science, U of Waterloo (519) 885-1211 x6658 Waterloo, Ontario, Canada Office: MC 2006 If you grab the bull by the horns, you at least confuse him -- R.A.Heinlein