Emacs for SOFA Development
From SOFAWiki
Contents |
Detailed Instructions
Emacs is a very powerful editor, however its default configuration is difficult to use if you are not an expert, and its indentation rules are really really bad if not configured properly !
Setup
Create the files ~/.emacs and ~/.emacs.d/sofa_style.el given in the Appendix section. TODO: explain what each setting means...
SVN support
Use shell commands.
SVN support with emacs needs to be tested
Building SOFA
Configuration
Use shell commands.
Compilation
Press F5 to set the command to use (required at least once), just press Enter if the default command from the config file is OK.
Press F6 to re-compile with the same command.
Press F1 to go to the next warning or error message in the compile log while opening the corresponding source file and putting the cursor at the right line.
Appendix
Configuration Files
Add the following in your ~/.emacs file :
;; http://www.haypocalc.com/logiciel/cfg_emacs.php ;; http://www.postulate.org/emacs.php ;; http://www.djcbsoftware.nl/dot-emacs.html ;; Raccouris clavier (global-set-key [f1] 'next-error) (global-set-key [f2] 'save-buffer) (global-set-key [f3] 'find-file) (global-set-key [f4] 'kill-this-buffer) (global-set-key [f5] 'compile) (global-set-key [f6] 'recompile) (global-set-key [(control z)] 'undo) (mouse-wheel-mode t) ;; Style d'indentation C (load "~/.emacs.d/sofa_style.el") (setq-default indent-tabs-mode nil) (setq default-tab-width 4) ;; Default compilation command (setq compile-command "nice -19 make -wC ~/Sofa -j 1" ) ;; use c++ mode for all extensions used in Sofa + sgml mode for scene files (setq auto-mode-alist (append '(("\\.cpp$" . c++-mode) ("\\.hpp$" . c++-mode) ("\\.h$" . c++-mode) ("\\.inl$" . c++-mode) ("\\.cg$" . c++-mode) ("\\.cu$" . c++-mode) ("\\.cuh$" . c++-mode) ("\\.pl$" . perl-mode) ("\\.scn$" . sgml-mode) ("\\.pscn$" . sgml-mode) ) auto-mode-alist)) ;; disable startup message (setq inhibit-startup-message t) ; don't show startup (setq inhibit-startup-echo-area-message t) ; crap ;; alias y to yes and n to no (defalias 'yes-or-no-p 'y-or-n-p) ;; highlight matches from searches (setq isearch-highlight t) (setq search-highlight t) (setq-default transient-mark-mode t) ;; show a menu only when running within X (save real estate when ;; in console) (menu-bar-mode (if window-system 1 -1)) ;; replace highlighted text with what I type rather than just ;; inserting at a point (delete-selection-mode t) ;; highlight during searching (setq query-replace-highlight t) ;; highlight incremental search (setq search-highlight t) ;(scroll-bar-mode t) ; show the scroll bar ... (set-scroll-bar-mode 'right) ; ... on the right side ;; Autorise la selection a l'aide de la touche SHIFT (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(auto-compression-mode t nil (jka-compr)) '(c++-mode-hook (quote ((lambda nil (c-set-style "sofa"))))) '(c-mode-hook (quote ((lambda nil (c-set-style "sofa"))))) '(case-fold-search t) '(column-number-mode t) '(compilation-scroll-output t) '(compile-auto-highlight 10) '(current-language-environment "UTF-8") '(default-input-method "rfc1345") '(default-justification (quote left)) '(global-font-lock-mode t nil (font-lock)) '(pc-select-meta-moves-sexps t) '(pc-select-selection-keys-only t) '(pc-selection-mode t nil (pc-select)) '(show-paren-mode t nil (paren)) '(text-mode-hook (quote (text-mode-hook-identify)))) ;; Affiche l'heure au format 24h (setq display-time-24hr-format t) (setq display-time-day-and-date t) ;; Les 'beep' deviennent visibles (et non plus audibles) (setq visible-bell t) ;; Activer la coloration syntaxique (global-font-lock-mode t) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(default ((t (:inherit nil :stipple nil :background "black" :foreground "white" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 102 :width normal :foundry "unknown" :family "Liberation Mono"))))) (set-face-foreground 'default "white") (set-face-background 'default "black") ;; SSH is used by default to edit remote files ( by opening files using syntax /hostname:path ) (setq tramp-default-method "ssh") ;; backups (emacs will write backups and number them) (setq make-backup-files t ; do make backups backup-by-copying t ; and copy them ... backup-directory-alist '(("." . "~/.emacs-backup")) ; ... here version-control t kept-new-versions 2 kept-old-versions 5 delete-old-versions t) ;; indent the entire buffer (defun c-indent-buffer () "Indent entire buffer of C source code." (interactive) (save-excursion (goto-char (point-min)) (while (< (point) (point-max)) (c-indent-command) (end-of-line) (forward-char 1))))
Put the following in a new file ~/.emacs.d/sofa_style.el :
(c-add-style "sofa" (quote ( ;; Indentation de base = 2 espaces (c-basic-offset . 4) (c-backslash-column . 48) (c-cleanup-list scope-operator) (c-comment-only-line-offset . 0) (c-electric-pound-behavior) (c-label-minimum-indentation 0) (c-hanging-braces-alist (brace-list-open) (brace-entry-open) (substatement-open after) (block-close . c-snug-do-while) (extern-lang-open after) (inexpr-class-open after) (inexpr-class-close before)) (c-hanging-colons-alist) (c-hanging-comment-starter-p . t) (c-hanging-comment-ender-p . t) (c-offsets-alist (string . c-lineup-dont-change) ;; Inside multi-line string. (c . c-lineup-C-comments) ;; 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 . 0) ;; The region between a function definition's argument list and the function opening brace (knr-argdecl-intro . 0) ;; First line of a K&R C argument declaration. (knr-argdecl . 0) ;; Subsequent lines in a K&R C argument declaration. (topmost-intro . 0) ;; The first line in a topmost construct definition. (topmost-intro-cont . 0) ;; Topmost definition continuation lines. (member-init-intro . 0) ;; First line in a member initialization list. (member-init-cont . 0) ;; Subsequent member initialization list lines. (inher-intro . 0) ;; First line of a multiple inheritance list. (inher-cont . c-lineup-multi-inher) ;; 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 . 0) ;; Subsequent lines in an enum or static array list that start with an open brace. (statement . 0) ;; A C (or like) statement. (statement-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 . 0) ;; 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. (case-label . 0) ;; 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 . c-lineup-comment) ;; A line containing only a comment introduction. (arglist-intro . 0) ;; The first line in an argument list. (arglist-cont . 0) ;; Subsequent argument list lines when no arguments follow on the same line as the arglist opening paren. (arglist-cont-nonempty . c-lineup-arglist) ;; Subsequent argument list lines when at least one argument follows on the same line as the arglist opening paren. (arglist-close . 0) ;; 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 . -1000) ;; The start of a C preprocessor macro definition. (cpp-macro-cont . c-lineup-dont-change) ;; Subsequent lines in a multi-line C preprocessor macro definition. (friend . 0) ;; A C++ friend declaration. (objc-method-intro . -1000) ;; The first line of an Objective-C method definition. (objc-method-args-cont . c-lineup-ObjC-method-args) ;; Lines continuing an Objective-C method definition. (objc-method-call-cont . c-lineup-ObjC-method-call) ;; Lines continuing an Objective-C method call. (extern-lang-open . 0) ;; Brace that opens an external language block. (extern-lang-close . 0) ;; Brace that closes an external language block. (inextern-lang . 0) ;; Analogous to the `inclass' syntactic symbol, but used inside extern constructs. (namespace-open . 0) ;; Brace that opens a C++ namespace block. (namespace-close . 0) ;; Brace that closes a C++ namespace block. (innamespace . 0) ;; Analogous to the `inextern-lang' syntactic symbol, but used inside C++ namespace constructs. (template-args-cont . +) ;; C++ template argument list continuations. (inlambda . c-lineup-inexpr-block) ;; In the header or body of a lambda function. (lambda-intro-cont . 0) ;; Continuation of the header of a lambda function. (inexpr-statement . 0) ;; The statement is inside an expression. (inexpr-class . 0) ;; The class is inside an expression. Used e.g. for Java anonymous classes. ) ) ) )
