Emacs C style for Apertium hacking
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 customisation 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")
;; 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/"
(buffer-file-name)))
(c-set-style "apertium"))
;; Some function names are camelCase, so make keys like M-f and M-b 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
(or use the default keyboard shortcut C-c .) and simply type
apertium
at the prompt.