summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuo Jinghua <sunmoon1997@gmail.com>2010-01-09 20:04:18 +0800
committerLuo Jinghua <sunmoon1997@gmail.com>2010-01-09 20:04:18 +0800
commite625d9cc3fc27b0b9855ebc183d638ba034490af (patch)
tree2cb8b830eeb84ba5ad997e30aba6a4156e01bc52
parent452086c8a686abe2dd38acd63e8f0907922aca04 (diff)
separate auto-complete and cc-style setups
-rw-r--r--emacs.d/lisp/setup-auto-complete.el173
-rw-r--r--emacs.d/lisp/setup-cc-styles.el110
2 files changed, 283 insertions, 0 deletions
diff --git a/emacs.d/lisp/setup-auto-complete.el b/emacs.d/lisp/setup-auto-complete.el
new file mode 100644
index 0000000..79bdfd5
--- /dev/null
+++ b/emacs.d/lisp/setup-auto-complete.el
@@ -0,0 +1,173 @@
+;;; setup-auto-complete.el --- setup auto-complete mode
+
+;; Copyright (C) 2010 Luo Jinghua <sunmoon1997@gmail.com>
+
+;; Author: Luo Jinghua <sunmoon1997@gmail.com>>
+;; Keywords: c
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+;;auto-complete
+(require 'auto-complete)
+(require 'auto-complete-config)
+(require 'yasnippet)
+
+(global-auto-complete-mode t)
+(setq ac-auto-start 2)
+
+(define-key ac-complete-mode-map "\t" 'ac-expand)
+(define-key ac-complete-mode-map "\r" 'ac-complete)
+(define-key ac-complete-mode-map (kbd "M-j") 'ac-complete)
+(define-key ac-complete-mode-map (kbd "M-n") 'ac-next)
+(define-key ac-complete-mode-map (kbd "M-p") 'ac-previous)
+
+(setq ac-dwim t)
+(setq ac-candidate-menu-height 20)
+(setq ac-candidate-max ac-candidate-menu-height)
+
+(set-default 'ac-sources
+ '(ac-source-semantic
+ ac-source-yasnippet
+ ac-source-abbrev
+ ac-source-words-in-buffer
+ ac-source-words-in-all-buffer
+ ac-source-imenu
+ ac-source-files-in-current-dir
+ ac-source-filename))
+;;(setq ac-modes ac+-modes)
+
+(setq ac-trigger-commands '(self-insert-command autopair-insert-or-skip-quote))
+
+(defun ac-settings-4-lisp ()
+ "Auto complete settings for lisp mode."
+ (setq ac-omni-completion-sources '(("require\s+'" ac-source-emacs-lisp-features)
+ ("load\s+\"" ac-source-emacs-lisp-features)))
+ (setq ac-sources
+ '(ac-source-yasnippet
+ ac-source-symbols
+ ac-source-semantic
+ ac-source-abbrev
+ ac-source-words-in-buffer
+ ac-source-words-in-all-buffer
+ ac-source-imenu
+ ac-source-files-in-current-dir
+ ac-source-filename)))
+
+(defun ac-settings-4-java ()
+ (setq ac-omni-completion-sources (list (cons "\\." '(ac-source-semantic))
+ (cons "->" '(ac-source-semantic))))
+ (setq ac-sources
+ '(ac-source-semantic
+ ac-source-yasnippet
+ ac-source-abbrev
+ ac-source-words-in-buffer
+ ac-source-words-in-all-buffer
+ ac-source-files-in-current-dir
+ ac-source-filename)))
+
+(defun ac-settings-4-c ()
+ (setq ac-omni-completion-sources (list (cons "\\." '(ac-source-semantic))
+ (cons "->" '(ac-source-semantic))))
+ (setq ac-sources
+ '(ac-source-semantic
+ ac-source-yasnippet
+ ac-source-c-keywords
+ ac-source-abbrev
+ ac-source-words-in-buffer
+ ac-source-words-in-all-buffer
+ ac-source-files-in-current-dir
+ ac-source-filename)))
+
+(defun ac-settings-4-cpp ()
+ (setq ac-omni-completion-sources
+ (list (cons "\\." '(ac-source-semantic))
+ (cons "->" '(ac-source-semantic))))
+ (setq ac-sources
+ '(ac-source-semantic
+ ac-source-yasnippet
+ ac-source-c++-keywords
+ ac-source-abbrev
+ ac-source-words-in-buffer
+ ac-source-words-in-all-buffer
+ ac-source-files-in-current-dir
+ ac-source-filename)))
+
+(defun ac-settings-4-python ()
+ (setq ac-omni-completion-sources
+ '(("\\." ac-source-ropemacs)))
+ (setq ac-sources
+ '(ac-source-semantic
+ ac-source-yasnippet
+ ac-source-abbrev
+ ac-source-words-in-buffer
+ ac-source-words-in-all-buffer
+ ac-source-files-in-current-dir
+ ac-source-filename)))
+
+(defun ac-settings-4-text ()
+ (setq ac-sources
+ '(;;ac-source-semantic
+ ac-source-yasnippet
+ ac-source-abbrev
+ ac-source-words-in-buffer
+ ac-source-words-in-all-buffer
+ ac-source-imenu)))
+
+(defun ac-settings-4-eshell ()
+ (setq ac-sources
+ '(;;ac-source-semantic
+ ac-source-yasnippet
+ ac-source-abbrev
+ ac-source-words-in-buffer
+ ac-source-words-in-all-buffer
+ ac-source-files-in-current-dir
+ ac-source-filename
+ ac-source-symbols
+ ac-source-imenu)))
+
+(defun ac-settings-4-ruby ()
+ (setq ac-omni-completion-sources
+ (list (cons "\\." '(ac-source-rcodetools))
+ (cons "::" '(ac-source-rcodetools)))))
+
+(defun ac-settings-4-html ()
+ (setq ac-sources
+ '(ac-source-semantic
+ ac-source-yasnippet
+ ac-source-abbrev
+ ac-source-words-in-buffer
+ ac-source-words-in-all-buffer
+ ac-source-files-in-current-dir
+ ac-source-filename)))
+
+(dolist (hook (list 'lisp-mode-hook 'emacs-lisp-mode-hook 'lisp-interaction-mode-hook
+ 'svn-log-edit-mode))
+ (add-hook hook 'ac-settings-4-lisp))
+
+(add-hook 'java-mode-hook 'ac-settings-4-java)
+(add-hook 'c-mode-hook 'ac-settings-4-c)
+(add-hook 'c++-mode-hook 'ac-settings-4-cpp)
+(add-hook 'python-mode-hook 'ac-settings-4-python)
+(add-hook 'text-mode-hook 'ac-settings-4-text)
+(add-hook 'eshell-mode-hook 'ac-settings-4-eshell)
+(add-hook 'html-mode-hook 'ac-settings-4-html)
+
+(provide 'setup-auto-complete)
+;;; setup-auto-complete.el ends here
diff --git a/emacs.d/lisp/setup-cc-styles.el b/emacs.d/lisp/setup-cc-styles.el
new file mode 100644
index 0000000..ffc7737
--- /dev/null
+++ b/emacs.d/lisp/setup-cc-styles.el
@@ -0,0 +1,110 @@
+;;; setup-cc-styles.el --- setup various programing styles
+
+;; Copyright (C) 2010 Luo Jinghua
+
+;; Author: Luo Jinghua <sunmoon1997@gmail.com>
+;; Keywords: c
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+;;----------------------------------------------------------------------------
+(setq tab-width 4)
+;;(setq c-basic-offset 4)
+;;(setq c-hanging-comment-ender-p nil)
+;;(setq-default indent-tabs-mode nil)
+
+;; define a new indentation style
+(require 'cc-styles)
+(add-to-list 'c-style-alist
+ '("ljh"
+ (indent-tabs-mode nil)
+ (c-basic-offset . 4)
+ (c-comment-only-line-offset . 0)
+ (c-offsets-alist . ((statement-block-intro . +)
+ (knr-argdecl-intro . 0)
+ (substatement-open . 0)
+ (substatement-label . 0)
+ (label . 1)
+ (statement-cont . +)
+ (arglist-intro . c-lineup-arglist-intro-after-paren)
+ (arglist-close . c-lineup-arglist)
+ ))
+ )
+ )
+
+(add-to-list 'c-style-alist
+ '("tables"
+ (c-basic-offset . 8)
+ (c-comment-only-line-offset . 0)
+ (c-offsets-alist . ((statement-block-intro . +)
+ (knr-argdecl-intro . 0)
+ (substatement-open . 0)
+ (substatement-label . 0)
+ (label . 1)
+ (statement-cont . +)
+ (inline-open 0)
+ (innamespace . 0)
+ (arglist-intro . c-lineup-arglist-intro-after-paren)
+ (arglist-close . c-lineup-arglist)
+ ))
+ )
+ )
+
+(add-hook 'c-mode-common-hook
+ (function
+ (lambda ()
+;; (c-set-style "ljh")
+ (hl-line-mode t)
+ (linum-mode)
+ )))
+(add-hook 'c++-mode-hook
+ (function
+ (lambda ()
+ (c-set-style "ljh")
+ (hl-line-mode t)
+ )))
+
+(add-hook 'python-mode-hook
+ (function
+ (lambda ()
+ (hl-line-mode t)
+ (linum-mode)
+ )))
+
+(defun gstreamer-c-mode ()
+ "C mode with adjusted defaults for use with GStreamer."
+ (interactive)
+ (c-mode)
+ (c-set-style "K&R")
+ (setq c-basic-offset 2))
+
+(setq auto-mode-alist (cons '("gst.*/.*\\.[ch]$" . gstreamer-c-mode)
+ auto-mode-alist))
+
+(defun ljh-c-mode ()
+ "C mode with adjusted defaults for myself."
+ (interactive)
+ (c-mode)
+ (c-set-style "ljh"))
+(setq auto-mode-alist (cons '("milkway.*/.*\\.[ch]$" . ljh-c-mode)
+ auto-mode-alist))
+
+(provide 'setup-cc-styles)
+;;; setup-cc-styles.el ends here