Emacs C style for Apertium hacking

From Apertium
Revision as of 19:12, 24 May 2012 by Unhammer (talk | contribs)
Jump to navigation Jump to 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 customization file (normally found under ~/.emacs in Unix systems).

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

;; Customizations 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/" 
                         (buffer-file-name)))
                (c-set-style "apertium"))
  ;; Some function names are camelCase, so make keys like M-w treat "camelCase" as two words:
  (subword-mode))

(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

and simply type

apertium

at the prompt.