Editor Emacs
From OpenOffice.org Wiki
This page is about (X)Emacs, editor and kitchen sink, and the only real one, for that matter.
Contents[hide] |
Emacs and Cscope
Emacs has a premade file for cscope, generally packaged with cscope. So adding
;;cscope integration
(require 'xcscope)
(to your .emacs
, normally) is enough to activate it. Major shortcut are :
- Find-symbol : C-c s s
- Find-global-definition : C-c s g
- Next-symbol : C-c s n
See the documentation for more
Useful Keyboard Macros
Here is a macro for inserting include-guards for auto-generated UNO headers. If you typed
#include <com/sun/star/module/XInterfaceName.hpp>
you can call the following keyboard macro:
(fset 'bm-make-default-ifndef
[home ?/C-s ?< ?/C- ?/C-s ?> left ?/M-w home ?/C-m up ?# ?i ?f ?n ?d ?e ?f ? ?_
?/C-y ?_ ?/C- home C-right right ?/M-x ?r ?e ?p ?l ?a ?c ?e ?- ?s ?t ?r ?i ?n ?g
?/C-m ?/ ?/C-m ?_ ?/C-m end ?/C- home C-right right ?/C-x ?/C-u end ?/C- home
C-right right ?/M-x ?r ?e ?p ?l ?a ?c ?e ?- ?s ?t ?r ?i ?n ?g ?/C-m ?. ?/C-m ?_
?/C-m home down end ?/C-m ?# ?e ?n ?d ?i ?f home up])
to get the following:
#ifndef _COM_SUN_STAR_MODULE_XINTERFACENAME_HPP_
#include <com/sun/star/module/XInterfaceName.hpp>
#endif
C++ Mode for OOo Development
This is what I (bm) use for developing OOo sources in Emacs. The only thing that bothers me from time to time is that when having large templates, the indentation is not very good. I have not found a solution for that.
(defconst ooo-c-style
'((c-backslash-column . 70)
(c-basic-offset . 4)
(c-cleanup-list scope-operator)
(c-comment-only-line-offset . 0)
(c-electric-pound-behavior)
(c-hungry-delete-key t)
(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-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)
(c . c-lineup-C-comments)
(defun-open . 0)
(defun-close . 0)
(defun-block-intro . +)
(class-open . 0)
(class-close . 0)
(inline-open . 0)
(inline-close . 0)
(func-decl-cont . +)
(knr-argdecl-intro . +)
(knr-argdecl . 0)
(topmost-intro . 0)
(topmost-intro-cont . +)
(member-init-intro . +)
(member-init-cont . 0)
(inher-intro . +)
(inher-cont . c-lineup-multi-inher)
(block-open . 0)
(block-close . 0)
(brace-list-open . 0)
(brace-list-close . 0)
(brace-list-intro . +)
(brace-list-entry . 0)
(brace-entry-open . 0)
(statement . 0)
(statement-cont . +)
(statement-block-intro . +)
(statement-case-intro . +)
(statement-case-open . 0)
(substatement . +)
(substatement-open . 0)
(case-label . +)
(access-label . -)
(label . 2)
(do-while-closure . 0)
(else-clause . 0)
(catch-clause . 0)
(comment-intro . c-lineup-comment)
(arglist-intro . +)
(arglist-cont . 0)
(arglist-cont-nonempty . c-lineup-arglist)
(arglist-close . +)
(stream-op . c-lineup-streamop)
(inclass . +)
(cpp-macro . -)
(cpp-macro-cont . c-lineup-dont-change)
(friend . 0)
(objc-method-intro . -1000)
(objc-method-args-cont . c-lineup-ObjC-method-args)
(objc-method-call-cont . c-lineup-ObjC-method-call)
(extern-lang-open . 0)
(extern-lang-close . 0)
(inextern-lang . +)
(namespace-open . 0)
(namespace-close . 0)
(innamespace . 0)
(template-args-cont . ++)
(inlambda . c-lineup-inexpr-block)
(lambda-intro-cont . +)
(inexpr-statement . 0)
(inexpr-class . +)))
"OOo Programming Style")
(defun ooo-c-mode-common-hook ()
(c-add-style "ooo" ooo-c-style t)
(c-set-style "ooo")
(c-set-offset 'member-init-intro '++)
(setq tab-width 4)
(setq indent-tabs-mode nil) ;; use spaces instead of tabs
(c-toggle-auto-state 1)
(define-key c-mode-base-map "/C-m" 'newline-and-indent)
)
(add-hook 'c-mode-common-hook 'ooo-c-mode-common-hook)
If you work with several different source styles on your machine, you can use:
(defvar ooo-c-mode-path-regexp
"/opt/OpenOffice/.*"
"Regexp that matches paths into your OpenOffice.org source tree.")
(defun ooo-c-mode-common-hook ()
(when (string-match ooo-c-mode-path-regexp buffer-file-name)
(message "Using OpenOffice.org code settings")
... as before ...
Keywords for Syntax Highlighting
What is also useful are some keywords that can be used for syntax-highlighting (font-locking).
Keywords for C++ Code
(defconst bm-throw-face-keywords
(cons
(regexp-opt
(list
"SAL_CALL" "SAL_STATIC_CAST" "SAL_CONST_CAST" "SAL_REINTERPRET_CAST"
"__EXPORT" "NULL"
) 'words)
font-lock-throws-face
))
(defconst bm-additional-constant-keywords
(cons
(regexp-opt
(list
"TRUE" "FALSE" "sal_True" "sal_False"
) 'words)
font-lock-constant-face
))
(defconst bm-strparam-keywords
(cons
(regexp-opt
(list
"RTL_CONSTASCII_STRINGPARAM" "RTL_CONSTASCII_USTRINGPARAM"
"RTL_CONSTASCII_LENGTH" "RTL_TEXTENCODING_ASCII_US"
) 'words)
font-lock-constant-face
))
(defconst bm-exit-keywords
(cons
(regexp-opt
(list
"return" "exit" "break" "continue" "goto"
) 'words)
font-lock-exit-face
))
(defconst bm-assert-keywords
(cons
(concat "//<//("
(regexp-opt
(list
"OSL_DEBUG_ONLY" "OSL_TRACE" "OSL_ASSERT" "OSL_VERIFY" "OSL_ENSURE" "OSL_PRECOND" "OSL_POSTCOND"
))
"//|DBG_//sw+//)//>")
font-lock-dbg-face
))
(defconst bm-const-keywords
(list
"//<//(//(S//|W//)ID//)_//(//sw+//)"
'(1 font-lock-sid-face)
'(3 font-lock-constant-face)
))
(defconst bm-brace-keywords
(cons
"[][(){}]"
font-lock-brace-face
))
(defconst bm-operator-keywords
(cons
"[|&]+"
font-lock-bool-face
))
(font-lock-add-keywords
'c++-mode
(list
bm-brace-keywords
bm-operator-keywords
bm-exit-keywords
bm-additional-constant-keywords
bm-const-keywords
bm-throw-face-keywords
bm-assert-keywords
bm-strparam-keywords
))
Keywords for IDL Files
(defconst bm-idl-keywords
(cons
(regexp-opt
(list
"module" "interface" "service" "constants" "enum" "typedef" "struct"
"singleton" "exception" "raises" "property" "oneway"
) 'words)
font-lock-keyword-face
))
(defconst bm-idl-unused-keywords
(cons
(regexp-opt
(list
"inout" "out" "observe" "needs" "attribute"
"union" "switch" "case" "array"
) 'words)
font-lock-throws-face
))
(defconst bm-idl-types
(cons
(regexp-opt
(list
"short" "long" "int" "hyper" "sequence" "boolean" "void" "string" "any"
"type" "float" "double" "byte" "unsigned"
) 'words) font-lock-type-face ) )
(defconst bm-idl-builtin
(cons
(regexp-opt
(list
"ifndef" "include" "endif" "define"
) 'words)
font-lock-builtin-face
))
(defconst bm-idl-property-flags
(cons
(regexp-opt
(list
"readonly" "bound" "constrained" "maybeambiguous" "maybedefault"
"maybevoid" "optional" "removable" "transient" "in"
) 'words)
font-lock-constant-face
))
;; Add the keyword groups you want to show
(font-lock-add-keywords
'idl-mode
(list
bm-idl-keywords
bm-idl-types
bm-idl-builtin
bm-brace-keywords
bm-idl-property-flags
bm-idl-unused-keywords
))
(font-lock-add-keywords
'idl-mode
'(( "//(</?//)//(atom//|type//|member//|const//|listing//)//(>//)"
(1 font-lock-tag-face)
(2 font-lock-constant-face)
(3 font-lock-tag-face))
( "//(<//)//(TRUE//|FALSE//|NULL//|void//)//(/>//)"
(1 font-lock-tag-face)
(2 font-lock-constant-face)
(3 font-lock-tag-face))
( "//(@//)//(author//|see//|param//|throws//|returns?//|version//)"
(1 font-lock-tag-face)
(2 font-lock-constant-face))
))
Some font definitions for additional Keywords
In the above section there are some faces used, that are not part of the default set of font-locking faces. The definitions are here. You can customize them, of course, if you do not like the colors.
(defface font-lock-dbg-face
'((((class color) (background light)) (:foreground "DeepPink"))
(((class color) (background dark)) (:foreground "Red3"))
(t (:bold t :italic t)))
"Font Lock mode face used for OOo Debug messages."
:group 'font-lock-highlighting-faces)
(defvar font-lock-dbg-face 'font-lock-dbg-face
"Face name to use for OOo Debug messages.")
(defface font-lock-throws-face
'((((class color) (background light)) (:foreground "Gray60"))
(((class color) (background dark)) (:foreground "Gray80"))
(t (:bold t :italic t)))
"Font Lock mode face used for OOo THROWS statements."
:group 'font-lock-highlighting-faces)
(defvar font-lock-throws-face 'font-lock-throws-face
"Face name to use for OOo THROWS statements.")
(defface font-lock-bugid-face
'((((class color) (background light)) (:foreground "DarkGreen" :background "Wheat1"))
(((class color) (background dark)) (:foreground "DarkRed" :background "Gray70"))
(t (:bold t :italic t)))
"Font Lock mode face used for OOo BugIDs."
:group 'font-lock-highlighting-faces)
(defvar font-lock-bugid-face 'font-lock-bugid-face
"Face name to use for OOo BugIDs.")
(defface font-lock-sid-face
'((((class color) (background light)) (:foreground "Aquamarine4"))
(((class color) (background dark)) (:foreground "White"))
(t (:bold t :italic t)))
"Font Lock mode face used for OOo Slot IDs."
:group 'font-lock-highlighting-faces)
(defvar font-lock-sid-face 'font-lock-sid-face
"Face name to use for OOo Slot IDs.")
(defface font-lock-brace-face
'((((class color) (background light)) (:foreground "Red2"))
(((class color) (background dark)) (:foreground "White"))
(t (:bold t :italic t)))
"Font Lock mode face used for braces ()[]{} and the comma."
:group 'font-lock-highlighting-faces)
(defvar font-lock-brace-face 'font-lock-brace-face
"Face name to use for braces.")
(defface font-lock-bool-face
'((((class color) (background light)) (:foreground "forest green"))
(((class color) (background dark)) (:foreground "lime green"))
(t (:bold t :italic t)))
"Font Lock mode face used for boolean operators."
:group 'font-lock-highlighting-faces)
(defvar font-lock-bool-face 'font-lock-bool-face
"Face name to use for boolean operators.")
(defface font-lock-exit-face
'((((class color) (background light)) (:background "ivory1" :foreground "blue3"))
(((class color) (background dark)) (:foreground "yellow"))
(t (:bold t :italic t)))
"Font Lock mode face used for exit operations like return, break and exit."
:group 'font-lock-highlighting-faces)
(defvar font-lock-exit-face 'font-lock-exit-face
"Face name to use for exit operations like return, break and exit.")
(defface font-lock-tag-face
'((t (:foreground "dodger blue")))
"Font Lock mode face used for tags in IDL files."
:group 'font-lock-highlighting-faces)
(defvar font-lock-tag-face 'font-lock-tag-face
"Face name to use for tags in IDL files.")
See also
- Howto compile from within Emacs
From : http://wiki.services.openoffice.org/wiki/Editor_Emacs