-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_cc-mode.el
More file actions
70 lines (52 loc) · 2.26 KB
/
_cc-mode.el
File metadata and controls
70 lines (52 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
;; -*-emacs-lisp-*-
;;;
;;; Configuration for cc-mode (i.e. C, C++, Objective-C, Java, Pike,
;;; AWK, CORBA IDL.
;;;
;; (require 'cc-mode)
;;; TODO: https://github.com/torvalds/linux/blob/master/Documentation/process/coding-style.rst
;;;
;;; This sets up the coding mode for linux kernel sources.
;;; (originally obtained from Documentation/CodingStyle in Linux kernel tree)
;;;
(defun linux-c-mode ()
"C mode with adjusted defaults for use with the Linux kernel."
(interactive)
(c-mode)
(if (>= emacs-version 22)
(c-set-style "linux") ; After version ??, we have "linux" mode!
(progn
(c-set-style "K&R")
(setq c-basic-offset 8))))
(add-to-list 'auto-mode-alist '("/linux.*/.*\\.[ch]$" . linux-c-mode))
;;; C & C++
(with-eval-after-load "cc-mode"
(add-hook 'c-mode-hook
#'(lambda ()
(cinsk/visit-tags-table (path-join user-emacs-directory
"TAGS.sys") t)))
(add-hook 'c++-mode-hook
#'(lambda ()
(cinsk/visit-tags-table (path-join user-emacs-directory
"TAGS.sys") t)))
(add-hook 'c-mode-hook (function (lambda nil (abbrev-mode 1))))
(add-hook 'c++-mode-hook (function (lambda nil (abbrev-mode 1))))
(when (locate-library "cc-subword")
(require 'cc-subword)
(define-key c-mode-base-map [(meta ?F)] 'c-forward-subword)
(define-key c-mode-base-map [(meta ?B)] 'c-backward-subword)
(define-key c-mode-base-map [(meta ?D)] 'c-kill-subword))
(define-key c-mode-base-map [(meta ?{)] 'c-beginning-of-defun)
(define-key c-mode-base-map [(meta ?})] 'c-end-of-defun)
(define-key c-mode-base-map [(control meta ?{)] 'c-up-conditional-with-else)
(define-key c-mode-base-map [(control meta ?})] 'c-down-conditional-with-else)
;; Highlights suspicious C/C++ constructions
(add-hook 'c-mode-common-hook (lambda () (cwarn-mode 1)))
;; Java
(add-hook 'java-mode-hook (lambda ()
(subword-mode 1)
(c-set-offset 'statement-cont '++)))
;; Prompt for arguments to the preprocessor for `c-macro-expand'
(setq c-macro-prompt-flag t)
(when (locate-library "autodisass-java-bytecode")
(require 'autodisass-java-bytecode)))