Editor Emacs

From Apache OpenOffice Wiki
Jump to: navigation, search

This page is about (X)Emacs, editor and kitchen sink, and the only real one, for that matter.

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:

#include <com/sun/star/module/XInterfaceName.hpp>

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-hungry-delete-key t)
     (substatement-open after)
     (block-close . c-snug-do-while)
     (extern-lang-open after)
     (inexpr-class-close before))
    (c-hanging-comment-starter-p . t)
    (c-hanging-comment-ender-p . t)
     (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
     "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
	 ) 'words)
(defconst bm-additional-constant-keywords
	 "TRUE" "FALSE" "sal_True" "sal_False"
	 ) 'words)
(defconst bm-strparam-keywords
	 ) 'words)
(defconst bm-exit-keywords
	 "return" "exit" "break" "continue" "goto"
	 ) 'words)
(defconst bm-assert-keywords
   (concat "\\<\\("
(defconst bm-const-keywords
   '(1 font-lock-sid-face)
   '(3 font-lock-constant-face)
(defconst bm-brace-keywords
(defconst bm-operator-keywords


Keywords for IDL Files

(defconst bm-idl-keywords
	 "module" "interface" "service" "constants" "enum" "typedef" "struct"
	 "singleton" "exception" "raises" "property" "oneway"
	 ) 'words)
(defconst bm-idl-unused-keywords
	 "inout" "out" "observe" "needs" "attribute"
	 "union" "switch" "case" "array"
	 ) 'words)
(defconst bm-idl-types
	 "short" "long" "int" "hyper" "sequence" "boolean" "void" "string" "any"
	 "type" "float" "double" "byte" "unsigned"
	 ) 'words) font-lock-type-face ) )
(defconst bm-idl-builtin
	 "ifndef" "include" "endif" "define"
	 ) 'words)
(defconst bm-idl-property-flags
	 "readonly" "bound" "constrained" "maybeambiguous" "maybedefault"
	 "maybevoid" "optional" "removable" "transient" "in"
	 ) 'words)

;; Add the keyword groups you want to show

 '(( "\\(</?\\)\\(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

Personal tools