Paste
#81782: Untitled Javascript paste by 124.126.130.24
(add-to-list 'load-path "~/.emacs.d/")
(add-to-list 'load-path "~/.emacs.d/haskell-mode-2.8.0/")
(add-to-list 'load-path "~/.emacs.d/auto-complete-1.3/")
(add-to-list 'load-path "~/.emacs.d/cscope-15.7a/contrib/xcscope")
(add-to-list 'load-path "~/.emacs.d/austin/")
;; (add-to-list 'load-path (expand-file-name "~/.emacs.d/cedet-1.1/common/"))
(load-file "/usr/share/emacs/site-lisp/cedet/common/cedet.el")
;; (load-file "~/.emacs.d/cedet-1.0/common/cedet.el")
(add-to-list 'load-path (expand-file-name "~/.emacs.d/elib-1.0"))
(add-to-list 'load-path "~/.emacs.d/Emacs-PDE-0.2.16/lisp")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/auto-complete-1.3/dict/")
(require 'auto-complete-yasnippet) ;add (2011.2.24 20:39)
(require 'auto-complete-clang)
(require 'xcscope)
(autoload 'adoc-mode "adoc-mode")
(require 'adoc-mode)
(setq ac-clang-flags
(mapcar (lambda (item)(concat "-I" item))
(split-string
"
/usr/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../../include/c++/4.7.0
/usr/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../../include/c++/4.7.0/i686-pc-linux-gnu
/usr/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../../include/c++/4.7.0/backward
/usr/lib/gcc/i686-pc-linux-gnu/4.7.0/include
/usr/local/include
/usr/lib/gcc/i686-pc-linux-gnu/4.7.0/include-fixed
/usr/include
"
)))
(setq ac-modes
(append ac-modes '(org-mode objc-mode jde-mode sql-mode
change-log-mode text-mode
makefile-gmake-mode makefile-bsdmake-mo
autoconf-mode makefile-automake-mode c-mode c++-mode)))
(setq ac-auto-start nil)
(setq ac-quick-help-delay 0.2)
;(ac-set-trigger-key "TAB")
;(define-key ac-mode-map [(tab)] 'auto-complete)
;(define-key ac-mode-map [(control tab)] 'auto-complete)
(defun my-ac-config ()
(setq-default ac-sources '(ac-source-abbrev ac-source-dictionary ac-source-words-in-same-mode-buffers))
(add-hook 'emacs-lisp-mode-hook 'ac-emacs-lisp-mode-setup)
;; (add-hook 'c-mode-common-hook 'ac-cc-mode-setup)
(add-hook 'ruby-mode-hook 'ac-ruby-mode-setup)
(add-hook 'css-mode-hook 'ac-css-mode-setup)
(add-hook 'auto-complete-mode-hook 'ac-common-setup)
(add-hook 'octave-mode-hook 'ac-octave-mode-setup)
(global-auto-complete-mode t))
(defun my-ac-cc-mode-setup ()
(setq ac-sources (append '(ac-source-clang ac-source-yasnippet) ac-sources)))
(add-hook 'c-mode-common-hook 'my-ac-cc-mode-setup)
;; ac-source-gtags
(my-ac-config)
(put 'scroll-left 'disabled nil)
(require 'auto-complete)
(require 'auto-complete-config)
(global-auto-complete-mode t)
(setq-default ac-sources '(ac-source-words-in-same-mode-buffers))
(add-hook 'emacs-lisp-mode-hook (lambda () (add-to-list 'ac-sources 'ac-source-symbols)))
(add-hook 'auto-complete-mode-hook (lambda () (add-to-list 'ac-sources 'ac-source-filename)))
(set-face-background 'ac-candidate-face "lightgray")
(set-face-underline 'ac-candidate-face "darkgray")
(set-face-background 'ac-selection-face "steelblue") ;;; 设置比上面截图中更好看的背景颜色
(define-key ac-completing-map "\M-n" 'ac-next) ;;; 列表中通过按M-n来向下移动
(define-key ac-completing-map "\M-p" 'ac-previous)
(setq ac-auto-start 2)
(setq ac-dwim t)
(define-key ac-mode-map (kbd "TAB") 'auto-complete)
;; (global-set-key (kbd "C-"))
;;;; CC-mode配置 http://cc-mode.sourceforge.net/
(require 'cc-mode)
(c-set-offset 'inline-open 0)
(c-set-offset 'friend '-)
(c-set-offset 'substatement-open 0)
;;;;我的C/C++语言编辑策略
(defun my-c-mode-common-hook()
(setq tab-width 4 indent-tabs-mode nil)
;;; hungry-delete and auto-newline
(c-set-style "GNU")
(c-toggle-auto-hungry-state 1)
;;按键定义
(define-key c-mode-base-map [(control \`)] 'hs-toggle-hiding)
(define-key c-mode-base-map [(return)] 'newline-and-indent)
(define-key c-mode-base-map [(f7)] 'compile)
(define-key c-mode-base-map [(meta \`)] 'c-indent-command)
(define-key c-mode-base-map [(meta ?/)] 'semantic-ia-complete-symbol-menu)
;;预处理设置
(setq c-macro-shrink-window-flag t)
(setq c-macro-preprocessor "cpp")
(setq c-macro-cppflags " ")
(setq c-macro-prompt-flag t)
(setq hs-minor-mode t)
(setq abbrev-mode t)
(setq c-hanging-braces-alist
(append '((brace-list-open)
(brace-list-close)) c-hanging-braces-alist))
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;;;;我的C++语言编辑策略
(defun my-c++-mode-hook()
(setq tab-width 4 indent-tabs-mode nil)
(c-set-style "GNU")
(setq c-hanging-braces-alist
(cons'
(brace-list-close)
c-hanging-braces-alist))
(c++-toggle-auto-newline 1))
;;;; 显示行号:
;(setq column-number-mode t)
;(setq line-number-mode t)
(require 'linum)
(global-linum-mode t)
;;;; 显示时间
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
(display-time)
;;;; 关闭启动画面
(setq inhibit-startup-message t)
;;;;设置大的kill ring
(setq kill-ring-max 150)
;; (progn (normal-top-level-add-subdirs-to-load-path))
(add-to-list 'load-path "~/.emacs.d")
(show-paren-mode t)
(setq show-paren-style 'parentheses)
(mouse-avoidance-mode 'animate)
;; (require 'color-theme)
;; (color-theme-comidia)
;; 共用剪切板
(setq x-select-enable-clipboard t)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(column-number-mode t)
'(display-time-mode t)
'(erc-autojoin-channels-alist (quote (("freenode.net" "#ubuntu-cn"))))
;; '(erc-default-sound "/home/madper/notify.wav")
'(erc-nick "little_imadper_away")
'(erc-play-sound t)
'(erc-port 8001)
'(erc-server "irc.freenode.com")
'(erc-sound-mode t)
'(erc-sound-path (quote ("/home/madper/")))
'(erc-user-full-name "imadper")
'(jde-compiler (quote ("javac" "")))
'(scroll-bar-mode nil)
'(show-paren-mode t)
'(tool-bar-mode nil)
'(tooltip-mode nil))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:inherit nil :stipple nil :background "Black" :foreground "SteelBlue" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 151 :width normal :foundry "unknown" :family "Inconsolata")))))
;;;;;;;;;;;;;;;;;;;;
;; Pool of colors to use when coloring IRC nicks.
(setq erc-colors-list '("green" "blue" "red"
"dark gray" "dark orange"
"dark magenta" "maroon"
"indian red" "forest green"
"midnight blue" "dark violet"))
;; special colors for some people
(setq erc-nick-color-alist '(("John" . "blue")
("Bob" . "red")
))
(defun erc-get-color-for-nick (nick)
"Gets a color for NICK. If NICK is in erc-nick-color-alist, use that color, else hash the nick and use a random color from the pool"
(or (cdr (assoc nick erc-nick-color-alist))
(nth
(mod (string-to-number
(substring (md5 (downcase nick)) 0 6) 16)
(length erc-colors-list))
erc-colors-list)))
(defun erc-put-color-on-nick ()
"Modifies the color of nicks according to erc-get-color-for-nick"
(save-excursion
(goto-char (point-min))
(if (looking-at "<\\([^>]*\\)>")
(let ((nick (match-string 1)))
(put-text-property (match-beginning 1) (match-end 1) 'face
(cons 'foreground-color
(erc-get-color-for-nick nick)))))))
(add-hook 'erc-insert-modify-hook 'erc-put-color-on-nick)
(defun quick-compile ()
"A quick compile funciton for C++"
(interactive)
(compile (concat "clang -g" (buffer-name (current-buffer))))
)
(global-set-key [(f9)] 'quick-compile) ;;快捷键F9
;; 没有任中任何区域时,注释、反注释作用于当前行,否则作用于
;; 选中区域
(defadvice comment-or-uncomment-region (before slickcomment activate compile)
"When called interactively with no active region, toggle comment on current line instead."
(interactive
(if mark-active (list (region-beginning) (region-end))
(list (line-beginning-position)
(line-beginning-position 2)))))
(global-set-key (kbd "C-c C-c") 'comment-or-uncomment-region)
(defun comment-dwim-line (&optional arg)
"Replacement for the comment-dwim command.
If no region is selected and current line is not blank and we are not at the end of the line,
then comment current line.
Replaces default behaviour of comment-dwim, when it inserts comment at the end of the line."
(interactive "*P")
(comment-normalize-vars)
(if (and (not (region-active-p)) (not (looking-at "[ \t]*$")))
(comment-or-uncomment-region (line-beginning-position) (line-end-position))
(comment-dwim arg)))
(global-set-key (kbd "M-;") 'comment-dwim-line)
;;删除行的定义
(defadvice kill-ring-save (before slickcopy activate compile)
;When called interactively with no active region, copy a single line instead.”
(interactive
(if mark-active (list (region-beginning) (region-end))
(list (line-beginning-position)
(line-beginning-position 2)))))
(defadvice kill-region (before slickcut activate compile)
;When called interactively with no active region, kill a single line instead.”
(interactive
(if mark-active (list (region-beginning) (region-end))
(list (line-beginning-position)
(line-beginning-position 2)))))
(global-set-key [(control ?\.)] 'ska-point-to-register)
(global-set-key [(control ?\,)] 'ska-jump-to-register)
(defun ska-point-to-register()
"Store cursorposition _fast_ in a register.
Use ska-jump-to-register to jump back to the stored
position."
(interactive)
(setq zmacs-region-stays t)
(point-to-register 8))
(defun ska-jump-to-register()
"Switches between current cursorposition and position
that was stored with ska-point-to-register."
(interactive)
(setq zmacs-region-stays t)
(let ((tmp (point-marker)))
(jump-to-register 8)
(set-register 8 tmp)))
(windmove-default-keybindings)
(setq windmove-wrap-around t)
(global-set-key (kbd "<f6>") 'smart-compile)
(defun smart-compile-is-root-dir(try-dir)
(or
;; windows root dir for a driver or Unix root
(string-match "\\`\\([a-zA-Z]:\\)?/$" try-dir)
;; tramp root-dir
(and (featurep 'tramp)
(string-match (concat tramp-file-name-regexp ".*:/$") try-dir))))
(defun smart-compile-throw-final-path(try-dir)
(cond
;; tramp root-dir
((and (featurep 'tramp)
(string-match tramp-file-name-regexp try-dir))
(with-parsed-tramp-file-name try-dir foo
foo-localname))
(t try-dir)))
(defun smart-compile-find-make-dir( try-dir)
"return a directory contain makefile. try-dir is absolute path."
(if (smart-compile-is-root-dir try-dir)
nil ;; return nil if failed to find such directory.
(let ((candidate-make-file-name `("GNUmakefile" "makefile" "Makefile")))
(or (catch 'break
(mapc (lambda (f)
(if (file-readable-p (concat (file-name-as-directory try-dir) f))
(throw 'break (smart-compile-throw-final-path try-dir))))
candidate-make-file-name)
nil)
(smart-compile-find-make-dir
(expand-file-name (concat (file-name-as-directory try-dir) "..")))))))
(defun wcy-tramp-compile (arg-cmd)
"reimplement the remote compile."
(interactive "scompile:")
(with-parsed-tramp-file-name default-directory foo
(let* ((key (format "/plink:%s@%s:" foo-user foo-host))
(passwd (password-read "PASS:" key))
(cmd (format "plink %s -l %s -pw %s \"(cd %s ; %s)\""
foo-host foo-user
passwd
(file-name-directory foo-localname)
arg-cmd)))
(password-cache-add key passwd)
(save-some-buffers nil nil)
(compile-internal cmd "No more errors")
;; Set comint-file-name-prefix in the compilation buffer so
;; compilation-parse-errors will find referenced files by ange-ftp.
(with-current-buffer compilation-last-buffer
(set (make-local-variable 'comint-file-name-prefix)
(format "/plink:%s@%s:" foo-user foo-host))))))
(defun smart-compile-test-tramp-compile()
(or (and (featurep 'tramp)
(string-match tramp-file-name-regexp (buffer-file-name))
(progn
(if (not (featurep 'tramp-util)) (require 'tramp-util))
'wcy-tramp-compile))
'compile))
(defun smart-compile-get-local-file-name(file-name)
(if (and
(featurep 'tramp)
(string-match tramp-file-name-regexp file-name))
(with-parsed-tramp-file-name file-name foo
foo-localname)
file-name))
(defun smart-compile ()
(interactive)
(let* ((compile-func (smart-compile-test-tramp-compile))
(dir (smart-compile-find-make-dir (expand-file-name "."))))
(funcall compile-func
(if dir
(concat "make -C " dir (if (eq compile-func 'tramp-compile) "&" ""))
(concat
(cond
((eq major-mode 'c++-mode) "g++ -g -o ")
((eq major-mode 'c-mode) "gcc -g -o "))
(smart-compile-get-local-file-name (file-name-sans-extension (buffer-file-name)))
" "
(smart-compile-get-local-file-name (buffer-file-name)))))))
(put 'set-goal-column 'disabled nil)
(put 'downcase-region 'disabled nil)
;; 快速编译
;;一键快速编译 C++-mode
(defun quick-compile ()
"A quick compile funciton for C++"
(interactive)
(compile (concat "clang++ -g " (buffer-name (current-buffer))))
)
(global-set-key [(f9)] 'quick-compile) ;;快捷键F9
;;;加载auto-header.el文件,自动添加文件头
(add-to-list 'load-path "~/.emacs.d/elisp")
(require 'auto-header)
;;加载auto-header.el文件,自动添加文件头
(require 'auto-header)
;; 设置文件头中的姓名
(setq header-full-name "madper")
;; 设置我的邮箱
(setq header-email-address "bbboson@gmail.com")
;; 设置每次保存时要更新的项目
(setq header-update-on-save '(filename
modified
counter
copyright
))
;; 设置文件头的显示格式
(setq header-field-list '(
filename ;;文件名
blank ;空行,下同
copyright ;版权
version
author ;作者
created ;创建人
blank
description ;描述
blank
;;modified_by ;更改者
;;blank
;;status ;状态,是否发布
;;update ;更新
;;blank
))
(global-set-key (kbd "C-c d") 'kid-star-dict)
(defun kid-star-dict ()
(interactive)
(let ((begin (point-min))
(end (point-max)))
(if mark-active
(setq begin (region-beginning)
end (region-end))
(save-excursion
(backward-word)
(mark-word)
(setq begin (region-beginning)
end (region-end))))
;; 有时候 stardict 会很慢,所以在回显区显示一点东西
;; 以免觉得 Emacs 在干什么其他奇怪的事情。
(message "searching for %s ..." (buffer-substring begin end))
(tooltip-show
(shell-command-to-string
(concat "sdcv -n "
(buffer-substring begin end))))))
;; 快速include一个系统/用户头文件
(mapc
(lambda (mode)
(define-abbrev-table mode '(("incy" "" skeleton-include 1)))
(define-abbrev-table mode '(("incz" "" skeleton-include-user 1))))
'(c-mode-abbrev-table c++-mode-abbrev-table))
;; 输入incy,可以自动提示输入文件名称,可以自动补全.
(define-skeleton skeleton-include
"产生#include<>" "" > "#include <"
(completing-read "包含系统头文件: "
(mapcar #'(lambda (f) (list f ))
(apply 'append (mapcar #'(lambda (dir) (directory-files dir))
system-head-file-dir)))) ">\n")
(define-skeleton skeleton-include-user
"产生#include\"\"" "" > "#include \""
(completing-read "包含用户头文件: "
(mapcar #'(lambda (f) (list f ))
(apply 'append (mapcar #'(lambda (dir) (directory-files dir))
user-head-file-dir)))) "\"\n")
(defun c/c++-hightligh-included-files ()
(interactive)
(when (or (eq major-mode 'c-mode)
(eq major-mode 'c++-mode))
(save-excursion
(goto-char (point-min))
;; remove all overlay first
(mapc (lambda (ov) (if (overlay-get ov 'c/c++-hightligh-included-files)
(delete-overlay ov)))
(overlays-in (point-min) (point-max)))
(while (re-search-forward "^[ \t]*#include[ \t]+[\"<]\\(.*\\)[\">]" nil t nil)
(let* ((begin (match-beginning 1))
(end (match-end 1))
(ov (make-overlay begin end)))
(overlay-put ov 'c/c++-hightligh-included-files t)
(overlay-put ov 'keymap c/c++-hightligh-included-files-key-map)
(overlay-put ov 'face 'underline))))))
;; 这不是一个好办法,也可以把它加载到c-mode-hook or c++-mode-hook中
(setq c/c++-hightligh-included-files-timer (run-with-idle-timer 0.5 t 'c/c++-hightligh-included-files))
(require 'yasnippet-bundle)
;;outPut the screen with html;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'htmlize)
;;;;;;;;;;;;;;;;;;;;;;;;;;Orgz-mode;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq load-path (cons "~/lib/emacs-lisp/org-7.3/lisp" load-path))
(setq load-path (cons "~/lib/emacs-lisp/org-7.3/contrib/lisp" load-path))
(require 'org-install)
(require 'org-publish)
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(add-hook 'org-mode-hook 'turn-on-font-lock)
(add-hook 'org-mode-hook
(lambda () (setq truncate-lines nil)))
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)
(setq org-log-done 'time)
(setq org-log-done 'note)
(defun org-summary-todo (n-done n-not-done)
"Swith entry to DONE when all subentries are done, to TODO otherwise."
(let (org-log-done org-log-states) ; turn off logging.
(org-todo (if (= n-not-done 0) "DONE" "TODO"))))
;;;;;;;;;;;;;;;;;;;;;;;;;;perl;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'load-path "~/.emacs.d/Emacs-PDE-0.2.16/lisp/")
(load "pde-load")
(add-hook 'cperl-mode-hook
(lambda()
(require 'perl-completion)
(perl-completion-mode t)))
(add-hook 'cperl-mode-hook
(lambda ()
(when (require 'auto-complete nil t) ; no error whatever auto-complete.el is not installed.
(auto-complete-mode t)
(make-variable-buffer-local 'ac-sources)
(setq ac-sources
'(ac-source-perl-completion)))))
;;;;;;;;;;;;;;;cedet
(semantic-load-enable-minimum-features)
(semantic-load-enable-code-helpers)
(semantic-load-enable-guady-code-helpers)
(semantic-load-enable-excessive-code-helpers)
(semantic-load-enable-semantic-debugging-helpers)
(global-set-key (kbd "<f12>") 'semantic-ia-fast-jump)
(global-set-key [S-f12]
(lambda ()
(interactive)
(if (ring-empty-p (oref semantic-mru-bookmark-ring ring))
(error "Semantic Bookmark ring is currently empty"))
(let* ((ring (oref semantic-mru-bookmark-ring ring))
(alist (semantic-mrub-ring-to-assoc-list ring))
(first (cdr (car alist))))
(if (semantic-equivalent-tag-p (oref first tag)
(semantic-current-tag))
(setq first (cdr (car (cdr alist)))))
(semantic-mrub-switch-tags first))))
(global-ede-mode 1)
;; global-srecode-minor-mode 1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'c-mode-hook
(lambda ()
(auto-fill-mode 1)
(set (make-local-variable 'fill-nobreak-predicate)
(lambda ()
(not (eq (get-text-property (point) 'face)
'font-lock-comment-face))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;markdown!;;;;;;;;;;;;;;;
(autoload 'markdown-mode "markdown-mode.el"
"Major mode for editing Markdown files" t)
(setq auto-mode-alist
(cons '("\.md" . markdown-mode) auto-mode-alist))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun comment-or-uncomment-region-or-line ()
"Like comment-or-uncomment-region, but if there's no mark \(that means no
region\) apply comment-or-uncomment to the current line"
(interactive)
(if (not mark-active)
(comment-or-uncomment-region
(line-beginning-position) (line-end-position))
(if (< (point) (mark))
(comment-or-uncomment-region (point) (mark))
(comment-or-uncomment-region (mark) (point)))))
(global-set-key (kbd "C-c C-;") 'comment-or-uncomment-region-or-line)
;;;;;;;;;;;;;;ruby;;;;;;;;;;;
(add-to-list 'load-path "/path/to/test-case-mode")
(autoload 'test-case-mode "test-case-mode" nil t)
(autoload 'enable-test-case-mode-if-test "test-case-mode")
(autoload 'test-case-find-all-tests "test-case-mode" nil t)
(autoload 'test-case-compilation-finish-run-all "test-case-mode")
(autoload 'ruby-mode "ruby-mode"
"Mode for editing ruby source files")
(setq interpreter-mode-alist (append '(("ruby" . ruby-mode))
interpreter-mode-alist))
(autoload 'run-ruby "inf-ruby"
"Run an inferior Ruby process")
(autoload 'inf-ruby-keys "inf-ruby"
"Set local key defs for inf-ruby in ruby-mode")
(add-hook 'ruby-mode-hook
'(lambda ()
(inf-ruby-keys)
))
;ruby RSence;;;;;
(setq rsense-home "/opt/rsense-0.3")
(add-to-list 'load-path (concat rsense-home "/etc"))
(require 'rsense)
(add-hook 'ruby-mode-hook
(lambda ()
(add-to-list 'ac-sources 'ac-source-rsense-method)
(add-to-list 'ac-sources 'ac-source-rsense-constant)))
;;;;;;;;;;;;;;;;;;;fffffffffffffffffff;;;;;;;;;;;;;;;;;
(require 'ace-jump-mode)
(define-key global-map (kbd "C-c SPC") 'ace-jump-mode)
;;;;;;;;;;;;;;;;;;;anything;;;;;;;;;;;;;;;;;
(require 'anything)
(require 'anything-match-plugin)
;;;;;;;;;;;;;;;;;;;;;;octave-mode;;;;;;;
(require 'octave-mod)
(load-file "~/.emacs.d/auto-complete-1.3/ac-octave.el")
(autoload 'run-octave "octave-inf" nil t)
(add-hook 'octave-mode-hook
(lambda ()
(abbrev-mode 1)
(auto-fill-mode 1)
(if (eq window-system 'x)
(font-lock-mode 1))))
(autoload 'octave-mode "octave-mod" nil t)
(setq auto-mode-alist
(cons '("\\.m$" . octave-mode) auto-mode-alist))
(require 'ac-octave)
(defun ac-octave-mode-setup ()
(setq ac-sources '(ac-source-octave)))
(add-hook 'octave-mode-hook
'(lambda () (ac-octave-mode-setup)))
(defun my-inferior-octave-listening-p ()
"True if inferior octave is running and ready to receive input.
Required for eldoc and other functions that try to get
information from the running Octave, so they don't freeze emacs
when Octave is busy doing something else."
(and (boundp 'inferior-octave-process)
inferior-octave-process
(not inferior-octave-receive-in-progress)
(eq (process-status inferior-octave-process) 'run)))
(defun my-octave-complete-symbol ()
"Perform completion on Octave symbol preceding point.
Compare that symbol against Octave's reserved words and builtin
variables. This is like the default Octave completer function,
except that it also completes on structure fields."
(interactive)
;; This code taken from lisp-complete-symbol
(let* ((end (point))
(beg (save-excursion (backward-sexp 1) (point)))
(string (buffer-substring-no-properties beg end))
(completion (try-completion string octave-completion-alist)))
(if completion
(setq completion-list octave-completion-alist)
(when (my-inferior-octave-listening-p)
(setq completion-list
(save-excursion
(inferior-octave-send-list-and-digest
(list (format "completion_matches(\"%s\");\n" string)))
inferior-octave-output-list))
(when completion-list
(setq completion
(try-completion string inferior-octave-output-list)))))
(cond ((eq completion t)) ; ???
((null completion)
(message "Can't find completion for \"%s\"" string))
((not (string= string completion))
(delete-region beg end)
(goto-char beg)
(insert completion))
(t
(let ((list (all-completions string completion-list))
(conf (current-window-configuration)))
;; Taken from comint.el
(message "Making completion list...")
(with-output-to-temp-buffer "*Completions*"
(display-completion-list list))
(message "Hit space to flush")
(let (key first)
(if (save-excursion
(set-buffer (get-buffer "*Completions*"))
(setq key (read-key-sequence nil)
first (aref key 0))
(and (consp first) (consp (event-start first))
(eq (window-buffer (posn-window (event-start
first)))
(get-buffer "*Completions*"))
(eq (key-binding key) 'mouse-choose-completion)))
(progn
(mouse-choose-completion first)
(set-window-configuration conf))
(if (eq first ?\ )
(set-window-configuration conf)
(setq unread-command-events
(listify-key-sequence key))))))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;indent;;;;;;;;;;;
(defun indent-buffer ()
"indent correct buffer by GNU indent!"
(interactive)
(set-file-name-coding-system 'unix)
(save-buffer (current-buffer))
(call-process "indent" nil nil nil (buffer-name (current-buffer)))
(revert-buffer t t)
(indent-region (point-min) (point-max))
)
(global-set-key (kbd"C-c C-'") 'indent-buffer)
;;;;;;;;;;;;;;;;;;;;;weather;;;;;;;;;;;;;;;
;; (require 'google-weather)
;;;;;;;;;;;;;;;;;;;;;;weibo;;;;;;;;;;;;;;;
(require 'weibo)