博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

心在天山

Software design is a craft worth all the intelligence, creativity, and passion you can muster -- Eric S. Raymond (The Art of Unix Programming)
  lgfang.cublog.cn

关于作者
姓名:方伦钢
职业:程序员
年龄:
位置:
个性介绍:
|| << >> ||
我的分类


my .emacs
;;; Created:  Fang lungang 2004
;;; Modified: Fang lungang 05/16/2009 23:32>

;;; This configure file is for GNU Emacs 21, 22 and 23 on both Windows and
;;; Linux.

;;; ------ begin Personal ------
(setq user-full-name "Fang lungang" ange-ftp-default-user "lungangfang")

;;; viper or not
(setq viper-inhibit-startup-message t)
(setq viper-expert-level '5)
(when nil ; for those who miss vi, change "nil" to "t"
(setq viper-mode t)
(require 'viper))

;;; world time I care. automatically pick one of following style.
(setq zoneinfo-style-world-list
'(("Asia/Shanghai" "China")
("US/Eastern" "Westford")
("US/Central" "IH")))
(setq legacy-style-world-list
'(("CST-8" "China")
("EST5EDT" "Westford")
("CST6CDT" "IH")))
;;; ------ end Personal ------

;;; ------ begin Site ------
;;; paths
(setq my-emacs-base (file-name-as-directory "~/.emacs.d")
my-extension-path (file-name-as-directory "~/.emacs.d/extensions")
my-personal-path (file-name-as-directory
"~/My Documents/homepage/source/personal/"))

;;; load path
(add-to-list 'load-path my-extension-path)
(add-to-list 'load-path my-emacs-base)

(when (eq system-type 'windows-nt)
;;; exec path
(setq exec-path (append '("c:/share/MPlayer-1.0rc2")
'("c:/cygwin/bin")
'("c:/cygwin/usr/local/bin")
exec-path))
;;; woman path
(setq woman-manpath '("c:/cygwin/usr/local/man"
"c:/cygwin/usr/share/man"
"c:/cygwin/usr/man"
"c:/cygwin/usr/ssl/man"
"c:/cygwin/usr/share/qt3/doc/man"
"c:/cygwin/usr/X11R6/man"
))
)

;;; fontset
(when window-system
(if (eq system-type 'windows-nt)
(create-fontset-from-fontset-spec
(concat
"-outline-Consolas-normal-r-normal-*-18-*-*-*-c-*-fontset-lgfang,"
;; "-outline-Courier New-normal-r-normal-normal-*-*-96-96-c-*-fontset-lgfang,"
"chinese-gb2312:-outline-新宋体-normal-r-normal-*-*-*-96-96-c-*-iso10646-1,"
"chinese-gb18030:-outline-新宋体-normal-r-normal-*-*-*-96-96-c-*-iso10646-1"))
(create-fontset-from-fontset-spec
(concat
;;"-B&H-LucidaTypewriter-normal-normal-normal-*-14-*-*-*-m-90-fontset-lgfang")))
;;"-adobe-courier-medium-r-normal--17-120-100-100-m-100-fontset-lgfang")))
"-unknown-文泉驿等宽正黑-normal-normal-normal-*-18-*-*-*-*-*-fontset-lgfang,"
"chinese-gb2312:-unknown-文泉驿等宽正黑-normal-normal-normal-*-*-*-*-*-*-0-iso10646-1,"
"chinese-gb18030:-unknown-文泉驿等宽正黑-normal-normal-normal-*-*-*-*-*-*-0-iso10646-1")))
(add-to-list 'default-frame-alist '(font . "fontset-lgfang"))
(set-default-font "fontset-lgfang"))

;;; frame position/size; emacs22 or later supports 'emacs --fullscreen'
(setq initial-frame-alist '((top . 1) (left . 1) (width . 100) (height . 32)))

;;; geo info
(setq calendar-latitude 36.06
calendar-longitude 120.27
calendar-location-name "QingDao")
;; (setq calendar-latitude 39.92
;; calendar-longitude 116.46
;; calendar-location-name "BeiJing")
;;; ------ end Site ------

;;; ------ begin LanguageEnvironment ------
(if (>= emacs-major-version 23)
(set-language-environment 'Chinese-GB18030)
(set-language-environment 'Chinese-GB))

;;; ------ end LanguageEnvironment ------

;;; ------ begin Keys ------
(define-key global-map (kbd "M-/") 'hippie-expand)
(define-key global-map (kbd "C-x C-b") 'ibuffer)
(define-key global-map (kbd "M-g c") 'move-to-column)
(define-key global-map (kbd "M-g f") 'ffap)
(define-key global-map (kbd "M-g w") 'webjump)
(define-key global-map (kbd "M-g ]") 'my-goto-page)
(define-key global-map (kbd "M-,") 'hs-toggle-hiding)
(define-key global-map (kbd "M-.") 'my-toggle-selective-display)
(define-key global-map (kbd "C-x c l") 'org-store-link)
(define-key global-map (kbd "C-x c a") 'org-agenda)

;; f1: help, maybe useful when c-h not available
(define-key global-map [f2] 'global-whitespace-mode)
;;(define-key global-map [f2] 'speedbar-get-focus)
;; f3/f4: define keyboard macros
(define-key global-map [f5] 'my-recentf-open)
(define-key global-map [f6] 'my-whitespace-cleanup)
(define-key global-map [f7] 'flyspell-mode)
(define-key global-map [f8] 'flyspell-prog-mode)
(define-key global-map [f9] 'my-mode-line-all)
(define-key global-map [f10] 'ido-goto-symbol)
(define-key global-map [f11] 'org-remember)
;; f12 : reserved for twm
;;; ------ end keys ------

;;; ------ begin General ------

(require 'ascii nil t)

;;; abbrev
(setq-default abbrev-mode t save-abbrevs nil)
(load "abbrev-defs" t nil nil)

;;; appointment
(require 'appt nil t)
(setq appt-display-format 'window
appt-audible t
appt-display-mode-line t
appt-display-duration t
appt-message-warning-time 12)
(when (> emacs-major-version 21) (appt-activate 1))

;;; asm mode
(setq-default asm-comment-char 35) ; 35 -> ascii code for '#' in DEC

;;; auto-complete
(when (and (> emacs-major-version 21)
(require 'auto-complete nil t))
(require 'auto-complete-semantic nil t)

(global-auto-complete-mode t)

(define-key ac-complete-mode-map "\C-n" 'ac-next)
(define-key ac-complete-mode-map "\C-p" 'ac-previous)
;; (define-key ac-complete-mode-map "\t" 'ac-complete)
;; (define-key ac-complete-mode-map "\r" nil)

(setq ac-dwim t)

(setq ac-auto-start 3 ; start ac after 3 chars

;; modes that automatically startup auto-complete-mode
ac-modes '(
asm-mode
c++-mode
c-mode
cc-mode
emacs-lisp-mode
java-mode
lisp-interaction-mode
lisp-mode
makefile-mode
makefile-gmake-mode
org-mode
cperl-mode
python-mode
sh-mode
tcl-mode
muse-mode
org-mode
text-mode
))

;; ;; do not start ac automatically
;; (setq ac-auto-start nil)
;; (global-set-key "\M-/" 'ac-start)

;; common source
(setq-default ac-sources
'(ac-source-imenu
ac-source-abbrev
ac-source-words-in-buffer
ac-source-files-in-current-dir
ac-source-filename
))

;; mode specific sources

;; c++
(defconst ac-c++-keywords
(sort
(list "and" "bool" "compl" "do" "export" "goto" "namespace"
"or_eq" "return" "struct" "try" "using" "xor" "and_eq"
"break" "const" "double" "extern" "if" "new" "private"
"short" "switch" "typedef" "virtual" "xor_eq" "asm" "case"
"const_cast" "dynamic_cast" "false" "inline" "not"
"protected" "signed" "template" "typeid" "void" "auto"
"catch" "continue" "else" "float" "int" "not_eq" "public"
"sizeof" "this" "typename" "volatile" "bitand" "char"
"default" "enum" "for" "long" "operator" "register"
"static" "throw" "union" "wchar_t" "bitor" "class" "delete"
"explicit" "friend" "mutable" "or" "reinterpret_cast"
"static_cast" "true" "unsigned" "while" )
#'(lambda (a b) (> (length a) (length b)))))

(defvar ac-source-c++
'((candidates
. (lambda ()
(all-completions ac-target ac-c++-keywords))))
"Source for c++ keywords.")

(add-hook 'c++-mode-hook (lambda ()
(add-to-list 'ac-sources 'ac-source-c++)))

;; lisp
(dolist (mode (list 'emacs-lisp-mode-hook
'lisp-interaction-mode))
(add-hook mode
'(lambda () (add-to-list 'ac-sources 'ac-source-symbols))))

;; perl
(defconst ac-perl-builtin-functions
'( "abs" "exec" "glob" "order" "seek" "symlink" "accept" "exists"
"gmtime" "our" "seekdir" "syscall" "alarm" "exit" "goto"
"pack" "select" "sysopen" "atan" "exp" "grep" "package"
"semctl" "sysread" "bind" "fcntl" "hex" "pipe" "semget"
"sysseek" "binmode" "fileno" "import" "pop" "semop" "system"
"bless" "flags" "index" "pos" "send" "syswrite" "caller"
"flock" "int" "precision" "setgrent" "tell" "chdir" "fork"
"ioctl" "print" "sethostent" "telldir" "chmod" "format" "join"
"printf" "setnetent" "tie" "chomp" "formline" "keys"
"prototype" "setpgrp" "tied" "chop" "getc" "kill" "push"
"setpriority" "time" "chown" "getgrent" "last" "q"
"setprotoent" "times" "chr" "getgrgid" "lc" "qq" "setpwent"
"tr" "chroot" "getgrnam" "lcfirst" "qr" "setservent"
"truncate" "close" "gethostbyaddr" "length" "quotemeta"
"setsockopt" "uc" "closedir" "gethostbyname" "link" "qw"
"shift" "ucfirst" "connect" "gethostent" "listen" "qx"
"shmctl" "umask" "continue" "getlogin" "local" "rand" "shmget"
"undef" "cos" "getnetbyaddr" "localtime" "read" "shmread"
"unlink" "crypt" "getnetbyname" "lock" "readdir" "shmwrite"
"unpack" "dbmclose" "getnetent" "log" "readline" "shutdown"
"unshift" "dbmopen" "getpeername" "lstat" "readlink" "sin"
"untie" "defined" "getpgrp" "m" "readpipe" "size" "use"
"delete" "getppid" "map" "recv" "sleep" "utime" "die"
"getpriority" "mkdir" "redo" "socket" "values" "do"
"getprotobyname" "msgctl" "ref" "socketpair" "vec" "dump"
"getprotobynumber" "msgget" "rename" "sort" "vector" "each"
"getprotoent" "msgrcv" "require" "splice" "wait" "endgrent"
"getpwent" "msgsnd" "reset" "split" "waitpid" "endhostent"
"getpwnam" "my" "return" "sprintf" "wantarray" "endnetent"
"getpwuid" "next" "reverse" "sqrt" "warn" "endprotoent"
"getservbyname" "no" "rewinddir" "srand" "write" "endpwent"
"getservbyport" "oct" "rindex" "stat" "y" "endservent"
"getservent" "open" "rmdir" "study" "eof" "getsockname"
"opendir" "s" "sub" "eval" "getsockopt" "ord" "scalar"
"substr"))

(defvar ac-source-perl
'((candidates
. (lambda ()
(all-completions ac-target ac-perl-builtin-functions))))
"Source for perl.")

(add-hook 'cperl-mode-hook (lambda ()
(add-to-list 'ac-sources 'ac-source-perl))))

;;; auto-fill for text mode
;; (add-hook 'text-mode-hook 'turn-on-auto-fill)

;;; auto insert
(setq auto-insert t
auto-insert-directory (concat my-emacs-base "auto-insert/"))
(add-hook 'find-file-hooks 'auto-insert)

;;; auto mode list
(setq auto-mode-alist (append '(("\\.[xX]\\'" . c-mode)
("\\.mak\\'" . makefile-mode)
("\\.make\\'" . makefile-mode)
("\\.gdb\\'" . gdb-script-mode)
("\\.v\\'" . verilog-mode)
) auto-mode-alist))

;;; auto-revert when file modified by other
(global-auto-revert-mode t)

;;; backup files ?
(setq make-backup-files t ; yes
version-control 'never) ; but only make a single backup

;;; bbdb & bbdb-vcard-export
(when (< emacs-major-version 23)
(add-to-list 'load-path (concat my-extension-path "bbdb-2.35/lisp")))
(when (require 'bbdb nil t)
(bbdb-initialize)
(setq bbdb-default-area-code 532
bbdb-default-country "China"
bbdb-file (concat my-personal-path "my-bbdb")
bbdb-info-file (concat my-extension-path "bbdb-2.35/texinfo/bbdb.info")
bbdb-north-american-phone-numbers-p nil)
(require 'bbdb-vcard-export nil t))

(when (require 'browse-kill-ring nil t)
(browse-kill-ring-default-keybindings))

;;; c mode configuration
(defconst lgfang-c-style
'((c-tab-always-indent . t)
(c-basic-offset . 4)
(c-ignore-auto-fill . nil)
(c-comment-only-line-offset . (0 . 0))
(c-hanging-braces-alist . (
(substatement-open after before)
(brace-list-open)
))
(c-hanging-colons-alist . ((member-init-intro before)
(inher-intro)
(case-label after)
(label after)
(access-label after)))
(c-cleanup-list . (scope-operator
empty-defun-braces
defun-close-semi))
(c-offsets-alist . (
(knr-argdecl-intro . 5)
(arglist-intro . +)
(arglist-close . c-lineup-close-paren)
(inclass . +)
(member-init-intro . +)
(statement-block-intro . +)
(defun-block-intro . +)
(substatement-open . 0)
(label . 0)
(statement-case-open . +)
(statement-case-intro . +)
(case-label . 0)
(statement-cont . c-lineup-math)
(inline-open . 0)
(brace-list-open . +)
(topmost-intro-cont . 0)
))
(c-special-indent-hook . c-gnu-impose-minimum)
(c-block-comment-prefix . "")
(c-echo-syntactic-information-p . t)
)
"lgfang's C Programming Style")
(c-add-style "lgfang" lgfang-c-style nil)

(add-hook 'c-mode-common-hook
(lambda ()
(c-set-style "lgfang")
(c-toggle-hungry-state 1)
(hs-minor-mode 1)
(c-subword-mode t)
(hide-ifdef-mode 1)
(turn-on-cwarn-mode)
;; (eldoc-mode 1)
(define-key c-mode-base-map (kbd "M-'") 'my-hif-toggle-block)
))
;;; Can't hook imenu-add-menubar-index to c-mode-common-hook since awk
;;; mode don't support it
(add-hook 'c-mode-hook
'imenu-add-menubar-index)
(add-hook 'c++-mode-hook
'imenu-add-menubar-index)
(add-hook 'java-mode-hook
'imenu-add-menubar-index)

;; calendar for Chinese
(when (< emacs-major-version 23) (require 'cal-china-x nil t))

(when (require 'color-theme nil t)
(if window-system (color-theme-gnome2)
(color-theme-calm-forest)))

(column-number-mode t)

(setq comment-style 'extra-line)

;;; Compilation
(require 'compile)
(setq compile-command "gcc -g -Wall "
compilation-scroll-output t)
(define-key compilation-mode-map "n" 'next-error-no-select)
(define-key compilation-mode-map "p" 'previous-error-no-select)
(define-key compilation-mode-map " " (lambda () (interactive)
(save-selected-window
(compile-goto-error))))
(define-key compilation-mode-map [return] 'compile-goto-error)
(define-key compilation-mode-map "o" (lambda () (interactive)
(compile-goto-error)
(delete-other-windows)))
(define-key compilation-mode-map "q" 'quit-window)

(setq default-major-mode 'text-mode)

(when (> emacs-major-version 21) (desktop-save-mode -1))

;;; diary
(add-hook 'list-diary-entries-hook 'include-other-diary-files)
(add-hook 'list-diary-entries-hook 'sort-diary-entries)
(setq diary-display-hook 'fancy-diary-display
diary-file (concat my-personal-path "my-diary"))

;;; dired & dired-X
(setq dired-recursive-copies 'top dired-recursive-deletes 'top)
(require 'dired-x)
(add-hook 'dired-load-hook (lambda () (load "dired-x")))
;; don't show hiden files, bak files etc.
(add-hook 'dired-mode-hook (lambda () (dired-omit-mode 1)))
(setq dired-omit-files (concat dired-omit-files "\\|^\\..+$"))


;;; ediff
;;don't pop a frame for ediff
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
;; (setq-default ediff-diff-options "-w")

;;; elisp
(add-hook 'emacs-lisp-mode-hook
(lambda()
(imenu-add-menubar-index)
(hs-minor-mode 1)))

;;; eshell: restore arrows(up/down) to their orginal functions
(add-hook 'eshell-mode-hook
(lambda ()
(define-key eshell-mode-map [up] 'previous-line)
(define-key eshell-mode-map [down] 'next-line)))
;; multi-eshell
(when (require 'multi-eshell nil t)
(setq multi-eshell-name "*eshell*")
(setq multi-eshell-shell-function (quote (eshell))))

;;; face, add our own keywords. ctypes.el is too heavy-weight
(add-hook 'find-file-hooks ; for all modes (except muse-mode?)
(lambda ()
(font-lock-add-keywords
nil '(("\\<\\(lgfang\\|TODO\\|FIXME\\|NOTE\\):"
. (0 font-lock-warning-face t))))))
(font-lock-add-keywords 'c-mode ; for c mode only
'(("\\<\\(TRUE\\|FALSE\\)\\>"
. font-lock-constant-face)))

;;; fill column
(setq-default fill-column 80)

;;; flymake
(when (> emacs-major-version 21)
(require 'flymake)
(setq flymake-no-changes-timeout 2) ; don't grab too much cpu time
(setq flymake-allowed-file-name-masks
(cons '("\\.cc\\'" flymake-simple-make-init) ;C++ source file
flymake-allowed-file-name-masks))
;;; remember add target in makefile
;;; check-syntax:
;;; g++/gcc -o nul -Wall -S $(CHK_SOURCES)
)

;;; frame: title & transparence
(setq frame-title-format
(list (replace-regexp-in-string "\\..*$" ""system-name) ":"
'(buffer-file-name "%f"
(dired-directory
dired-directory "%b"))))
;; transparent frame
;; (add-to-list 'default-frame-alist '(alpha 80 50))
;; ;; change dynamically (set-frame-parameter (selected-frame) 'alpha '(100 50))

;; (setq gdb-many-windows t)

;;; hide-ifdef-mode settings
(require 'hideif)
(setq hide-ifdef-initially nil)
;; (setq hide-ifdef-define-alist
;; '((cpp _cplusplus)
;; (plexus-lynx TELICA_DCL_MMM)
;; (synopsys-icc DEAD_CODE_XX)
;; ))
;; (hide-ifdef-use-define-alist 'synopsys-icc)

;;; hide-show
(setq hs-allow-nesting t)
;; default value of following var can't deal with '{' not in the same
;; line with "if"
(add-to-list 'hs-special-modes-alist
'(c-mode "[\n\t ]*{" "}" "/[*/]" nil
hs-c-like-adjust-block-beginning))
(add-to-list 'hs-special-modes-alist
'(c++-mode "[\n\t ]*{" "}" "/[*/]" nil
hs-c-like-adjust-block-beginning))
;; remember to add (forward-line -1) to hideshow.el according to
;; http://www.emacswiki.org/cgi-bin/wiki/HideShow

;;; hippie expand
(setq hippie-expand-try-functions-list
'(try-expand-dabbrev
try-expand-dabbrev-visible
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-complete-file-name-partially
try-complete-file-name
try-expand-all-abbrevs
try-expand-list
try-expand-line
try-complete-lisp-symbol-partially
try-complete-lisp-symbol))

(require 'htmlize nil t)

;;; ido
(when (> emacs-major-version 21)
(ido-mode 'buffer)
(setq ido-enable-flex-matching t))

;;; imenu
(setq imenu-sort-function 'imenu--sort-by-name)

(setq inhibit-startup-message nil)

;;; ispell - aspell instead
(setq ispell-program-name "aspell")

;;; linum
(when (> emacs-major-version 21)
(require 'linum nil t)
;;(global-linum-mode t)
)

(setq longlines-wrap-follows-window-size t)

(setq messages-buffer-max-lines 500) ; default value too small

;;; mouse
(setq mouse-yank-at-point t) ; instead of at mouse cursor
(when (not window-system) (xterm-mouse-mode 1)) ;use mouse in xterm

;;; nXML mode
(when (or (>= emacs-major-version 23) ; nxml is part of emacs 23
(and (add-to-list 'load-path
(concat my-extension-path "nxml-mode-20041004"))
(load "rng-auto" t nil nil)))
(add-to-list 'auto-mode-alist
(cons (concat "\\." (regexp-opt
'("xml" "xsd" "sch"
"rng" "xslt" "svg" "rss") t)
"\\'") 'nxml-mode))
(when (> emacs-major-version 21)
(setq magic-mode-alist
(cons '("<\\?xml " . nxml-mode) magic-mode-alist)))
(fset 'xml-mode 'nxml-mode)
(fset 'html-mode 'nxml-mode)
(require 'rng-loc nil t)
(add-to-list 'rng-schema-locating-files
(concat my-emacs-base "my-schemas.xml")))

;;; occur
(define-key occur-mode-map "n" 'next-error-no-select)
(define-key occur-mode-map "p" 'previous-error-no-select)
(define-key occur-mode-map " " 'occur-mode-display-occurrence)
(define-key occur-mode-map "o" (lambda () (interactive)
(occur-mode-goto-occurrence)
(delete-other-windows)))

;;; org-mode
(when (and (> emacs-major-version 21)
(require 'org nil t))
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
(setq org-hide-leading-stars t
org-cycle-include-plain-lists t
org-archive-location "::* Archived Tasks"
org-log-done 'time

org-deadline-warning-days 14

org-agenda-skip-deadline-if-done t
org-agenda-skip-scheduled-if-done t
org-agenda-show-all-dates t
org-agenda-start-on-weekday nil
org-agenda-include-diary t
org-agenda-files (list
(concat my-personal-path "work-tasks.org")
(concat my-personal-path "my-tasks.org")
(concat my-personal-path "my-readings.org")
(concat my-personal-path "my-anniversaries.org")
)

org-reverse-note-order t
org-default-notes-file "~/income.org" ; not used, see templates
org-remember-templates (list
(list ?p "* TODO %?" (concat my-personal-path "my-tasks.org"))
(list ?w "* TODO %?" (concat my-personal-path "work-tasks.org")))

org-tag-alist '(("@work" . ?w) ("@home" . ?h) ("out" . ?o)
("phone" . ?p) ("read" . ?r) ("video" . ?v)
("computer" . ?c) ("someday" . ?s))

org-todo-keywords '((sequence "TODO(t)" "NEXT(n)" "STARTED(s)" "WAITING(w@/!)"
"|" "HOLD(h@/!)" "DELEGATED(p@/!)" "CANCELED(c@/!)" "DONE(d!)"))

org-agenda-custom-commands '( ;; ("t" todo "TODO" nil)
("a" "Agenda + TODO" ; overwrite default 't'
((todo "TODO")(agenda)(todo "WAITING")))
("n" todo "NEXT" nil)
("h" todo "HOLD" nil)
("s" tags "someday")
)

org-publish-project-alist
'(("org"
:base-directory "~/My Documents/homepage/source/personal/"
:publishing-directory "~/My Documents/tmp"
:section-numbers nil
:table-of-contents nil
:exclude "my.*.org"
:style "<link rel=stylesheet
href=\"../my.css\"
type=\"text/css\">"
))
)
(add-hook 'remember-mode-hook 'org-remember-apply-template)
(add-hook 'org-mode-hook 'imenu-add-menubar-index))

;;; perl: using cperl-mode instead
(defalias 'perl-mode 'cperl-mode)

;;; pylint
(load "pylint" t nil nil)

;;; Python mode
(add-hook 'python-mode-hook
(lambda()
(imenu-add-menubar-index)
(c-subword-mode t)
(outline-minor-mode 1)
))

;;; recently opened file
(require 'recentf)
;; add at the front of list, don't conncect to remote hosts
(when (> emacs-major-version 21)
(add-to-list 'recentf-keep 'file-remote-p))
(setq recentf-max-saved-items 100)
(recentf-mode 1)

;;; remember
(add-to-list 'load-path (concat my-extension-path "remember-2.0"))
(when (require 'remember nil t)
(setq
remember-annotation-functions '(org-remember-annotation)
remember-handler-functions '(org-remember-handler)
))

;;; Always end a file with a newline
(setq require-final-newline t)

;;; rfcview & sb-rfcview
(add-to-list 'auto-mode-alist
'("/\\(rfc[0-9]+\\|draft-.+\\)\\.txt\\(\\.gz\\)?\\'"
. rfcview-mode))
(autoload 'rfcview-mode "rfcview")
(eval-after-load "speedbar" '(load "sb-rfcview" t nil nil))

;;; rnc mode - relax-ng compact syntax
(add-to-list 'auto-mode-alist '("\\.rnc\\'" . rnc-mode))
(autoload 'rnc-mode "rnc-mode")

;;; save minibuffer history between sessions
(when (> emacs-major-version 21) (savehist-mode t))

(setq scroll-margin 0 scroll-conservatively 100) ; scroll-step ?

(when (> emacs-major-version 21) (server-start))

;;; Mode for shell script editing is sh-mode, NOT shell-mode
(add-hook 'sh-mode-hook (lambda ()
(hs-minor-mode 1)
(setq imenu-generic-expression
my-sh-imenu-generic-expression)
(imenu-add-menubar-index)))
(setq my-sh-imenu-generic-expression
'((nil "^\\s-*\\(function\\s-+\\)?\\([A-Za-z_][A-Za-z_0-9]+\\)\\s-*()" 2)
(nil "^\\s-*function\\s-+\\([A-Za-z_][A-Za-z_0-9]+\\)" 1)))

;;; highlight matching parenthesis
(show-paren-mode t)

;;; skeleton
(load "my-skeleton" t nil nil)
;; skeleton-pair-insert
(setq skeleton-pair nil ; turn on/off skeleton-pair-insert
skeleton-pair-on-word nil) ; inhibit paired insertion
; before/inside a word
(when skeleton-pair ; if turned on
(global-set-key (kbd "(") 'skeleton-pair-insert-maybe)
(global-set-key (kbd "[") 'skeleton-pair-insert-maybe)
(global-set-key (kbd "{") 'skeleton-pair-insert-maybe)
(global-set-key (kbd "'") 'skeleton-pair-insert-maybe)
(global-set-key (kbd "`") 'skeleton-pair-insert-maybe)
(global-set-key (kbd "\"") 'skeleton-pair-insert-maybe)
(add-hook 'c-mode-hook ; need to be dealt with specifically due to electric keys
'(lambda ()
(define-key c-mode-base-map "{" 'skeleton-pair-insert-maybe)
(define-key c-mode-base-map "(" 'skeleton-pair-insert-maybe)
))
)

;;; speedbar & sr-speedbar
(setq speedbar-show-unknown-files t)
;; (add-hook 'speedbar-timer-hook
;; (lambda ()
;; (save-excursion
;; (set-buffer speedbar-buffer)
;; (speedbar-expand-line))))
;; (when (require 'sr-speedbar nil t)
;; (setq sr-speedbar-skip-other-window-p t))

;;; split horizontally if screen wide enough
(when (>= emacs-major-version 23) (setq split-width-threshold 120))

;;; avoid Chinese chars in time stamps even in Chinese locale.
(setq system-time-locale "C")

;;; tab related
(setq-default tab-stop-list '(4 8 12 16 20 24 28 32 36 40
44 48 52 56 60 64 68 72 76 80)
tab-width 4
;; change tabs to spaces when entering it
indent-tabs-mode nil)

;;; tabbar
(when (and (require 'tabbar nil t) window-system) (tabbar-mode 1))

;;; Tcl & expect
(add-hook 'tcl-mode-hook (lambda ()
(imenu-add-menubar-index)
(hs-minor-mode 1)
(c-subword-mode t)
))
(add-to-list 'interpreter-mode-alist '("expect" . tcl-mode))

;;; time stamp
(add-hook 'write-file-hooks 'time-stamp)
(setq time-stamp-format "%U %02m/%02d/%:y %02H:%02M"
time-stamp-start "\\(Modified\\|last-edit\\): *\\\\?"
time-stamp-end "\\\\?>")

;;; toggle-window-dedicated.el
(load "toggle-window-dedicated" t nil nil)

(tool-bar-mode -1)

(setq tooltip-use-echo-area t)
(tooltip-mode 1)

;;; tramp
(when (> emacs-major-version 21)
(require 'tramp)
(setq tramp-debug-buffer t)

(when (eq system-type 'windows-nt)
(setq tramp-rsh-end-of-line "\r")
;; use 'plink -telnet' for telnet on windows
(add-to-list 'tramp-methods
'("plinkt"
(tramp-connection-function tramp-open-connection-telnet)
(tramp-login-program "plink")
(tramp-copy-program nil)
(tramp-remote-sh "/bin/sh")
(tramp-login-args ("-telnet"))
(tramp-copy-args nil)
(tramp-copy-keep-date-arg nil)
)))

(let ( ;; uses plink as ssh client on windows
(ssh-program (if (eq system-type 'windows-nt) "plink" "ssh"))
;; no applicable ftp client on windows, try ssh(plink) instead
(ftp-program (if (eq system-type 'windows-nt) "plink" "ftp")))

(add-to-list 'tramp-default-method-alist '("localhost" nil "su"))

(setq tramp-default-method-alist
(append (mapcar (lambda (host) (list host nil ftp-program))
'( "192.168.*" ; ftp sites
"135.251.*"
"135.252.*"
"152.148.185.*"
"ihgp.*"
"oak.*"))
tramp-default-method-alist))
(setq tramp-default-method-alist
(append (mapcar (lambda (host) (list host nil ssh-program))
'("maatca.inse.*")) ; ssh sites
tramp-default-method-alist))))

;;; highlight selected region
(setq-default transient-mark-mode t)

;;; trash
(when (>= emacs-major-version 23)
(setq delete-by-moving-to-trash t)
(setq trash-directory "~/.trashbin") ; work for *nix only
)

;;; verilog mode
(autoload 'verilog-mode "verilog-mode" "Verilog mode" t )

(setq-default truncate-lines nil)

;;; w32
(when (eq system-type 'windows-nt)
(load "w32-fontified-region-to-clipboard" t nil nil)
(setq w32-recognize-altgr nil)
(require 'w32-winprint nil t))

;;; webjump
(require 'webjump)
(load (concat my-personal-path "my-web-bookmark") t nil nil)

(which-function-mode t)

;;; whitespace
(if (>= emacs-major-version 23)
(progn
(setq whitespace-line-column fill-column
whitespace-style '(trailing
indentation
space-before-tab
space-after-tab
lines-tail
empty))
(global-whitespace-mode 1))
;; for emacs22 and older
(setq-default indicate-empty-lines t
show-trailing-whitespace nil)
(mapcar (lambda(hook)
(add-hook hook
(lambda () (setq show-trailing-whitespace t))))
(list 'emacs-lisp-mode-hook
'c-mode-common-hook
'python-mode-hook
'nxml-mode-hook
'tcl-mode-hook
'muse-mode-hook)))

(windmove-default-keybindings)

;;; woman
(setq woman-use-own-frame nil)

;;; xcscope for cscope
(when (require 'xcscope nil t)
;; for large code base, set it to t.
(setq cscope-do-not-update-database t)
;; use xcscope for java too.
(add-hook 'java-mode-hook (function cscope:hook))
(add-hook 'eshell-mode-hook (function cscope:hook)))

;;; y/n instead of yes/no
(fset 'yes-or-no-p 'y-or-n-p)

;;; ------ end General ------

;;; ------ begin MyFunction ------

(defun my-goto-page (pageNumber)
"RFCs in ascii format use traditional page
delimiter (Ctrl-L). While Emacs Provides functions like
forward-page,backward-page etc., it doesn't provide goto-page or
sth alike. To go to certain page, I used to either go to the
beginning of the buffer at first or calculate how many pages to
be moved from current page at first. For me, that is a little
boring. I think this function may help. P.S. You may want to give
rfcview.el a try. --lgfang"


(interactive
(if (and current-prefix-arg (not (consp current-prefix-arg)))
(list (prefix-numeric-value current-prefix-arg))
;; Look for a default, a number in the buffer at point.
(let* ((default
(save-excursion
(skip-chars-backward "0-9")
(if (looking-at "[0-9]")
(buffer-substring-no-properties
(point)
(progn (skip-chars-forward "0-9") (point)))))))

(list (read-from-minibuffer
(format (if default "Goto Page (%s): "
"Goto Page: ")
default)
nil nil t
'minibuffer-history
default)
))))
(save-restriction
(widen)
(goto-char (point-min))
(forward-page (1- pageNumber)))
)

;;; for hideif
(defun my-hif-toggle-block ()
"toggle hide/show-ifdef-block --lgfang"
(interactive)
(require 'hideif)
(let* ((top-bottom (hif-find-ifdef-block))
(top (car top-bottom)))
(goto-char top)
(hif-end-of-line)
(setq top (point))
(if (hif-overlay-at top)
(show-ifdef-block)
(hide-ifdef-block))))

(defun hif-overlay-at (position)
"An imitation of the one in hide-show --lgfang"
(let ((overlays (overlays-at position))
ov found)
(while (and (not found) (setq ov (car overlays)))
(setq found (eq (overlay-get ov 'invisible) 'hide-ifdef)
overlays (cdr overlays)))
found))

(defun my-hide-if-0()
"hide #if 0 blocks, inspired by internet. --lgfang"
(interactive)
(require 'hideif)
(save-excursion
(goto-char (point-min))
(while (re-search-forward "^[ \t]*#if[ \t]*0" nil t) (hide-ifdef-block)) )
)
(add-hook 'c-mode-hook 'my-hide-if-0)

(defun my-insert-date ()
"Insert current date at point. From Tijs van Bakel at
newsgroup: gnu.emacs.help. To customize format of date
string,refer to format-time-string. --lgfang"

(interactive)
(insert (format-time-string "%m/%d/%Y")))

(defun my-mode-line-all () ; long/long/ago
"Sometimes there are too many infomation in mode line to show
it in one line. Using this function to show it in an message
box (or pop-up tool tip) --lgfang"

(interactive)
(message "%s" (format-mode-line mode-line-format t))
;; (tooltip-show (format-mode-line mode-line-format t))
;; (message-box "%s" (format-mode-line mode-line-format t))
)

(defun my-recentf-open ()
"open recent files. In ido style if applicable --lgfang"
(interactive)
(let* ((prompt "File Name: ")
(path-table (mapcar
(lambda (x) (cons (file-name-nondirectory
x) x)) recentf-list))
(fname (if (require 'ido nil t)
(ido-completing-read
prompt
(mapcar (lambda(x) (file-name-nondirectory
x)) recentf-list))
(completing-read prompt path-table))))
(find-file (cdr (assoc fname path-table)))))

(defun my-set-frame-title (formatString)
"a short hand to set frame title, ugly but works --lgfang"
(interactive
(let ((default "---"))
(list (read-from-minibuffer "Set frame title: " nil nil t
'minibuffer-history default))))

(if (string-equal formatString "---")
(setq frame-title-format
(list (replace-regexp-in-string "\\..*$" ""system-name) ":"
'(buffer-file-name "%f"
(dired-directory dired-directory "%b"))))
(setq frame-title-format (message "%s" formatString))
))


(defun my-toggle-selective-display()
"set-selective-display to current column or toggle
selective-display --lgfang"

(interactive)
(let ((arg (progn (back-to-indentation) (1+ (current-column)))))
(set-selective-display (if (eq arg selective-display) nil arg))))


(defun my-whitespace-cleanup (beg end)
"Modified standard delete-trailing-whitespace to work regards
region. And add untabify. I don't like the standard
whitespace-cleanup come with emacs22.--lgfang"

(interactive "r")
(if (>= emacs-major-version 23)
(whitespace-cleanup-region beg end)
;; for emacs22 or older
(save-match-data
(save-excursion
(goto-char beg)
(while (re-search-forward "\\s-$" end t)
(skip-syntax-backward "-" (save-excursion (forward-line 0) (point)))
;; Don't delete formfeeds, even if they are considered whitespace.
(save-match-data
(if (looking-at ".*\f")
(goto-char (match-end 0))))
(delete-region (point) (match-end 0))))))
;; beg/end already changed
(untabify (region-beginning) (region-end)))

(when (> emacs-major-version 21)

(defun ido-goto-symbol ()
"Will update the imenu index and then use ido to select a
symbol to navigate to. From emacswiki, by shjk"

(interactive)
(imenu--make-index-alist)
(let ((name-and-pos '())
(symbol-names '()))
(flet ((addsymbols (symbol-list)
(when (listp symbol-list)
(dolist (symbol symbol-list)
(let ((name nil) (position nil))
(cond
((and (listp symbol) (imenu--subalist-p symbol))
(addsymbols symbol))

((listp symbol)
(setq name (car symbol))
(setq position (cdr symbol)))

((stringp symbol)
(setq name symbol)
(setq position (get-text-property 1 'org-imenu-marker symbol))))

(unless (or (null position) (null name))
(add-to-list 'symbol-names name)
(add-to-list 'name-and-pos (cons name position))))))))
(addsymbols imenu--index-alist))
(let* ((selected-symbol (ido-completing-read "jump to: " symbol-names))
(position (cdr (assoc selected-symbol name-and-pos))))
(goto-char position))))
) ; end (when (> emacs-major-version 21)

;;; ------ end MyFunction ------

(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.
'(flymake-errline ((((class color)) (:inherit font-lock-warning-face :underline t))))
'(flymake-warnline ((((class color)) (:foreground "Orange" :underline t :weight bold)))))

发表于: 1970-01-01,修改于: 2009-06-12 21:08,已浏览1674次,有评论0条 推荐 投诉


网友评论
 发表评论