Emacs C style for Apertium hacking

From Apertium
Jump to: navigation, search

Apertium's coding style does not match any of the Emacs built-in C styles. You can place the following code in your Emacs customisation file (normally found under ~/.emacs in Unix systems).

(defconst apertium-c-style
  '((c-basic-offset . 2)
    (c-comment-only-line-offset . 0)
     (substatement-open before after))
     (topmost-intro . 0)
     (substatement . +)
     (substatement-open . 0)
     (case-label . +)
     (access-label . -)
     (inclass . ++)
     (inline-open . 0)))
  "Apertium C++ Programming Style")

;; Customisations for all modes in CC Mode.
(defun my-c-mode-common-hook ()
  ;; add apertium to the list of C/C++ styles:
  (c-add-style "apertium" apertium-c-style t)
  ;; use the apertium style if the path of the opened file contains the substring "/apertium/":
  (if (and (buffer-file-name)
           (string-match "/matxin/\\|/apertium/\\|/lttoolbox/" 
                (c-set-style "apertium"))
  ;; Some function names are camelCase, so make keys like M-f and M-b treat "camelCase" as two words:

(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

The above should enable the Apertium style to the correct C++ files. If it's not enabled automatically, just execute

M-x c-set-style

(or use the default keyboard shortcut C-c .) and simply type


at the prompt.

[edit] See also

Personal tools