From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: C++ access label indentation. Date: Thu, 21 Mar 2013 22:14:31 +0100 Organization: Informatimago Message-ID: <87k3p0pia0.fsf@kuiper.lan.informatimago.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1363900509 11265 80.91.229.3 (21 Mar 2013 21:15:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 21 Mar 2013 21:15:09 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Mar 21 22:15:34 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UImph-0002r6-EN for geh-help-gnu-emacs@m.gmane.org; Thu, 21 Mar 2013 22:15:33 +0100 Original-Received: from localhost ([::1]:34378 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UImpK-0003ej-2Q for geh-help-gnu-emacs@m.gmane.org; Thu, 21 Mar 2013 17:15:10 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:51769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UImp2-0003ea-4F for help-gnu-emacs@gnu.org; Thu, 21 Mar 2013 17:14:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UImov-0001qP-EN for help-gnu-emacs@gnu.org; Thu, 21 Mar 2013 17:14:52 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:40888) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UImou-0001qI-VP for help-gnu-emacs@gnu.org; Thu, 21 Mar 2013 17:14:45 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UImpG-0002Xw-KU for help-gnu-emacs@gnu.org; Thu, 21 Mar 2013 22:15:06 +0100 Original-Received: from amontsouris-651-1-93-50.w82-123.abo.wanadoo.fr ([82.123.216.50]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 21 Mar 2013 22:15:06 +0100 Original-Received: from pjb by amontsouris-651-1-93-50.w82-123.abo.wanadoo.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 21 Mar 2013 22:15:06 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 486 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: amontsouris-651-1-93-50.w82-123.abo.wanadoo.fr Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) Cancel-Lock: sha1:OTQ3YjQwMjgwMGEyMDk3MmNiMjA0YzJmNTAyZWJhNTZkYjI2OGMzNg== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:89640 Archived-At: Alessio Giovanni Baroni writes: > Hi to all, > > I'm writing you because I don't know how to indenting the C++ code in > the following mode: > > class foo > { >     private: >          int n; >     public: >         void bar (); > }; > > I did many searches, and the two principal messages (http:// > lists.gnu.org/archive/html/help-gnu-emacs/2009-09/msg00593.html and > http://lists.gnu.org/archive/html/help-gnu-emacs/2012-10/ > msg00332.html) doesn't resolve my problem. > > Any help? M-x set-variable RET c-echo-syntactic-information-p RET t RET C-x C-f /tmp/test.c++ RET and paste the code there, then: C-x h C-M-\ now you get the "default" indentation. Go at the beginning of the line that's not indented as you want, and type TAB. You should see in the minibuffer the syntactic information echoed. For example, for "private:", I get: syntax: ((inclass 11) (access-label 11)), indent: 0 It means that you can set the indentation by configuring the inclass and/or the access-label offset in c-offsets-alist (inclass . +) (access-label . 0) Then do the same for the member lines: syntax: ((inclass 11) (topmost-intro 11)), indent: 8 so combining inclass and topmost-intro: (topmost-intro . +) you should get the indentation you want. You can configure it in two ways: - with a c-style, in which case the custom variables must be set to 'set-from-style to defer to the c-style, and you will configure c-offsets-alist in your c-style, (custom-set-variables … '(c-basic-offset (quote set-from-style)) …) (c-add-style "Your style" '( … (c-offsets-alist . ( … (inclass . +) (access-label . 0) (topmost-intro . +) … )) … ))) - or directly setting the custom variable c-offsets-alist. (customize-variables … '(c-offsets-alist '( (inclass . +) (access-label . 0) (topmost-intro . +) …)) …) Of course, in either case, you will want to configure a lot more to get indenting of the rest to your taste. Following the fold are my own settings. (custom-set-variables '(c-argdecl-indent 4 t) '(c-auto-newline nil t) '(c-backslash-column (quote set-from-style)) '(c-backslash-max-column (quote set-from-style)) '(c-basic-offset (quote set-from-style)) '(c-block-comment-prefix (quote set-from-style)) '(c-brace-imaginary-offset 0 t) '(c-brace-offset 0 t) '(c-cleanup-list (quote set-from-style)) '(c-comment-continuation-stars "" t) '(c-comment-only-line-offset (quote set-from-style)) '(c-comment-prefix-regexp (quote set-from-style)) '(c-continued-brace-offset 0 t) '(c-continued-statement-offset 4 t) '(c-default-style "pjb") '(c-doc-comment-style (quote set-from-style)) '(c-echo-syntactic-information-p t) '(c-hanging-braces-alist (quote set-from-style)) '(c-hanging-colons-alist (quote set-from-style)) '(c-hanging-comment-ender-p nil t) '(c-hanging-comment-starter-p nil t) '(c-hanging-semi&comma-criteria (quote set-from-style)) '(c-indent-comment-alist (quote set-from-style)) '(c-indent-comments-syntactically-p (quote set-from-style)) '(c-indent-level 4 t) '(c-label-minimum-indentation 2) '(c-label-offset -4 t) '(c-macro-shrink-window-flag t) '(c-offsets-alist nil) '(c-special-indent-hook nil) '(c-tab-always-indent t)) (c-add-style "pjb" '((c-backslash-column . 72) (c-backslash-max-column . 128) (c-basic-offset . 4) ; Amount of basic offset used by `+' and ; `-' symbols in `c-offsets-alist'. (c-block-comment-prefix . "") (c-cleanup-list . (brace-else-brace brace-elseif-brace brace-catch-brace list-close-comma scope-operator)) (c-comment-only-line-offset . (0 . 0)) ;; (c-comment-prefix-regexp) (c-doc-comment-style . javadoc) (c-hanging-braces-alist . ( ;; (statement-cont) ;; (brace-list-intro) (inexpr-class-open . (after)) (inexpr-class-close . (before)) (defun-open . (after)) ; Brace that opens a function definition. (defun-close . (before)) ; Brace that closes a function definition. (class-open . (before after)) ; Brace that opens a class definition. (class-close . ()) ; Brace that closes a class definition. (inline-open . (before after)) ; Brace that opens an in-class inline method. (inline-close . (before)) ; Brace that closes an in-class inline method. (block-open . ()) ; Statement block open brace. (block-close . c-snug-do-while) ; Statement block close brace. (brace-list-open . (after)) ; Open brace of an enum or static array list. (brace-list-close . (before after)) ; Close brace of an enum or static array list. (brace-entry-open . (before after)) ; Subsequent lines in an enum or static array (statement-case-open . (after)) ; The first line in a case block starting with brace. (substatement-open . (after)) ; The brace that opens a substatement block. (extern-lang-open . (after)) ; Brace that opens an "extern" block. (extern-lang-close . (before after)) ; Brace that closes an "extern" block. (namespace-open . (after)) (namespace-close . ()) (module-open . (after)) (module-close . ()) (composition-open . (after)) (composition-close) . ())) (c-hanging-colons-alist . ((case-label . (after)) (label . (after)) (access-label . (after)) (member-init-intro . ()) (inher-intro . ()))) (c-hanging-semi&comma-criteria . ()) ;; (c-indent-comment-alist) (c-indent-comments-syntactically-p . nil) (c-label-minimum-indentation . 2) (c-offsets-alist . ( (string . 0) ;; Inside multi-line string. (c . 0) ;; Inside a multi-line C style block comment. (defun-open . 0) ;; Brace that opens a function definition. (defun-close . 0) ;; Brace that closes a function definition. (defun-block-intro . +) ;; The first line in a top-level defun. (class-open . 0) ;; Brace that opens a class definition. (class-close . 0) ;; Brace that closes a class definition. (inline-open . 0) ;; Brace that opens an in-class inline method. (inline-close . 0) ;; Brace that closes an in-class inline method. (func-decl-cont . +) ;; The region between a function definition's ;; argument list and the function opening brace ;; (excluding K&R argument declarations). In C, you ;; cannot put anything but whitespace and comments ;; between them; in C++ and Java, throws declarations ;; and other things can appear in this context. (knr-argdecl-intro . +) ;; First line of a K&R C argument declaration. (knr-argdecl . +) ;; Subsequent lines in a K&R C argument declaration. (topmost-intro . +) ;; The first line in a topmost construct definition. (topmost-intro-cont . (c-lineup-string-cont 0)) ;; Topmost definition continuation lines. (member-init-intro . +) ;; First line in a member initialization list. (member-init-cont . ++) ;; Subsequent member initialization list lines. (inher-intro . +) ;; First line of a multiple inheritance list. (inher-cont . ++) ;; Subsequent multiple inheritance lines. (block-open . 0) ;; Statement block open brace. (block-close . 0) ;; Statement block close brace. (brace-list-open . 0) ;; Open brace of an enum or static array list. (brace-list-close . 0) ;; Close brace of an enum or static array list. (brace-list-intro . +) ;; First line in an enum or static array list. (brace-list-entry . 0) ;; Subsequent lines in an enum or static array list. (brace-entry-open . +) ;; Subsequent lines in an enum or static array ;; list that start with an open brace. (statement . (c-lineup-runin-statements 0)) ;; A C (or like) statement. (statement-cont . (c-lineup-string-cont ++)) ;; A continuation of a C (or like) statement. (statement-block-intro . +) ;; The first line in a new statement block. (statement-case-intro . +) ;; The first line in a case "block". (statement-case-open . +) ;; The first line in a case block starting with brace. (substatement . +) ;; The first line after an if/while/for/do/else. (substatement-open . 0) ;; The brace that opens a substatement block. (substatement-label . /) ;; Labelled line after an if/while/for/do/else. (case-label . *) ;; A "case" or "default" label. (access-label . -) ;; C++ private/protected/public access label. (label . /) ;; Any ordinary label. (do-while-closure . 0) ;; The "while" that ends a do/while construct. (else-clause . 0) ;; The "else" of an if/else construct. (catch-clause . 0) ;; The "catch" or "finally" of a try/catch construct. (comment-intro . 0) ;; A line containing only a comment introduction. (arglist-intro . (c-lineup-arglist-intro-after-paren +)) ;; The first line in an argument list. (arglist-cont . (c-lineup-string-cont c-lineup-arglist-intro-after-paren c-lineup-argcont +)) ;; Subsequent argument list lines when no ;; arguments follow on the same line as the ;; arglist opening paren. (arglist-cont-nonempty . (c-lineup-string-cont c-lineup-arglist-intro-after-paren c-lineup-argcont +)) ;; Subsequent argument list lines when at ;; least one argument follows on the same ;; line as the arglist opening paren. (arglist-close . (c-lineup-argcont c-lineup-arglist-intro-after-paren -)) ;; The solo close paren of an argument list. (stream-op . (c-lineup-streamop +)) ;; Lines continuing a stream operator construct. (inclass . +) ;; The construct is nested inside a class definition. ;; Used together with e.g. `topmost-intro'. (cpp-macro . [0]) ;; The start of a C preprocessor macro definition. (cpp-macro-cont . [8]) ;; Inside a multi-line C preprocessor macro definition. (friend . 0) ;; A C++ friend declaration. (objc-method-intro . 0) ;; The first line of an Objective-C method definition. (objc-method-args-cont . (c-lineup-ObjC-method-args-2 +)) ;; Lines continuing an Objective-C method definition. (objc-method-call-cont . (c-lineup-ObjC-method-call-colons c-lineup-ObjC-method-call +)) ;; Lines continuing an Objective-C method call. (extern-lang-open . 0) ;; Brace that opens an "extern" block. (extern-lang-close . 0) ;; Brace that closes an "extern" block. (inextern-lang . +) ;; Analogous to the `inclass' syntactic symbol, ;; but used inside "extern" blocks. (namespace-open . 0) (namespace-close . 0) (innamespace . +) ;; Similar to the three `extern-lang' symbols, but for ;; C++ "namespace" blocks. (module-open . 0) (module-close . 0) (inmodule . +) ;; Similar to the three `extern-lang' symbols, but for ;; CORBA IDL "module" blocks. (composition-open . 0) (composition-close . 0) (incomposition . +) ;; Similar to the three `extern-lang' symbols, but for ;; CORBA CIDL "composition" blocks. (template-args-cont . (c-lineup-template-args +)) ;; C++ template argument list continuations. (inlambda . +) ;; In the header or body of a lambda function. (lambda-intro-cont . ++) ;; Continuation of the header of a lambda function. (inexpr-statement . +) ;; The statement is inside an expression. (inexpr-class . +) ;; The class is inside an expression. Used e.g. for ;; Java anonymous classes. )) ;; Only called when c-syntactic-indentation is non nil. ;; (c-special-indent-hook . user-fun) (c-label-minimum-indentation . 2) ;; other emacs variables: ;; (c-comment-continuation-stars "" t) ;; (c-echo-syntactic-information-p t) ;; (c-hanging-comment-ender-p nil t) ;; (c-hanging-comment-starter-p nil t) ;; (c-macro-shrink-window-flag . t) (tab-width . 4) ; the true one! (c-indent-level . 4) ; Indentation of C statements with ; respect to containing block. (c-brace-imaginary-offset . 0) ; Imagined indentation of a C open brace ; that actually follows a statement. (c-brace-offset . 0) ; Extra indentation for braces, compared ; with other text in same context. (c-argdecl-indent . 4) ; Indentation level of declarations of ; C function arguments. (c-label-offset . -) ; Offset of C label lines and case ; statements relative to usual ; indentation. (c-continued-statement-offset . 4) ; Extra indent for lines not starting ; new statements. (c-continued-brace-offset . 0) ; Extra indent for substatements that ; start with open-braces. (c-auto-newline . nil) ; Non-nil means automatically newline ; before and after braces, and after ; colons and semicolons, inserted in C ; code. If you do not want a leading ; newline before braces then use: ; (define-key c-mode-map \"{\" ; 'electric-c-semi)" (c-tab-always-indent . nil) ; Non-nil means TAB in C mode should ; always reindent the current line, ; regardless of where in the line point ; is when the TAB command is used. ))) -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}.