summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@opera.com>2017-09-21 16:15:16 +0200
committerJoel Klinghed <the_jk@opera.com>2017-09-21 16:15:16 +0200
commit9f60ebc23f04c409d89a379b69cf0b5116310aa4 (patch)
tree29227ead0ecbee5c870e652996eeceaf49ece999
parent6a742f3fcff1387105e98c23d63788275492d0c2 (diff)
Merge some fixes between the emacs files
-rw-r--r--emacs-blue60
-rw-r--r--emacs-stark70
-rw-r--r--emacs-willow36
-rw-r--r--site-lisp/google-c-style.el151
4 files changed, 272 insertions, 45 deletions
diff --git a/emacs-blue b/emacs-blue
index 617b997..749759b 100644
--- a/emacs-blue
+++ b/emacs-blue
@@ -4,6 +4,9 @@
;;; Code:
+;; support local packages
+(add-to-list 'load-path "~/.emacs.d/site-lisp/")
+
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
@@ -12,7 +15,7 @@
package-selected-packages '(meson-mode groovy-mode gradle-mode flycheck))
;; use (package-install-selected-packages) to install the ones above
- ;; show matching parentheses (and other characters)
+;; show matching parentheses (and other characters)
(show-paren-mode t)
;; hide toolbar
@@ -81,6 +84,21 @@
(add-to-list 'default-frame-alist '(background-color . "black"))
(add-to-list 'default-frame-alist '(background-mode . "dark"))
+;; Toggle frame width
+(defun toggle-frame-width (frame)
+ "Toggle FRAME width between 100 and 80."
+ (when window-system
+ (let ((width (frame-width frame)))
+ (cond ((eq width 80)
+ (set-frame-width frame 100))
+ (t
+ (set-frame-width frame 80))))))
+
+(defun toggle-selected-frame-width ()
+ "Toggle selected frame width between 100 and 80."
+ (interactive)
+ (toggle-frame-width (selected-frame)))
+
;; default styles
(setq-default
;; no tabs in indentation
@@ -170,8 +188,7 @@
(eval-after-load 'autoinsert
'(define-auto-insert
'("\\.\\(java\\)\\'" . "Java source")
- '((capitalize
- (file-name-base buffer-file-name))
+ '((file-name-base buffer-file-name)
"package " (mapconcat 'identity (member "com" (split-string (file-name-directory buffer-file-name) "/" t)) ".") ";" \n
\n
"class " str " {" \n
@@ -189,6 +206,7 @@
;; keys
(global-set-key (kbd "C-c o") 'ff-find-other-file)
+(global-set-key [?\C-x ?\t] 'toggle-selected-frame-width)
;; flycheck
(require 'flycheck)
@@ -213,13 +231,37 @@
'("common c"
(c-basic-offset . 2)))
+(make-variable-buffer-local 'flycheck-clang-definitions)
+(make-variable-buffer-local 'flycheck-clang-include-path)
+(make-variable-buffer-local 'flycheck-clang-language-standard)
+
(add-hook 'c++-mode-hook
(lambda()
(setq flycheck-clang-language-standard "c++11"
flycheck-clang-definitions '("HAVE_CONFIG_H")
flycheck-clang-include-path
'("../src" "../build"))
- (c-set-style "default c++")))
+ (c-set-style "default c++")
+ (when (and buffer-file-name
+ (string-match "/source/monmon/" buffer-file-name))
+ (setq flycheck-clang-include-path
+ '("../src" "../build"
+ "/usr/include/cairo"
+ "/usr/include/pango-1.0"
+ "/usr/include/pixman-1"
+ "/usr/include/freetype2"
+ "/usr/include/libpng16"
+ "/usr/include/harfbuzz"
+ "/usr/include/glib-2.0"
+ "/usr/lib/glib-2.0/include"
+ "/usr/lib/icecream/include")))
+ (when (and buffer-file-name
+ (string-match "/source/sawmill-0.5/" buffer-file-name))
+ (setq flycheck-clang-include-path
+ '("../src" "../build"
+ "../subprojects/googletest-release-1.8.0/googletest/include"
+ "../subprojects/googletest-release-1.8.0/googlemock/include"
+ )))))
;; Opera Java hook
(add-hook 'java-mode-hook
@@ -234,6 +276,14 @@
flycheck-android-java-checkstyle-config
"checkstyle-config-android.xml"
flycheck-android-java-checkstyle-properties
- "checkstyle.properties"))))
+ "checkstyle.properties")
+ (require 'google-c-style)
+ (google-set-c-style)
+ (setq c-file-style "Google")
+ (c-set-offset 'arglist-intro '++)
+ (c-set-offset 'arglist-cont nil)
+ (c-set-offset 'arglist-cont-nonempty '++)
+ (setq indent-tabs-mode nil)
+ (setq c-basic-offset 4))))
;;;
diff --git a/emacs-stark b/emacs-stark
index c2a47b9..37d1709 100644
--- a/emacs-stark
+++ b/emacs-stark
@@ -247,35 +247,6 @@
'("common c"
(c-basic-offset . 2)))
-(add-hook 'c++-mode-hook
- (lambda()
- (make-local-variable 'flycheck-clang-language-standard)
- (setq flycheck-clang-language-standard "c++11")
- (c-set-style "default c++")))
-
-;; Opera Java hook
-(add-hook 'java-mode-hook
- (lambda()
- (when (and buffer-file-name
- (string-match "/opera/head" buffer-file-name))
- (require 'flycheck-android-experimental)
- (setq flycheck-android-java-checkstyle-jar
- "../../chromium/src/third_party/checkstyle/checkstyle-6.5-all.jar"
- flycheck-android-java-checkstyle-path
- "tools/checkstyle"
- flycheck-android-java-checkstyle-config
- "checkstyle-config-android.xml"
- flycheck-android-java-checkstyle-properties
- "checkstyle.properties")
- (require 'google-c-style)
- (google-set-c-style)
- (setq c-file-style "Google")
- (c-set-offset 'arglist-intro '++)
- (c-set-offset 'arglist-cont nil)
- (c-set-offset 'arglist-cont-nonempty '++)
- (setq indent-tabs-mode nil)
- (setq c-basic-offset 4))))
-
(defun get-base-dir (path needle)
"Get base directory for PATH using NEEDLE to cut."
(let ((parts (split-string path "/" t)))
@@ -284,14 +255,20 @@
(concat "/" (mapconcat 'identity (seq-take parts (+ index 1)) "/"))
path))))
-;; Chromium hook
+(make-variable-buffer-local 'flycheck-clang-definitions)
+(make-variable-buffer-local 'flycheck-clang-include-path)
+(make-variable-buffer-local 'flycheck-clang-language-standard)
+
(add-hook 'c++-mode-hook
(lambda()
+ (make-local-variable 'flycheck-clang-language-standard)
+ (setq flycheck-clang-language-standard "c++11")
+ (c-set-style "default c++")
+ ;; Chromium hook
(when (and buffer-file-name
(string-match "/chromium/src/" buffer-file-name))
(let ((base (get-base-dir (file-name-directory buffer-file-name) "src")))
(make-local-variable 'flycheck-clang-language-standard)
- (make-local-variable 'flycheck-clang-definitions)
(make-local-variable 'flycheck-clang-include-path)
(setq flycheck-clang-language-standard "c++11"
flycheck-clang-definitions (list "OS_ANDROID")
@@ -299,11 +276,8 @@
(concat base "/out_wam_armv7/Debug/gen")
(concat base "/out_wam_armv7/Release/gen"))))
(require 'google-c-style)
- (c-add-style "Google" google-c-style t))))
-
-;; ofa hook
-(add-hook 'c++-mode-hook
- (lambda()
+ (c-add-style "Google" google-c-style t))
+ ;; ofa hook
(when (and buffer-file-name
(string-match "/mobile/mobile/" buffer-file-name))
(let ((base (get-base-dir (file-name-directory buffer-file-name) "mobile")))
@@ -318,3 +292,27 @@
(require 'google-c-style)
(c-add-style "Google" google-c-style t))))
+;; Opera Java hook
+(add-hook 'java-mode-hook
+ (lambda()
+ (when (and buffer-file-name
+ (string-match "/opera/head" buffer-file-name))
+ (require 'flycheck-android-experimental)
+ (setq flycheck-android-java-checkstyle-jar
+ "../../chromium/src/third_party/checkstyle/checkstyle-6.5-all.jar"
+ flycheck-android-java-checkstyle-path
+ "tools/checkstyle"
+ flycheck-android-java-checkstyle-config
+ "checkstyle-config-android.xml"
+ flycheck-android-java-checkstyle-properties
+ "checkstyle.properties")
+ (require 'google-c-style)
+ (google-set-c-style)
+ (setq c-file-style "Google")
+ (c-set-offset 'arglist-intro '++)
+ (c-set-offset 'arglist-cont nil)
+ (c-set-offset 'arglist-cont-nonempty '++)
+ (setq indent-tabs-mode nil)
+ (setq c-basic-offset 4))))
+
+;;;
diff --git a/emacs-willow b/emacs-willow
index 5b45e49..749759b 100644
--- a/emacs-willow
+++ b/emacs-willow
@@ -4,6 +4,9 @@
;;; Code:
+;; support local packages
+(add-to-list 'load-path "~/.emacs.d/site-lisp/")
+
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
@@ -12,7 +15,7 @@
package-selected-packages '(meson-mode groovy-mode gradle-mode flycheck))
;; use (package-install-selected-packages) to install the ones above
- ;; show matching parentheses (and other characters)
+;; show matching parentheses (and other characters)
(show-paren-mode t)
;; hide toolbar
@@ -81,6 +84,21 @@
(add-to-list 'default-frame-alist '(background-color . "black"))
(add-to-list 'default-frame-alist '(background-mode . "dark"))
+;; Toggle frame width
+(defun toggle-frame-width (frame)
+ "Toggle FRAME width between 100 and 80."
+ (when window-system
+ (let ((width (frame-width frame)))
+ (cond ((eq width 80)
+ (set-frame-width frame 100))
+ (t
+ (set-frame-width frame 80))))))
+
+(defun toggle-selected-frame-width ()
+ "Toggle selected frame width between 100 and 80."
+ (interactive)
+ (toggle-frame-width (selected-frame)))
+
;; default styles
(setq-default
;; no tabs in indentation
@@ -170,8 +188,7 @@
(eval-after-load 'autoinsert
'(define-auto-insert
'("\\.\\(java\\)\\'" . "Java source")
- '((capitalize
- (file-name-base buffer-file-name))
+ '((file-name-base buffer-file-name)
"package " (mapconcat 'identity (member "com" (split-string (file-name-directory buffer-file-name) "/" t)) ".") ";" \n
\n
"class " str " {" \n
@@ -189,6 +206,7 @@
;; keys
(global-set-key (kbd "C-c o") 'ff-find-other-file)
+(global-set-key [?\C-x ?\t] 'toggle-selected-frame-width)
;; flycheck
(require 'flycheck)
@@ -213,7 +231,9 @@
'("common c"
(c-basic-offset . 2)))
+(make-variable-buffer-local 'flycheck-clang-definitions)
(make-variable-buffer-local 'flycheck-clang-include-path)
+(make-variable-buffer-local 'flycheck-clang-language-standard)
(add-hook 'c++-mode-hook
(lambda()
@@ -256,6 +276,14 @@
flycheck-android-java-checkstyle-config
"checkstyle-config-android.xml"
flycheck-android-java-checkstyle-properties
- "checkstyle.properties"))))
+ "checkstyle.properties")
+ (require 'google-c-style)
+ (google-set-c-style)
+ (setq c-file-style "Google")
+ (c-set-offset 'arglist-intro '++)
+ (c-set-offset 'arglist-cont nil)
+ (c-set-offset 'arglist-cont-nonempty '++)
+ (setq indent-tabs-mode nil)
+ (setq c-basic-offset 4))))
;;;
diff --git a/site-lisp/google-c-style.el b/site-lisp/google-c-style.el
new file mode 100644
index 0000000..9bb12c6
--- /dev/null
+++ b/site-lisp/google-c-style.el
@@ -0,0 +1,151 @@
+;;; google-c-style.el --- Google's C/C++ style for c-mode
+
+;; Keywords: c, tools
+
+;; google-c-style.el is Copyright (C) 2008 Google Inc. All Rights Reserved.
+;;
+;; It is free software; you can redistribute it and/or modify it under the
+;; terms of either:
+;;
+;; a) the GNU General Public License as published by the Free Software
+;; Foundation; either version 1, or (at your option) any later version, or
+;;
+;; b) the "Artistic License".
+
+;;; Commentary:
+
+;; Provides the google C/C++ coding style. You may wish to add
+;; `google-set-c-style' to your `c-mode-common-hook' after requiring this
+;; file. For example:
+;;
+;; (add-hook 'c-mode-common-hook 'google-set-c-style)
+;;
+;; If you want the RETURN key to go to the next line and space over
+;; to the right place, add this to your .emacs right after the load-file:
+;;
+;; (add-hook 'c-mode-common-hook 'google-make-newline-indent)
+
+;;; Code:
+
+;; For some reason 1) c-backward-syntactic-ws is a macro and 2) under Emacs 22
+;; bytecode cannot call (unexpanded) macros at run time:
+(eval-when-compile (require 'cc-defs))
+
+;; Wrapper function needed for Emacs 21 and XEmacs (Emacs 22 offers the more
+;; elegant solution of composing a list of lineup functions or quantities with
+;; operators such as "add")
+(defun google-c-lineup-expression-plus-4 (langelem)
+ "Indents to the beginning of the current C expression plus 4 spaces.
+
+This implements title \"Function Declarations and Definitions\"
+of the Google C++ Style Guide for the case where the previous
+line ends with an open parenthese.
+
+\"Current C expression\", as per the Google Style Guide and as
+clarified by subsequent discussions, means the whole expression
+regardless of the number of nested parentheses, but excluding
+non-expression material such as \"if(\" and \"for(\" control
+structures.
+
+Suitable for inclusion in `c-offsets-alist'."
+ (save-excursion
+ (back-to-indentation)
+ ;; Go to beginning of *previous* line:
+ (c-backward-syntactic-ws)
+ (back-to-indentation)
+ (cond
+ ;; We are making a reasonable assumption that if there is a control
+ ;; structure to indent past, it has to be at the beginning of the line.
+ ((looking-at "\\(\\(if\\|for\\|while\\)\\s *(\\)")
+ (goto-char (match-end 1)))
+ ;; For constructor initializer lists, the reference point for line-up is
+ ;; the token after the initial colon.
+ ((looking-at ":\\s *")
+ (goto-char (match-end 0))))
+ (vector (+ 4 (current-column)))))
+
+;;;###autoload
+(defconst google-c-style
+ `((c-recognize-knr-p . nil)
+ (c-enable-xemacs-performance-kludge-p . t) ; speed up indentation in XEmacs
+ (c-basic-offset . 2)
+ (indent-tabs-mode . nil)
+ (c-comment-only-line-offset . 0)
+ (c-hanging-braces-alist . ((defun-open after)
+ (defun-close before after)
+ (class-open after)
+ (class-close before after)
+ (inexpr-class-open after)
+ (inexpr-class-close before)
+ (namespace-open after)
+ (inline-open after)
+ (inline-close before after)
+ (block-open after)
+ (block-close . c-snug-do-while)
+ (extern-lang-open after)
+ (extern-lang-close after)
+ (statement-case-open after)
+ (substatement-open after)))
+ (c-hanging-colons-alist . ((case-label)
+ (label after)
+ (access-label after)
+ (member-init-intro before)
+ (inher-intro)))
+ (c-hanging-semi&comma-criteria
+ . (c-semi&comma-no-newlines-for-oneline-inliners
+ c-semi&comma-inside-parenlist
+ c-semi&comma-no-newlines-before-nonblanks))
+ (c-indent-comments-syntactically-p . t)
+ (comment-column . 40)
+ (c-indent-comment-alist . ((other . (space . 2))))
+ (c-cleanup-list . (brace-else-brace
+ brace-elseif-brace
+ brace-catch-brace
+ empty-defun-braces
+ defun-close-semi
+ list-close-comma
+ scope-operator))
+ (c-offsets-alist . ((arglist-intro google-c-lineup-expression-plus-4)
+ (func-decl-cont . ++)
+ (member-init-intro . ++)
+ (inher-intro . ++)
+ (comment-intro . 0)
+ (arglist-close . c-lineup-arglist)
+ (topmost-intro . 0)
+ (block-open . 0)
+ (inline-open . 0)
+ (substatement-open . 0)
+ (statement-cont
+ .
+ (,(when (fboundp 'c-no-indent-after-java-annotations)
+ 'c-no-indent-after-java-annotations)
+ ,(when (fboundp 'c-lineup-assignments)
+ 'c-lineup-assignments)
+ ++))
+ (label . /)
+ (case-label . +)
+ (statement-case-open . +)
+ (statement-case-intro . +) ; case w/o {
+ (access-label . /)
+ (innamespace . 0))))
+ "Google C/C++ Programming Style.")
+
+;;;###autoload
+(defun google-set-c-style ()
+ "Set the current buffer's c-style to Google C/C++ Programming
+ Style. Meant to be added to `c-mode-common-hook'."
+ (interactive)
+ (make-local-variable 'c-tab-always-indent)
+ (setq c-tab-always-indent t)
+ (c-add-style "Google" google-c-style t))
+
+;;;###autoload
+(defun google-make-newline-indent ()
+ "Sets up preferred newline behavior. Not set by default. Meant
+ to be added to `c-mode-common-hook'."
+ (interactive)
+ (define-key c-mode-base-map "\C-m" 'newline-and-indent)
+ (define-key c-mode-base-map [ret] 'newline-and-indent))
+
+(provide 'google-c-style)
+;;; google-c-style.el ends here