unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#10192: Emacs 24.0.92 windows build, fatal error with M-< or M->
@ 2011-12-02  5:20 Da Zhang
  2011-12-02  7:53 ` Eli Zaretskii
  2011-12-02 14:08 ` Stefan Monnier
  0 siblings, 2 replies; 4+ messages in thread
From: Da Zhang @ 2011-12-02  5:20 UTC (permalink / raw)
  To: 10192


[-- Attachment #1.1: Type: text/plain, Size: 868 bytes --]

Dear Yidong,

I am a dedicated Emacs user who is excited for the new Emacs 24. I have tried the 3 pretests of Emacs 24, and I saw improvements of its stability from each pretest. For example, with my current extensive .emacs configuration file, the first 2 pretests were not able to start normally. However, all the three pretests have the following problems:
1. after the .emacs file is loaded into the pretest Emacs, when I press M-< or M->, the program abort with a fatal error: "A fatal error has occurred! Would you like to attach a debugger? Select Yes to debug, No to abort Emacs..."
2. certain part of eieio is not available, and the emacs prompts with "Symbol's function definition is void: eieio--defgeneric-init-form"

I am not sure if other windows users have experienced the same problem. I attached my .emacs file. Thanks for your attention.

Da Zhang



[-- Attachment #1.2: Type: text/html, Size: 1383 bytes --]

[-- Attachment #2: .emacs --]
[-- Type: text/plain, Size: 111665 bytes --]

;; Filename: .emacs
;; Description:
;; Author: Da Zhang
;; Created: Tue Sep 30 01:18:02 2008
;; Da Zhang
;;     Update #: 2576
;;
;;; Commentary:
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;; -*- Mode: Emacs-Lisp -*- ;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:

;;{{{ General settings {begin}--------------------

(defalias 'ttl 'toggle-truncate-lines)
(defalias 'sbm 'scroll-bar-mode)
(defalias 'menu 'menu-bar-mode)
(defalias 'tbm 'tool-bar-mode)
(defalias 'repl 'query-replace-regexp)
(defalias 'mkh 'make-header)
(defalias 'flb 'flyspell-buffer)
(defalias 'flm 'flyspell-mode)
(defalias 'flr 'flyspell-region)
(defalias 'prb 'ps-print-buffer)
(defalias 'prr 'ps-print-region)
(defalias 'printb 'htmlize-view-buffer)
(defalias 'printr 'htmlize-view-region)
(defalias 'sht 'shell-toggle)
(defalias 'trp 'transparency_plus)
(defalias 'trm 'transparency_minus)
(defalias 'trn 'transparencey_normal)
(defalias 'stw 'show-ws-toggle-show-trailing-whitespace)
(defalias 'font 'menu-set-font)
(defalias 'obp 'open-buffer-path)
(defalias 'zoomin 'text-scale-increase)
(defalias 'zoomout 'text-scale-decrease)
(defalias 'res 'research)
(defalias 'rep 'report)
(defalias 'fold 'folding-mode)
(defalias 'wc 'word-count)

;; Change cursor color according to mode
(defvar set-cursor-color-color "")
(defvar set-cursor-color-buffer "")
(defun set-cursor-color-according-to-mode ()
  "change cursor color according to some minor modes."
  ;; set-cursor-color is somewhat costly, so we only call it when needed:
  (let ((color
         (if buffer-read-only "white"
           (if overwrite-mode "red"
             "red3"))))
    (unless (and
             (string= color set-cursor-color-color)
             (string= (buffer-name) set-cursor-color-buffer))
      (set-cursor-color (setq set-cursor-color-color color))
      (setq set-cursor-color-buffer (buffer-name)))))
(add-hook 'post-command-hook 'set-cursor-color-according-to-mode)

;; set the cursor as a bar instead the rectangular block
(setq-default cursor-type 'box)

;; for cygwin's Emacs
(add-to-list 'load-path "c:/Emacs/site-lisp/")

;; disable the scroll bar on the right by default
(scroll-bar-mode t)

;; highlight the current line, as in Matlab
(global-hl-line-mode t)

;; disable the WoMan-log buffer
(setq-default woman-show-log nil)
(setq-default woman-ignore t)

;; when you mark a region, you can delete it or replace it as in other Windows programs:
;; simply hit delete or type whatever you want or yank
(delete-selection-mode t)

;; make the slow activity to echo my unfinished commands faster
(setq-default echo-keystrokes 0.1)

;; let there be a marker on every empty line on the left fringe: not needed, so nil
(setq-default default-indicate-empty-lines nil)

;; for Emacs 23 only. use the system's trash can when deleting files and foldrs
(setq-default delete-by-moving-to-trash t)

;; by default, do not display continuation lines, instead, give each line of the text just one screen line
(setq-default truncate-lines nil)

;; show the matching parentheses immediately
(setq-default show-paren-delay 0)

;; display the name of the current function at the mode-line
(which-function-mode t)

;; (setq visible-bell t)	; turn off the bell when we have error

(setq ring-bell-function 'ignore)   ; no bells

(setq inhibit-startup-message t)	; turn off the startup message

(setq column-number-mode t) 	; display the column number

(setq mouse-yank-at-point t)    ; prevent the mouse yanking at click. So move the caret first,
                                ; then use middle key of mouse to yank there

(setq kill-ring-max 200)        ; to have a very long kill ring so that I can recover more.

(setq default-fill-column 120)	; set the fill-column as XXX columns for easy reading, 80 is default

(setq-default indent-tabs-mode nil)    ; don't use TAB to indent.

(setq default-tab-width 4)      ; set the default TAB width to 4 characters.

(setq sentence-end-double-space nil) ; don't insert 2 spaces after sentence end.

(setq enable-recursive-minibuffers t) ; t means to enable me to use minibuffer recursively. but I don't like it

(defun stop-using-minibuffer ()
  "kill the minibuffer"
  (when (>= (recursion-depth) 1)
    (abort-recursive-edit)))

(add-hook 'mouse-leave-buffer-hook 'stop-using-minibuffer)

;; (setq scroll-step 1)

;; (setq mouse-wheel-scroll-amount '(1 ((shift) . 1) ((control))))

;; for smooth scrolling and disabling the automatical recentering of emacs when moving the cursor
(setq-default scroll-margin 0
	  scroll-conservatively 0
	  scroll-up-aggressively 0.01
	  scroll-down-aggressively 0.01)


(setq scroll-preserve-screen-position t)

(setq default-major-mode 'text-mode)	; set the default mode

(show-paren-mode t) ; match parentheses

(setq show-paren-style 'parenthesis)    ; when matching parentheses show the matching paren if it is visible
                                        ; otherwise show the entire expression

(mouse-avoidance-mode 'jump) ; when caret is close to mouse pointer, move
                                        ; the mouse pointer away automatically
; how the title of the buffer is displayed
; (setq frame-title-format "%b")

(auto-image-file-mode 1)	; enable emacs to open and display pictures directly

(fset 'yes-or-no-p 'y-or-n-p) ; use y/n rather than yes/no as choices

(display-time) ; display time

(global-font-lock-mode t)		; syntax highlighting
(setq font-lock-maximum-decoration t)
(setq font-lock-verbose t)
(setq font-lock-maximum-size '((t . 1048576) (vm-mode . 5250000)))

(transient-mark-mode t) ; use  high contrast to show region

(tool-bar-mode t) ; don't want that big tool bar

(setq user-full-name "Da Zhang")	; personal information

(add-hook 'text-mode-hook 'turn-on-auto-fill) ; wrap long lines in text mode

(setq compile-command "make")

;; when the caret is at the end of line and you want to move it up, it stays at each line's end: t
;; when the caret is at the end of line and you want to move it up, it stays at each line's end: nil
(setq track-eol nil)

;; set up emacs so that it generates backup files
(setq make-backup-files t)
(setq-default make-backup-files t)
;; Backups in ~/.backups/emacs/ folder
(defun make-backup-file-name (FILE)
    (let ((dirname (concat "~/.backups/emacs/"
                     (format-time-string "%y/%m/%d/"))))
          (if (not (file-exists-p dirname))
             (make-directory dirname t))
           (concat dirname (file-name-nondirectory FILE))))

;; kill a line and the RET together by C-k
(setq-default kill-whole-line t)

;; show-wspace, load this library to enable several nice features: show-ws-toggle-show-hard-spaces,
;; show-ws-toggle-show-tabs
(require 'show-wspace)

;; "focus follows mouse": the window your mouse pointer is over receives focus (input) so you don't need to click on it
;; to give it focus.
(setq mouse-autoselect-window nil)

;; set the default encoding system
(prefer-coding-system 'utf-8)

;; htmlize: output color highlighted file into html file
(require 'htmlize)
(add-to-list 'auto-mode-alist '("\\.htm$" . html-mode))
(add-to-list 'auto-mode-alist '("\\.html$" . html-mode))
(add-to-list 'auto-mode-alist '("\\.tmpl$" . html-mode))
(add-to-list 'auto-mode-alist '("\\.xml$" . xml-mode))

;; my version of revert-buffer
(defun da-revert-buffer (&optional arg)
  "save the current position to tmp, then call revert-buffer, then goto-char(position)"
  (interactive "P")
  (defvar tmp)
  (setq tmp (point))
  (if arg
      (revert-buffer t t)
      (revert-buffer t)
      )
  (goto-char tmp)
  (kill-local-variable 'tmp))

;; several quick accesses 
(defun work ()
  "Switch to my work dir."
   (interactive)
   (find-file "C:/Documents and Settings/da/My Documents/work")
   )

(defun research ()
  "Switch to my research dir."
   (interactive)
   (find-file "C:/research")
   )

(defun report ()
  "Switch to my research dir."
   (interactive)
   (find-file "C:/Documents and Settings/da/My Documents/report")
   )

(defun lit ()
  "Switch to the literature folder."
   (interactive)
   (find-file "C:/Documents and Settings/da/My Documents/literature")
   )

(defun doc ()
  "Switch to the literature folder."
   (interactive)
   (find-file "C:/Documents and Settings/da/My Documents")
   )

(defun matlab-dir ()
  "Switch to the literature folder."
   (interactive)
   (find-file "C:/MATLAB2008a/work/Da_matural_subroutines")
   )

;; modify kill line and kill region so that if M-w or C-w without an active region, just copy the line
(defadvice kill-ring-save (before slick-copy activate compile) "When called
  interactively with no active region, copy a single line instead."
  (interactive (if mark-active (list (region-beginning) (region-end)) (message
  "Copied line") (list (line-beginning-position) (line-beginning-position
  2)))))

(defadvice kill-region (before slick-cut 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)))))

;; Load the appropriate interaction-mode for given source file extensions
(setq auto-mode-alist
      (append '(("\\.pl$" . perl-mode)
                ("\\.perl$" . perl-mode)
                ("\\.txt$" . text-mode)
                ("\\.html$" . html-mode)
                ("\\.java$" . java-mode)
                ("\\.nqc$" . c++-mode)
                ("\\.C$". c++-mode)
                ("\\.H$". c++-mode)
                ("\\.h$". c++-mode)
                ("\\.dra$". c++-mode)
                ("\\.par$". c++-mode)
                ("\\.env$". shell-script-mode)
                ("\\.eml$" . mail-mode)
                ("\\.org$$\\'" . org-mode)
                ("\\.m$$\\'" . matlab-mode)
                ("\\.tlc$" . tlc-mode)
                ("\\.ijm$" . java-mode)
                )
              auto-mode-alist))

;; global-auto-revert-mode
(global-auto-revert-mode t)

;; use fringe to indicate empty lines on the left
(setq-default indicate-empty-lines t
        indicate-buffer-boundaries 'left)

(setq redisplay-dont-pause nil) ;; Non-nil means update isn't paused when input is detected.

(setq-default scroll-step 1) ;; change the behavior of scroll

;; start usging the version control mechanism
;; (setq version-control t)
;; (setq kept-old-version 2) ; you can backup 2 old versions, i.e, last version, the one before last version
;; (setq kept-new-versions 1); back up the new version once
;; (setq delete-old-versions t);; get rid of the old versions other than the last 2 versions
;; (setq backup-directory-alist '(("." . "~/backups"))) ; set up the path for backups
;; (setq backup-by-copying t) ; using direct copy to back up
;; default start up path:
;; (setq default-directory "C:/Documents and Settings/da/My Documents/") ; My documents

;; just to turn on these settings
;; (put 'set-goal-column 'disabled nil)	
;; (put 'upcase-region 'disabled nil)
;; (put 'downcase-region 'disabled nil)
;; (put 'LaTeX-hide-environment 'disabled nil)

;; REMOVE TRAILING WHITESPACES BEFORE SAVING (NOW LOCAL)
;; (add-hook 'before-save-hook 'delete-trailing-whitespace)

;; ;; Non-nil means to automatically adjust `window-vscroll' to view tall lines.
;; (setq-default auto-window-vscroll nil)

;; ;; midnight mode
;; (require 'midnight)
;; (setq clean-buffer-list-delay-general 2)

;;}}} General settings {end}--------------------


;;{{{ ELPA {begin}--------------------

;;; This was installed by package-install.el.
;;; This provides support for the package system and
;;; interfacing with ELPA, the package archive.
;;; Move this code earlier if you want to reference
;;; packages in your .emacs.
(when
    (load
     (expand-file-name "~/.emacs.d/elpa/package.el"))
  (package-initialize))

(setq package-archives '(("ELPA" . "http://tromey.com/elpa/") 
                          ("gnu" . "http://elpa.gnu.org/packages/")
                          ("marmalade" . "http://marmalade-repo.org/packages/")))

;;}}} ELPA {end}--------------------



;;{{{ Transparency {begin}--------------------

(defun opacity-modify (&optional dec)
  "modify the transparency of the emacs frame; if DEC is t,
    decrease the transparency, otherwise increase it in 20%-steps"
  (let* ((alpha-or-nil (frame-parameter nil 'alpha)) ; nil before setting
          (oldalpha (if alpha-or-nil alpha-or-nil 100))
          (newalpha (if dec (- oldalpha 10) (+ oldalpha 10))))
    (when (and (>= newalpha frame-alpha-lower-limit) (<= newalpha 100))
      (modify-frame-parameters nil (list (cons 'alpha newalpha))))))

(defun transparency_plus ()
  "increase the transparency"
  (interactive)
  (opacity-modify t))

(defun transparency_minus ()
  "decrease the transparency"
  (interactive)
  (opacity-modify))

(defun transparencey_normal ()
  "make the transparency to normal"
  (interactive)
  (modify-frame-parameters nil `((alpha . 100))))

;;}}} Transparency {end}--------------------



;;{{{ Diary and calendar {begin}--------------------

;; set the latitude and longitude of Norman, OK so that Emacs can calculate the
;; time of sunrise and sunset for me
(setq calendar-latitude +42.37)
(setq calendar-longitude -71.03)
(setq calendar-location-name "Boston, MA")

;; set up how calendar displays
(setq calendar-remove-frame-by-deleting t)
(setq calendar-week-start-day 1)            ; a week starts at Monday
(setq mark-diary-entries-in-calendar t)        ; mark the dates where I have diaries
;; (setq mark-holidays-in-calendar nil)        ; don't show hoildays on the calendar
;; (setq view-calendar-holidays-initially nil) ; don't show holidays when the calendar starts

;; set up diary
(setq diary-file "~/diary");; the default diary path
(setq diary-mail-addr "daveluciffer@gmail.com")
(add-hook 'diary-hook 'appt-make-list)

;;}}} Diary and calendar {end}--------------------



;;{{{ Auctex Settings {begin}--------------------

;; Reftex activation
(autoload 'reftex-mode "reftex" "RefTeX Minor Mode" t)
(autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil)
(autoload 'reftex-citation "reftex-cite" "Make citation" nil)
(autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX LaTeX mode
(add-hook 'latex-mode-hook 'turn-on-reftex)   ; with Emacs latex mode
(setq reftex-plug-into-AUCTeX t)

;; ;; enable document parcing
(setq TeX-auto-save t)
(setq TeX-parse-self t)

;; To get a full featured LaTeX-section command, insert: http://www.gnu.org/software/auctex/manual/auctex.html
(setq LaTeX-section-hook
      '(LaTeX-section-heading
        LaTeX-section-title
        LaTeX-section-section
        LaTeX-section-label))

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

;; flyspell
(add-hook 'LaTeX-mode-hook 'flyspell-mode)
(add-hook 'latex-mode-hook 'flyspell-mode)
(add-hook 'TeX-mode-hook 'flyspell-mode)

;; latex toolbar
;; (add-hook 'LaTeX-mode-hook 'LaTeX-install-toolbar)


;; enable the Tex-fold-mode for all Auctex modes, which can hide (fold) and show (unfold) macros and environments
;; described in section 6.2 http://www.gnu.org/software/auctex/manual/auctex.html
(add-hook 'TeX-mode-hook (lambda ()
                           (TeX-fold-mode 1)
                           (define-key TeX-mode-map
                             "\C-m" 'reindent-then-newline-and-indent)))

;; enabled source-specials (for dvi inverse search) permanently
(add-hook 'TeX-mode-hook 'TeX-source-specials-mode 1)

;; variables for BibTeX auto search
(setq reftex-bibpath-environment-variables '("/cygdrive/c/H/Bib/"))

;; Add standard Sweave file extensions to the list of files recognized
;; by AUCTeX.
(setq TeX-file-extensions
      '("Rnw" "rnw" "Snw" "snw" "tex" "sty" "cls" "ltx" "texi" "texinfo" "dtx"))

;; to enable auto-fill-mode in all text mode, similar to above:
;; (add-hook 'text-mode-hook 'turn-on-auto-fill)

;; if you often use /include and multifile structure, enable emacs to ask for
;; a master file every time you open a new file
;; (setq-default TeX-master nil)

;;}}} Auctex Settings {end}--------------------



;;{{{ printing {begin}--------------------

;;; Easier printing
(require 'w32-winprint)
(require 'htmlize-view)
(htmlize-view-add-to-files-menu)

;; since the correct program gsprint.exe is used, now emacs can print by
;; PostScript print XXX
(setq ps-lpr-command "C:/Program Files/Ghostgum/gsview/gsprint.exe")
;; This line causes ghostscript to query which printer to
;; use - which you may not need if, for example, you only
;; have one printer.
(setq ps-lpr-switches '("-query"))
(setq ps-printer-name t)

;; to enable the new printing package of Emacs 22
;; more options and customizations are needed to fully use this printing.el, but
;; I will leave it for later invesgivation
(require 'printing)
;; First of all, take a glance of printing documentation only to have an idea
;; of what `printing' is capable.
;; Then try to set the variables: `pr-ps-name', `pr-ps-printer-alist',
;; `pr-txt-name', `pr-txt-printer-alist' and `pr-path-alist'.  These variables
;; are the main variables for printing processing.
;; Now, please, see these variables documentation more in deep.  You can do
;; this by typing C-h v pr-ps-name RET (for example) if you already loaded
;; printing package, or by browsing printing.el source file.

;;}}} printing {end}--------------------



;;{{{ Muse {begin}--------------------

;; (add-to-list 'load-path "c:/Emacs/site-lisp/muse/")
;; (add-to-list 'load-path "c:/Emacs/site-lisp/muse/")
(require 'muse-mode)     ; load authoring mode
(require 'muse-html)     ; load publishing styles I use
(require 'muse-latex)
(require 'muse-texinfo)
(require 'muse-docbook)
(require 'muse-project)  ; publish files in projects
(require 'muse-colors)
(require 'muse-wiki)

(setq muse-html-meta-content-type (concat "text/html; charset=utf-8"))

(define-key muse-mode-map [f5] 'muse-project-publish-this-file)

(add-to-list 'auto-mode-alist '("\\.muse$" . muse-mode))

(defun my-muse-mode-hook ()
  (setq auto-fill-mode t)
  (flyspell-mode 1)
  (footnote-mode 1)
  )

(add-hook 'muse-mode-hook 'my-muse-mode-hook)

;; load the customization file for muse mode and project definitions
;; location: site-lisp/muse-da-projects.el
(load "muse-da-projects")

;; muse to slides
(require 'muse-html-slidy)

;;}}} Muse {end}--------------------



;;{{{ CS-RCS mode {begin}--------------------

;; this is the integration of the ComponentSoftware CS-RCS front end of RCS in
;; windows and the emacs. CF:
;; http://www.componentsoftware.com/csrcs/Integration/emacs.htm
(load "vc-hooks")
(setq vc-path "C:/program files/ComponentSoftware/cs-rcs/system")

;; don't use the vc-toggle-read-only, use the toggle-read-only
(global-set-key (kbd "C-x C-q") 'toggle-read-only)

;;}}} CS-RCS mode {end}--------------------



;;{{{ Org-mode {begin}--------------------

(add-to-list 'load-path "c:/Emacs/site-lisp/org/")
;; (add-to-list 'load-path "C:/Emacs/site-lisp/org/")
(require 'org-install)
;; The following lines are always needed.  Choose your own keys.
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
;; (global-set-key (kbd "C-c l") 'org-store-link)
;; (global-set-key (kbd "C-c a") 'org-agenda)
;; (global-set-key (kbd "C-c b") 'org-iswitchb)

(setq org-hide-leading-stars t)
(setq org-log-done t)
;; set sorting strategy for org TODO items
(setq org-agenda-sorting-strategy
      '((agenda priority-down time-up)
        (todo priority-down category-keep)
        (tags priority-down category-keep)))

;; CDLaTeX hook
(add-hook 'org-mode-hook 'turn-on-org-cdlatex)

;; allows changing todo states with S-left and S-right skipping all of the normal processing when entering or leaving a
;; todo state
(setq org-treat-S-cursor-todo-selection-as-state-change nil)
(setq org-agenda-skip-timestamp-if-done t)
;; TODO, MAYBE, STARTED, WAITING, DONE
(setq org-todo-keywords '((type "MAYBE(m)" "TODO(t)" "STARTED(s)" "WAITING(w)" "|" "DONE(d)")))
;; (setq org-todo-keyword-faces
;;       '(("WAITING" . (:foreground "gray" :weight bold))))
;; (setq org-todo-keyword-faces
;;       '(("MAYBE" . (:foreground "gray" :weight bold))))
;; (setq org-todo-keyword-faces
;;       '(("TODO" . (:foreground "red" :weight bold))))

;; (setq org-directory "~/org")
(setq org-directory "c:/H/GTD/")
(setq org-reverse-note-order nil)
(global-set-key [f12] 'remember)
(global-set-key [C-f12] 'gtd)
(defun gtd ()
  "Switch to my GTD project file."
   (interactive)
   (find-file "c:/H/GTD/this_week.org")
   )

;; org-google-weather support
(require 'google-weather)
(require 'org-google-weather)

;; disable the translation from _ and ^ to subscript and superscript
(setq-default org-export-with-sub-superscripts nil)

;; sacha chua's org-toodledo mode for toodledo integration (http://www.toodledo.com/)
;; (require 'org-toodledo)
;; (setq org-toodledo-userid "td4bf2dc9a78677")
;; (setq org-toodledo-password "da014916")

;;}}} Org-mode {end}--------------------



;;{{{ Remember mode {begin}--------------------

(require 'remember)
(org-remember-insinuate)

(setq org-remember-templates
      '(("TODO" ?t "* %?%&" "~/org/TODO.org" bottom)
        ("NOTES" ?n "* %?\n** %T\n" "~/org/notes.org" bottom)
        ("MINUTES" ?m "* %?\n** %T\n" "~/org/minutes.org" bottom)))

(setq remember-annotation-functions '(org-remember-annotation))
(setq remember-handler-functions '(org-remember-handler))
(add-hook 'remember-mode-hook 'org-remember-apply-template)

;; CF: http://metajack.im/2008/12/30/gtd-capture-with-emacs-orgmode/

;;}}} Remember mode {end}--------------------



;;{{{ outline minor mode {begin}--------------------

(global-unset-key (kbd "C-o"))
(global-set-key (kbd "M-o") 'open-line)
;; Set the minor mode prefix to C-o
(setq outline-minor-mode-prefix "\C-o")
(add-hook 'muse-mode-hook 'outline-minor-mode)
(add-hook 'html-mode-hook 'outline-minor-mode)
(add-hook 'LaTeX-mode-hook 'outline-minor-mode)

;;}}} outline minor mode {end}--------------------



;;{{{ cygwin-shell {begin}--------------------

;; disable these two -- they slow down the start up so much, and I don't know the use of them

;;; Add Cygwin Info pages
(setq Info-default-directory-list (append Info-default-directory-list (list "c:/cygwin/usr/info/")))

(setq ediff-shell shell-file-name)      ; Ediff shell

(add-hook 'comint-output-filter-functions
    'shell-strip-ctrl-m nil t)
(add-hook 'comint-output-filter-functions
    'comint-watch-for-password-prompt nil t)

;; to use the bash shell provided by cygwin
(setq explicit-shell-file-name "C:/cygwin/bin/bash.exe")

;; to use the windows system shell
;; (setq explicit-shell-file-name "cmdproxy.exe")

;; For subprocesses invoked via the shell
;; (e.g., "shell -c command")
(setq shell-file-name explicit-shell-file-name)

;; set environmental variables specific for this Emacs emulation of bash.exe (this shell will not load /etc/profile properly)
;; but this emulation will read ~/.bashrc
;; if use \ to separate path, must use \\ to escape \
;; or use / to separate path
(setenv "SHELL" shell-file-name)
(setenv "PATH" (concat (getenv "PATH") "C:\\cygwin\\bin;C:\\cygwin\\usr\\X11R6\\bin;C:\\cygwin\\usr\\sbin;C:\\cygwin\\usr\\local\\bin;"))
(setenv "PATH" (concat "C:\\cygwin\\bin;C:\\cygwin\\usr\\X11R6\\bin;C:\\cygwin\\usr\\sbin;C:\\cygwin\\usr\\local\\bin;" (getenv "PATH")))
;; (setenv "PS1" "\[\e[31;1m\][\w]\[\e[0m\]")

;;; Shell mode
(setq ansi-color-names-vector ; better contrast colors
      ["black" "red4" "green4" "yellow4"
       "blue3" "magenta4" "cyan4" "white"])
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)

;;}}} cygwin-shell {end}--------------------



;;{{{ default emacs windows size {begin}--------------------

(setq default-frame-alist
      '((top . 0) (left . 0)
        (width . 164) (height . 52)))

;; (set-frame-height (selected-frame) 54) ; # of lines

;; (set-frame-width (selected-frame) 164); # of columns

;; (set-frame-position (selected-frame) 0 0) ; upper left corner is (0,0)

;; set up the X resource Geometry for MS-Windows
;; registry, HKEY_LOCAL_MACHINE\SOFTWARE\GNU\Emacs
;; Emacs.Geometry:83x59 (3:4) 124x59 (4:3, resolution: 1280x1024)
;; CF:
;; http://www.gnu.org/savannah-checkouts/gnu/emacs/manual/html_node/emacs/Table-of-Resources.html#Table-of-Resources
;; http://xwinman.org/resource.php

;;}}} default emacs windows size {end}--------------------



;;{{{ Emacs Server {begin}--------------------

(server-force-delete)
(server-start)

;;}}} Emacs Server {end}--------------------



;;{{{ line number setting {begin}--------------------

;; for adding line numbers to the beginning of each line
;; better than setnu.el
(require 'linum)
(defun toggle-linum-mode ()	; define function
  "Toggle the linum-mode"
  (interactive)
  (if linum-mode
      (linum-mode -1)
    (linum-mode 1)))

;; use f1 as the key sequency for toggle line number on/off
(global-set-key [f1] 'toggle-linum-mode)

;;}}} line number setting  {end}--------------------



;;{{{ buffer modes {begin}--------------------

;; ibuffer
(require 'ibuffer)
(global-set-key (kbd "C-x C-b") 'ibuffer) ; ibuffer.el, to lable, sort, hide, search, replace through buffers
(defun ibuffer-ediff-marked-buffers ()
  (interactive)
  (let* ((marked-buffers (ibuffer-get-marked-buffers))
         (len (length marked-buffers)))
    (unless (= 2 len)
      (error (format "%s buffer%s been marked (needs to be 2)"
                     len (if (= len 1) " has" "s have"))))
    (ediff-buffers (car marked-buffers) (cadr marked-buffers))))

(define-key ibuffer-mode-map "e" 'ibuffer-ediff-marked-buffers)

;; use /-R in ibuffer mode to enable the filtered view of buffers
(setq ibuffer-saved-filter-groups
      (quote (("default"
               ("dir" (or
                (mode . dired-mode)
                (mode . shell-mode)))
               ("org" (or
                           (name . "^\\*Calendar\\*$")
                           (name . "^diary$")
                           (mode . org-mode)
                           (mode . org-agenda-mode)))
               ("muse" (or
                           (mode . muse-mode)
                           (name . "^\\.muse$")))
               ("webpage" (or
                           (mode . html-mode)
                           (mode . xml-mode)
                           (mode . css-mode)
                           (name . "^\\.html$")
                           (name . "^\\.htm$")
                           (name . "^\\.xml$")
                           (name . "^\\.tmpl$")
                           (name . "^\\.css$")))
               ("lisp" (or
                         (mode . emacs-lisp-mode)
                         (name . "^\\.el$")
                         (name . "^\\.elc$")))
               ("latex" (or
                         (mode . TeX-latex-mode)
                         (mode . TeX-tex-mode)
                         (mode . latex-mode)
                         (mode . bibtex-mode)
                         (name . "^\\.tex$")
                         (name . "^\\.bib$")
                         (name . "^\\.bbl$")
                         (name . "^\\.aux$")
                         (name . "^\\.log$")
                         (name . "^\\.blg$")))
               ("matlab" (or
                          (mode . matlab-mode)
                          (name . "^\\.m$")))
               ("c++" (or
                          (mode . c++-mode)
                          (mode . c-mode)
                          (mode . makefile-mode)
                          (name . "makefile")
                          (name . "^\\.cpp$")
                          (name . "^\\.c$")
                          (name . "^\\.h$")
                          (name . "^\\.hpp$")
                          (name . "^\\.dra$")
                          (name . "^\\.par$")))
               ("doc" (or
                                 (mode . Info-mode)
                                 (mode . apropos-mode)
                                 (mode . woman-mode)
                                 (mode . help-mode)
                                 (mode . Man-mode)))
               ))))

;; Note: the name of the group is case sensitive, so "default" != "DEFAULT"
(add-hook 'ibuffer-mode-hook
          (lambda ()
            (ibuffer-switch-to-saved-filter-groups "default")))

(setq ibuffer-saved-filters
               (quote (("dir" 
                 ((or
                   (mode . dired-mode)
                   (mode . shell-mode))))
                ("org" 
                 ((or
                   (name . "^\\*Calendar\\*$")
                   (name . "^diary$")
                   (mode . org-mode)
                   (mode . org-agenda-mode))))
                ("muse" 
                 ((or
                   (mode . muse-mode)
                   (name . "^\\.muse$"))))
                ("webpage" 
                 ((or
                   (mode . html-mode)
                   (mode . xml-mode)
                   (mode . css-mode)
                   (name . "^\\.html$")
                   (name . "^\\.htm$")
                   (name . "^\\.xml$")
                   (name . "^\\.tmpl$")
                   (name . "^\\.css$"))))
                ("lisp" 
                 ((or
                   (mode . emacs-lisp-mode)
                   (name . "^\\.el$")
                   (name . "^\\.elc$"))))
                ("tex" 
                 ((or
                   (mode . TeX-latex-mode)
                   (mode . TeX-tex-mode)
                   (mode . latex-mode)
                   (mode . bibtex-mode)
                   (name . "^\\.tex$")
                   (name . "^\\.bib$")
                   (name . "^\\.bbl$")
                   (name . "^\\.dra$")
                   (name . "^\\.par$")
                   (name . "^\\.aux$")
                   (name . "^\\.log$")
                   (name . "^\\.blg$"))))
                ("matlab" 
                 ((or
                   (mode . matlab-mode)
                   (name . "^\\*M-Lint\\*$")
                   (name . "^\\.m$"))))
                ("c++" 
                 ((or
                   (mode . c++-mode)
                   (mode . c-mode)
                   (mode . makefile-mode)
                   (name . "makefile")
                   (name . "^\\.cpp$")
                   (name . "^\\.c$")
                   (name . "^\\.h$")
                   (name . "^\\.hpp$")
                   (name . "^\\.dra$")
                   (name . "^\\.par$"))))
                ("Image" 
                 ((or
                   (mode . image-mode)
                   (name . "^\\.jpg$")
                   (name . "^\\.png$")
                   (name . "^\\.tif$")
                   (name . "^\\.tiff$"))))
                ("doc" 
                 ((or
                   (mode . Info-mode)
                   (mode . apropos-mode)
                   (mode . woman-mode)
                   (mode . help-mode)
                   (mode . Man-mode)))))))

;; column width of ibuffer
;; Use human readable Size column instead of original one
(define-ibuffer-column size-h
  (:name "Size" :inline t)
  (cond
   ((> (buffer-size) 1000) (format "%7.3fk" (/ (buffer-size) 1000.0)))
   ((> (buffer-size) 1000000) (format "%7.3fM" (/ (buffer-size) 1000000.0)))
   (t (format "%8d" (buffer-size)))))

;; Modify the default ibuffer-formats
(setq ibuffer-formats
      '((mark modified read-only " "
              (name 40 40 :left)
              " "
              (size-h 9 -1 :right)
              " "
              (mode 16 16 :left :elide)
              " "
              filename-and-process)))

;; swbuff
;; (require 'swbuff)
;; (global-set-key (kbd "<C-prior>") 'swbuff-switch-to-previous-buffer)
;; (global-set-key (kbd "<C-next>") 'swbuff-switch-to-next-buffer)
;; (setq swbuff-exclude-buffer-regexps
;;      '("^ .*" "^\\*.*\\*")) ;; from swbuff.el
;; ;;'("^ " "\\*.*\\*")) ;; Wang Yin's original setting
;; (setq swbuff-status-window-layout 'scroll)
;; (setq swbuff-clear-delay 0.1)
;; (setq swbuff-separator "|")
;; (setq swbuff-window-min-text-height 1)

;; tabbar
;; (require 'tabbar-acquamacs)
(require 'tabbar)
(tabbar-mode 1)
(global-set-key (kbd "C-S-p") 'tabbar-backward-group)
(global-set-key (kbd "C-S-n") 'tabbar-forward-group)
(global-set-key (kbd "C-S-b") 'tabbar-backward)
(global-set-key (kbd "C-S-f") 'tabbar-forward) ; tabbar.el, put all the buffers on the tabs.
(global-set-key (kbd "C-<") 'tabbar-backward)
(global-set-key (kbd "C->") 'tabbar-forward) ; tabbar.el, put all the buffers on the tabs.
(setq tabbar-background-color "gray80")
(setq tabbar-cycle-scope (quote tabs))
(setq tabbar-separator (quote (1)))
(setq table-time-before-update 0.1)
(setq tabbar-use-images nil)

;;}}} buffer modes {end}--------------------



;;{{{ browse-kill-ring {begin}--------------------

(require 'browse-kill-ring)
(global-set-key (kbd "C-c k") 'browse-kill-ring)
(browse-kill-ring-default-keybindings) ; browse-kill-ring.el, to use a buffer to
                                       ; let you select what you want to yank
;;}}} browse-kill-ring {end}--------------------



;;{{{ ido {begin}--------------------

;; ido.el, easist way to switch among buffers and to search files
;; (require 'ido)
;; (ido-mode t)

;; use the following "(add-hook 'term-setup-hook 'ido-mode)" instead of
(require 'ido)
(ido-mode t)
;; as a work around of a bug in this version of the emacs
;; 23-cvs-081124: recursive load tramp
;; (add-hook 'term-setup-hook 'ido-mode)

;; ignore what buffer, file, directory in ido minibuffer
(setq ido-ignore-buffers
      '("\\` " "^\\*ESS\\*" "^\\*Messages\\*" "^\\*Help\\*" "^\\*Buffer"
        "^\\*.*Completions\\*$" "^\\*Ediff" "^\\*tramp" "^\\*cvs-"
        "_region_" " output\\*$" "^TAGS$" "^\*Ido" "^\\*WoMan-log\\*"))

(setq ido-ignore-directories
      '("\\`auto/" "\\.prv/" "\\`CVS/" "\\`\\.\\./" "\\`\\./"))

(setq ido-ignore-files
      '("\\.asv/" "\\`auto/" "\\.prv/" "_region_" "\\`CVS/" "\\`#" "\\`.#" "\\`\\.\\./" "\\`\\./"))

;; flex-matching: ido will match files containing the characters which have been
;; entered anywhere so long as they are in the correct sequence.
(setq ido-enable-flex-matching t)

;; whether a new buffer is created if no buffer matches substring. Choices are
;; 'always to create new buffers unconditionally, 'prompt to ask user whether to
;; create buffer, or 'never to never create new buffer.
(setq ido-create-new-buffer 'always)

;; ido auto merge
(setq ido-auto-merge-delay-time 5) ; wait for 5 seconds before doing auto merge.

;; the following are keybindings of ido, but I just didn't enable them because someday I want to bind these
;; keys by myself
(add-hook 'ido-define-mode-map-hook 'ido-my-keys)

(defun ido-my-keys ()
  "Set up the keymap for `ido'."

  ;; common keys
  (define-key ido-mode-map "\C-e" 'ido-edit-input)
  (define-key ido-mode-map "\t" 'ido-complete) ;; complete partial, using TAB
  (define-key ido-mode-map "\C-j" 'ido-select-text)
  (define-key ido-mode-map "\C-m" 'ido-exit-minibuffer)
  (define-key ido-mode-map "?" 'ido-completion-help) ;; list completions
  (define-key ido-mode-map [(control ? )] 'ido-restrict-to-matches)
  (define-key ido-mode-map [(control ?@)] 'ido-restrict-to-matches)

  ;; cycle through matches
  (define-key ido-mode-map "\C-r" 'ido-prev-match)
  (define-key ido-mode-map "\C-s" 'ido-next-match)
  (define-key ido-mode-map [right] 'ido-next-match)
  (define-key ido-mode-map [left] 'ido-prev-match)

  ;; toggles
  (define-key ido-mode-map "\C-t" 'ido-toggle-regexp) ;; same as in isearch
  (define-key ido-mode-map "\C-p" 'ido-toggle-prefix)
  (define-key ido-mode-map "\C-c" 'ido-toggle-case)
  (define-key ido-mode-map "\C-a" 'ido-toggle-ignore)

  ;; keys used in file and dir environment
  (when (memq ido-cur-item '(file dir))
    (define-key ido-mode-map "\C-b" 'ido-enter-switch-buffer)
    (define-key ido-mode-map "\C-d" 'ido-enter-dired)
    (define-key ido-mode-map "\C-f" 'ido-fallback-command)

    ;; cycle among directories
    ;; use [left] and [right] for matching files
    (define-key ido-mode-map [down] 'ido-next-match-dir)
    (define-key ido-mode-map [up]   'ido-prev-match-dir)

    ;; backspace functions
    (define-key ido-mode-map [backspace] 'ido-delete-backward-updir)
    (define-key ido-mode-map "\d"        'ido-delete-backward-updir);; use of backspace
    (define-key ido-mode-map [(meta backspace)] 'ido-delete-backward-word-updir)
    (define-key ido-mode-map [(control backspace)] 'backward-kill-word)

    ;; I can't understand this
    (define-key ido-mode-map [(meta ?d)] 'ido-wide-find-dir)
    (define-key ido-mode-map [(meta ?f)] 'ido-wide-find-file)
    (define-key ido-mode-map [(meta ?k)] 'ido-forget-work-directory)
    (define-key ido-mode-map [(meta ?m)] 'ido-make-directory)

    (define-key ido-mode-map [(meta down)] 'ido-next-work-directory)
    (define-key ido-mode-map [(meta up)] 'ido-prev-work-directory)
    (define-key ido-mode-map [(meta left)] 'ido-prev-work-file)
    (define-key ido-mode-map [(meta right)] 'ido-next-work-file)

    ;; search in the directories
    ;; use C-_ to undo this
    (define-key ido-mode-map [(meta ?s)] 'ido-merge-work-directories)
    (define-key ido-mode-map [(control ?\/)] 'ido-undo-merge-work-directory)
    )

  (when (eq ido-cur-item 'file)
    (define-key ido-mode-map "\C-k" 'ido-delete-file-at-head)
    (define-key ido-mode-map "\C-l" 'ido-toggle-literal)
    (define-key ido-mode-map "\C-o" 'ido-copy-current-word)
    (define-key ido-mode-map "\C-v" 'ido-toggle-vc)
    (define-key ido-mode-map "\C-w" 'ido-copy-current-file-name)
    )

  (when (eq ido-cur-item 'buffer)
    (define-key ido-mode-map "\C-b" 'ido-fallback-command)
    (define-key ido-mode-map "\C-f" 'ido-enter-find-file)
    (define-key ido-mode-map "\C-k" 'ido-kill-buffer-at-head)
    ))

;;}}} ido {end}--------------------



;;{{{ auto save of the time of last change {begin}--------------------

;; set up the time stamp so that the time and date of last change can be saved
;; according to the following webpage: http://zhdotemacs.sourceforge.net/emacs/timestamp.html
(add-hook 'write-file-hooks 'time-stamp)
(setq time-stamp-format "%:u %02m/%02d/%04y %02H:%02M:%02S") ; format: username  mm/dd/yy hh/mm/ss

;;}}} auto save of the time of last change {end}--------------------



;;{{{ set up rect mark for selected region {begin}--------------------

;; according to rect-mark.el
;; press Shift and drag mouse to highlight a region
;; Support for marking a rectangle of text with highlighting.
(require 'rect-mark)

;; Use this section in your "~/.emacs" when rect-mark isn't included
;; as an integral part of Emacs.  Don't forget to remove the first
;; three columns.

;; ;; Support for marking a rectangle of text with highlighting.

(define-key ctl-x-map "r\C-@" 'rm-set-mark)
(define-key ctl-x-map [?r ?\C-\ ] 'rm-set-mark)
;; bind C-x r C-x to rm-exchange-point-and-mark===> working great with C-x C-x:
;; exchange-point-and-mark
(define-key ctl-x-map "r\C-x" 'rm-exchange-point-and-mark)
(define-key ctl-x-map "r\C-w" 'rm-kill-region)
(define-key ctl-x-map "r\M-w" 'rm-kill-ring-save)
(define-key global-map [S-down-mouse-1] 'rm-mouse-drag-region)

(autoload 'rm-set-mark "rect-mark"
  "Set mark for rectangle." t)
(autoload 'rm-exchange-point-and-mark "rect-mark"
  "Exchange point and mark for rectangle." t)
(autoload 'rm-kill-region "rect-mark"
  "Kill a rectangular region and save it in the kill ring." t)
(autoload 'rm-kill-ring-save "rect-mark"
  "Copy a rectangular region to the kill ring." t)
(autoload 'rm-mouse-drag-region "rect-mark"
  "Drag out a rectangular region with the mouse." t)

;; ;; Use this section in your "~/.emacs" to modify picture mode so that
;; ;; it automatically uses the rect-mark equivalents of many commands.

;; ;; ;; One vision of a better picture mode.
(add-hook 'picture-mode-hook 'rm-example-picture-mode-bindings)
(autoload 'rm-example-picture-mode-bindings "rect-mark"
  "Example rect-mark key and mouse bindings for picture mode.")

;;}}} set up rect mark for selected region {end}--------------------



;;{{{ set up auto pair parentheses {begin}--------------------

;;right after you input left bracket or parenthesis, emacs automatically pair
;;the right one for your, including:(), "", [] , {}, etc.
(defun my-general-mode-auto-pair ()
  "Auto pair the matching parentheses."
  (interactive)
  (make-local-variable 'skeleton-pair-alist)
  (setq skeleton-pair-alist  '(
                               (?' _ "'")
                               (?\" _ "\"")
                               (?\( _ ")")
                               (?\[ _ "]")
                               (?{ \n > _ \n ?} >)))
  (setq skeleton-pair t)
  (local-set-key (kbd "(") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "{") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "'") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "\"") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "[") 'skeleton-pair-insert-maybe))

(add-hook 'java-mode-hook 'my-general-mode-auto-pair)
(add-hook 'perl-mode-hook 'my-general-mode-auto-pair)
(add-hook 'php-mode-hook 'my-general-mode-auto-pair)
(add-hook 'BibTeX-mode 'my-general-mode-auto-pair)

(defun my-c-mode-auto-pair ()
  "Auto pair the matching parentheses specialized for C/C++ programming."
  (interactive)
  (make-local-variable 'skeleton-pair-alist)
  (setq skeleton-pair-alist  '(
                               (?' _ "'")
                               (?\" _ "\"")
                               (?\( _ ")")
                               (?\[ _ "]")))
  (setq skeleton-pair t)
  (local-set-key (kbd "(") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "'") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "\"") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "[") 'skeleton-pair-insert-maybe))

(add-hook 'c-mode-hook 'my-general-mode-auto-pair)
(add-hook 'c++-mode-hook 'my-general-mode-auto-pair)

;; define my version of paratheses pair strategy for matlab mode
(defun my-matlab-mode-auto-pair ()
  "Auto pair the matching parentheses specialized for Matlab programming."
  (interactive)
  (make-local-variable 'skeleton-pair-alist)
  (setq skeleton-pair-alist  '(
                               (?' _ "'")
                               (?\( _ ")")
                               (?\[ _ "]")
                               (?\{ _ "}")))
  (setq skeleton-pair t)
  (local-set-key (kbd "(") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "{") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "'") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "[") 'skeleton-pair-insert-maybe))

(add-hook 'matlab-mode-hook 'my-matlab-mode-auto-pair)
(add-hook 'sh-mode-hook 'my-matlab-mode-auto-pair)

;; define my version of paratheses pair strategy for all AucTeX modes
(defun my-TeX-mode-auto-pair ()
  "Auto pair the matching parentheses specialized for TeX/LaTeX."
  (interactive)
  (make-local-variable 'skeleton-pair-alist)
;; version 1: (),{},[],$$
  (setq skeleton-pair-alist  '(
                               (?\( _ ")")
                               (?\[ _ "]")
                               (?\{ _ "}")
                               (?\$ _ "$")))

;; version 2: (  ),{  },[  ],$  $----->not used
;;   (setq skeleton-pair-alist  '(
;;                                (?\( ?  _ " )")
;;                                (?\[ ?  _ " ]")
;;                                (?\{ ?  _ " }")
;;                                (?\$ ?  _ " $")))
  (setq skeleton-pair t)
  (local-set-key (kbd "(") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "{") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "`") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "[") 'skeleton-pair-insert-maybe)
  (local-set-key (kbd "$") 'skeleton-pair-insert-maybe))

(add-hook 'TeX-mode-hook 'my-TeX-mode-auto-pair)
;; (add-hook 'LaTeX-mode-hook 'my-TeX-mode-auto-pair)
(add-hook 'emacs-lisp-mode-hook 'my-TeX-mode-auto-pair)
(add-hook 'org-mode-hook 'my-TeX-mode-auto-pair)
(add-hook 'bibtex-mode-hook 'my-TeX-mode-auto-pair)

;;}}} set up auto pair parentheses {end}--------------------



;;{{{ color theme {begin}--------------------

;; enable the color-theme package
(require 'color-theme) ; load  the color-theme package

;; Call function da-color-theme to change to the dark face, and call C-u da-color-theme for the yellow background face.
(require 'switch-color-theme-matlab-latex)
(global-set-key [f6] 'da-color-theme)

(da-color-theme) ; select my own color theme as default

(require 'zenburn)

;;}}} color theme {end}--------------------



;;{{{ file header {begin}--------------------

;; use M-x make-header to auto write fire header for my source codes
(require 'header2)
;; Do this in your ~/.emacs:according to the header2.el

;; User options (variables) defined here:
;;
;;   `header-copyright-notice', `header-history-label', `header-max',
;;   `make-header-hook'
;;
;; Other variables defined here:
;;
;;   `file-header-update-alist', `header-prefix-string', `return-to'
(setq header-copyright-notice "Da Zhang MGH Radiology\n")
(setq header-modification-author "Da Zhang\n")
(setq make-header-hook '( header-file-name
                          header-author
                          header-copyright
                          header-usage
                          header-compile
                          header-system
                          header-bugs
                          header-creation-date
                          header-modification-date
                          header-update-count
                          header-description
                          header-mode-line
                          header-code
                          header-eof
                          ))
(make-local-variable 'user-full-name)
(make-local-variable 'user-mail-address)

;; Update file headers when write files.
(add-hook 'write-file-hooks 'update-file-header)
;; Create headers for file buffers in my favorite modes.
(add-hook 'emacs-lisp-mode-hook 'auto-make-header)
(add-hook 'c-mode-common-hook   'auto-make-header)
(add-hook 'c++-mode-hook   'auto-make-header)
(add-hook 'java-mode-hook   'auto-make-header)
(add-hook 'perl-mode-hook   'auto-make-header)

(defun my-matlab-mode-auto-make-header ()
  "Auto make header for matlab code."
  (interactive)
  (make-local-variable 'make-header-hook)
  (setq make-header-hook '( header-file-name
                            header-author
                            header-copyright
                            header-usage
                            header-compile
                            header-system
                            header-bugs
                            header-creation-date
                            header-modification-date
                            header-update-count
                            header-description
                            header-mode-line
                            header-matlab-code-begin
                            header-matlab-code-end
                            )))
(add-hook 'matlab-mode-hook 'my-matlab-mode-auto-make-header)

(defun my-org-mode-auto-make-header ()
  "Auto make header for matlab code."
  (interactive)
  (make-local-variable 'make-header-hook)
  (setq make-header-hook '( header-org-mode
                            )))
(add-hook 'org-mode-hook 'my-org-mode-auto-make-header)

(defun my-perl-mode-auto-make-header ()
  "Auto make header for matlab code."
  (interactive)
  (make-local-variable 'make-header-hook)
  (setq make-header-hook '(header-perl-header-begin 
                           header-file-name
                           header-author
                           header-creation-date
                           header-modification-date
                           header-update-count
                           header-description
                           header-mode-line
                           header-perl-code-begin
                           )))
(add-hook 'perl-mode-hook 'my-perl-mode-auto-make-header)


;;}}} file header {end}--------------------



;;{{{ redo {begin}--------------------

(require 'redo)
(global-set-key (kbd "C-?") 'redo)

;;}}} redo {end}--------------------



;;{{{ scroll without cursor moving {begin}--------------------

;; scroll functions
(defun hold-line-scroll-up()
  "Scroll the page with the cursor in the same line"
  (interactive)
  (let ((next-screen-context-lines
         (count-lines
          (window-start) (window-end)
          )
         ))
    (scroll-up)
    ))
(defun hold-line-scroll-down()
  "Scroll the page with the cursor in the same line"
  (interactive)
  (let ((next-screen-context-lines
         (count-lines
          (window-start) (window-end)
          )
         ))
    (scroll-down)
    ))
;; while scroll up/down by holding Ctrl and mouse wheel up/down, the cursor doesn't move within the current
;; window, and scroll line by line.
(global-set-key (kbd "<C-wheel-up>") 'hold-line-scroll-up)
(global-set-key (kbd "<C-wheel-down>") 'hold-line-scroll-down)

;;}}} scroll without cursor moving {end}--------------------



;;{{{ shell toggle {begin}--------------------

(autoload 'shell-toggle "da-shell-toggle"
 "Toggles between the *shell* buffer and whatever buffer you are editing."
 t)
(autoload 'shell-toggle-cd "da-shell-toggle"
 "Pops up a shell-buffer and insert a \"cd <file-dir>\" command." t)

(global-set-key (kbd "C-M-'") 'shell-toggle-cd)
(global-set-key (kbd "C-'") 'shell-toggle)
(global-set-key (kbd "C-M-!") 'shell-command)

(defun open-buffer-path ()
  "Run explorer on the directory of the current buffer."
  (interactive)
  (shell-command
   (concat "explorer "  (replace-regexp-in-string "/" "\\\\" 
                                                  (if (eq major-mode 'dired-mode)
                                                      dired-directory
                                                    (file-name-directory (buffer-file-name))) t t))))

;; (defun run-shell-at-buffer-path ()
;;   "Run explorer on the directory of the current buffer."
;;   (interactive)
;;   (shell-command
;;    (concat "bash " " -c " (concat "'cd " (replace-regexp-in-string "/" "\\\\" 
;;                                                   (if (eq major-mode 'dired-mode)
;;                                                       dired-directory
;;                                                     (file-name-directory (buffer-file-name))) t t) "'" ))

;;}}} shell toggle {end}--------------------



;;{{{ dired mode {begin}--------------------

;; enable dired to visit subfolders in the current buffer by typing "a"
(put 'dired-find-alternate-file 'disabled nil)

;; dired+ mode
(require 'dired+)
(require 'dired-details)
;; use ( or ) to toggle the details shown in dired
(require 'dired-details+)

;; find-dired
(require 'find-dired)
(setq find-ls-option '("-print0 | xargs -0 ls -ld" . "-ld"))

;; Hack dired to launch files mouse clicking
;; and Ret to open the dir into the same buffer
(require 'w32-browser)

;; open the father path using M-<up>
(add-hook 'dired-mode-hook (lambda ()
                             (interactive)
                             (define-key dired-mode-map (kbd "<M-up>")
                               'dired-up-directory)
                             (define-key dired-mode-map
                               "c" 'diredp-copy-this-file)
                             ;; (define-key dired-mode-map
                             ;;   [M-f8] 'dired-w32-browser) ;; open in window associated application
                             (define-key dired-mode-map
                               (kbd "<C-M-return>") 'dired-w32-browser) ;; open in window associated application
                             (define-key dired-mode-map
                               "\r" 'dired-find-alternate-file)))

;; we want dired not not make always a new buffer if visiting a directory
;; but using only one dired buffer for all directories.
(defadvice dired-advertised-find-file (around dired-subst-directory activate)
  "Replace current buffer if file is a directory."
  (interactive)
  (let ((orig (current-buffer))
        (filename (dired-get-filename)))
    ad-do-it
    (when (and (file-directory-p filename)
               (not (eq (current-buffer) orig)))
      (kill-buffer orig))))

(eval-after-load "dired"
  ;; don't remove `other-window', the caller expects it to be there
  '(defun dired-up-directory (&optional other-window)
     "Run Dired on parent directory of current directory."
     (interactive "P")
     (let* ((dir (dired-current-directory))
     	    (orig (current-buffer))
     	    (up (file-name-directory (directory-file-name dir))))
       (or (dired-goto-file (directory-file-name dir))
     	   ;; Only try dired-goto-subdir if buffer has more than one dir.
     	   (and (cdr dired-subdir-alist)
                (dired-goto-subdir up))
     	   (progn
     	     (kill-buffer orig)
     	     (dired up)
     	     (dired-goto-file dir))))))

;; enable dired to recursively copy and delete files and directories
(setq dired-recursive-copies 'top)
(setq dired-recursive-deletes 'top)

;; sorting functionality in dired
;; ss sort according to file size
;; sx sort according to file extention
;; st sort according to access time
;; sn sort according to file name
(add-hook 'dired-mode-hook (lambda ()
  (interactive)
  (make-local-variable  'dired-sort-map)
  (setq dired-sort-map (make-sparse-keymap))
  (define-key dired-mode-map "s" dired-sort-map)
  (define-key dired-sort-map "s"
    '(lambda () "sort by Size"
       (interactive) (dired-sort-other (concat dired-listing-switches "S"))))
  (define-key dired-sort-map "x"
    '(lambda () "sort by eXtension"
       (interactive) (dired-sort-other (concat dired-listing-switches "X"))))
  (define-key dired-sort-map "t"
    '(lambda () "sort by Time"
       (interactive) (dired-sort-other (concat dired-listing-switches "t"))))
  (define-key dired-sort-map "n"
    '(lambda () "sort by Name"
       (interactive) (dired-sort-other (concat dired-listing-switches ""))))))

;; put folder at the top of the list
(defun dired-sort-dir-first ()
  "Dired sort hook to list directories first."
  (save-excursion
    (let (buffer-read-only)
      (forward-line 2) ;; beyond dir. header
      (sort-regexp-fields t "^.*$" "[ ]*." (point) (point-max))))
  (and (featurep 'xemacs)
       (fboundp 'dired-insert-set-properties)
       (dired-insert-set-properties (point-min) (point-max)))
  (set-buffer-modified-p nil))
(add-hook 'dired-after-readin-hook 'dired-sort-dir-first)

;; use C-x C-j to open the containing folder of the current file
;; C-x C-j open the directory of current buffer
(global-set-key (kbd "C-x C-j") 'open-dir-current-file)

(defun open-dir-current-file()
  (interactive)
  (if (buffer-file-name)
      (dired default-directory)))

;; omit certain file extensions that I don't want to see
;; use M-o to toggle omitting these files
(setq dired-omit-extensions '("CVS/" "~"
                              ".a" ".aux"
                              ".bin" ".lbin" ".blg"
                              ".class" ".cp" ".cps"
                              ".fasl" ".fas" ".fmt"
                              ".ufsl"  ".ln" ".fn" ".fns"
                              ".glo"
                              ".idx"
                              ".ky" ".kys"
                              ".la" ".lof" ".lot"
                              ".o"
                              ".pgs" ".pg"
                              ".sparcf"
                              ".tfm" ".toc" ".tp" ".tps"
                              ".vr" ".vrs"
                              ".x86f"))

;;}}} dired mode {end}--------------------



;;{{{ bm Bookmarks {begin}--------------------

;; Make sure the repository is loaded as early as possible
(setq bm-restore-repository-on-load t)
(require 'bm)

;; M$ Visual Studio key setup.
(global-set-key [(f2)]                  'bm-toggle)
(global-set-key [(control f2)]          'bm-previous)
(global-set-key [(shift f2)]            'bm-next)
(global-set-key [(meta f2)]             'bm-show-all)
(global-set-key [(control shift f2)]    'bm-remove-all-current-buffer)

(global-set-key [(f3)]                  'bm-next)
(global-set-key [(control f3)]          'bm-previous)

;; Click on fringe to toggle bookmarks, and use mouse wheel to move
;; between them.
(setq bm-marker 'bm-marker-left)
(setq bm-highlight-style 'bm-highlight-line-and-fringe)

;; (global-set-key (kbd "<left-fringe> <mouse-5>") 'bm-next-mouse)
;; (global-set-key (kbd "<left-fringe> <mouse-4>") 'bm-previous-mouse)
;; (global-set-key (kbd "<left-fringe> <mouse-1>") 'bm-toggle-mouse)

;; make bookmarks persistent as default
(setq bm-repository-file "c:/home/zhangda/bm-repository")
(setq-default bm-buffer-persistence t)

;; Update bookmark repository when saving the file.
(add-hook 'after-save-hook 'bm-buffer-save)

;; Restore bookmarks when buffer is reverted.
(add-hook 'after-revert-hook 'bm-buffer-restore)

;; Loading the repository from file when on start up.
(add-hook' after-init-hook 'bm-repository-load)

;; Restoring bookmarks when on file find.
(add-hook 'find-file-hooks 'bm-buffer-restore)

;; Saving bookmark data on killing a buffer
(add-hook 'kill-buffer-hook 'bm-buffer-save)

;; Saving the repository to file when on exit.
;; kill-buffer-hook is not called when Emacs is killed, so we
;; must save all bookmarks first.
(add-hook 'kill-emacs-hook '(lambda nil
                              (bm-buffer-save-all)
                              (bm-repository-save)))

;; make sure bookmarks is saved before check-in (and revert-buffer)
(add-hook 'vc-before-checkin-hook 'bm-buffer-save)

;;}}} bm Bookmarks {end}--------------------



;;{{{ word-count {begin}--------------------

;;; Final version: while
(defun word-count (beginning end)
  "Print number of words in the region."
  (interactive "r")
  (message "Counting words in region ... ")
;;; 1. Set up appropriate conditions.
  (save-excursion
    (let ((count 0))
      (goto-char beginning)
;;; 2. Run the while loop.
      (while (and (< (point) end)
                  (re-search-forward "\\w+\\W*" end t))
        (setq count (1+ count)))
;;; 3. Send a message to the user.
      (cond ((zerop count)
             (message
              "The region does NOT have any words."))
            ((= 1 count)
             (message
              "The region has 1 word."))
            (t
             (message
              "The region has %d words." count))))))

;;}}} word-count {end}--------------------



;;{{{ unicad {begin}--------------------

;; Unicad helps Emacs to guess the correct coding system when opening a file.
;; It's designed to work automatically and quietly without user interaction.
(require 'unicad)

;;}}} unicad {end}--------------------



;;{{{ pager {begin}--------------------

;; make the scroll up and scroll down act as in other softwares
;; pager.el stuff
(require 'pager)
(global-set-key "\C-v"     'pager-page-down)
(global-set-key [next]     'pager-page-down)
(global-set-key "\M-v"      'pager-page-up)
(global-set-key [prior]    'pager-page-up)
(global-set-key '[M-up]    'pager-row-up)
(global-set-key '[M-down]  'pager-row-down)

;;}}} pager {end}--------------------



;;{{{ unfill {begin}--------------------

;;; Stefan Monnier <foo at acm.org>. It is the opposite of
;;; fill-paragraph Takes a multi-line paragraph and makes it into a
;;; single line of text.
(defun unfill-paragraph ()
  "Reverse the effect of fill-paragraph: make a paragraph into a single line."
  (interactive)
  (let ((fill-column 46488))
    (fill-paragraph nil)))

(defun unfill-region ()
  "Do the opposite of fill-region; stuff all paragraphs in the current region into long lines."
  (interactive)
  (let ((fill-column 46488))
    (fill-region (point) (mark))))

(global-unset-key (kbd "C-M-q"))
(global-set-key (kbd "C-M-q") 'unfill-paragraph)

;;}}} unfill {end}--------------------



;;{{{ move up/down by multiple lines {begin}--------------------

;; Faster point movement
(global-set-key (kbd "C-M-p")
  '(lambda () (interactive) (previous-line 15)))

(global-set-key (kbd "C-M-n")
  '(lambda () (interactive) (next-line 15)))

;;}}} move up/down by multiple lines {end}--------------------



;;{{{ anything {begin}--------------------
(require 'anything-config)

(setq anything-map
  (let ((map (copy-keymap minibuffer-local-map)))
    (define-key map (kbd "<down>") 'anything-next-line)
    (define-key map (kbd "<up>") 'anything-previous-line)
    (define-key map (kbd "C-n") 'anything-next-line)
    (define-key map (kbd "C-p") 'anything-previous-line)
    (define-key map (kbd "<prior>") 'anything-previous-page)
    (define-key map (kbd "<next>") 'anything-next-page)
    (define-key map (kbd "<right>") 'anything-next-source)
    (define-key map (kbd "<left>") 'anything-previous-source)
    (define-key map (kbd "<RET>") 'anything-exit-minibuffer)
    (define-key map (kbd "C-1") 'anything-select-with-digit-shortcut)
    (define-key map (kbd "C-2") 'anything-select-with-digit-shortcut)
    (define-key map (kbd "C-3") 'anything-select-with-digit-shortcut)
    (define-key map (kbd "C-4") 'anything-select-with-digit-shortcut)
    (define-key map (kbd "C-5") 'anything-select-with-digit-shortcut)
    (define-key map (kbd "C-6") 'anything-select-with-digit-shortcut)
    (define-key map (kbd "C-7") 'anything-select-with-digit-shortcut)
    (define-key map (kbd "C-8") 'anything-select-with-digit-shortcut)
    (define-key map (kbd "C-9") 'anything-select-with-digit-shortcut)
    (define-key map (kbd "C-i") 'anything-select-action)
    map))

(global-set-key [C-f10]
  (lambda() (interactive)
    (anything
     :prompt "Switch to: "
     :candidate-number-limit 10                 ;; up to 10 of each 
     :sources
     '( anything-c-source-buffers               ;; buffers 
        anything-c-source-recentf               ;; recent files 
        anything-c-source-bookmarks             ;; bookmarks
        anything-c-source-files-in-current-dir+)))) ;; current dir
;;        anything-c-source-locate)))              ;; use 'locate'

;;}}} anything {end}--------------------



;;{{{ flyspell {begin}--------------------

;;; Use Aspell for spell checking
(add-hook 'text-mode-hook 'flyspell-mode)
(setq-default ispell-program-name "C:/Emacs/aspell/bin/aspell.exe")
(setq-default ispell-extra-args '("--sug-mode=ultra"))

;;}}} flyspell {end}--------------------



;;{{{ Tramp mode {begin}--------------------

(setq tramp-default-method "sshx")
;; (setq tramp-default-method "plink")
;; (setq tramp-verbose 10)
;; (setq tramp-debug-buffer t)

;;}}} Tramp mode {end}--------------------



;;{{{ Auto Complete {begin}--------------------

(global-set-key (kbd "<apps>") 'hippie-expand)
(global-set-key (kbd "<C-tab>") 'hippie-expand)
;; hippie-expand
(setq hippie-expand-try-functions-list
      '(senator-try-expand-semantic
        try-expand-dabbrev
        try-expand-dabbrev-visible
        try-expand-dabbrev-all-buffers
        try-expand-dabbrev-from-kill
        try-expand-all-abbrevs
        try-expand-list
        try-expand-list-all-buffers
        try-expand-line
        try-expand-line-all-buffers
        try-complete-file-name-partially
        try-complete-file-name
        try-complete-lisp-symbol-partially
        try-complete-lisp-symbol
        try-expand-whole-kill))

;; key bindings for specific modes

;; Auctex mode
(add-hook 'LaTeX-mode-hook
          '(lambda ()
          (define-key LaTeX-mode-map (kbd "<C-tab>")
            'TeX-complete-symbol)))

;; Matlab mode
(add-hook 'matlab-mode-hook
          '(lambda ()
          (define-key matlab-mode-map (kbd "<C-tab>")
            'matlab-complete-symbol)))

;; Emacs-Lisp mode
(add-hook 'emacs-lisp-mode-hook
          '(lambda ()
             (define-key emacs-lisp-mode-map (kbd "<C-tab>")
               'lisp-complete-symbol)))

(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "c:/Emacs/site-lisp/ac-dict")
(ac-config-default)

;;}}} Auto Complete {end}--------------------



;;{{{ Desktop and recentf {begin}--------------------

;; recentf stuff
(require 'recentf)
(recentf-mode t)
(setq recentf-max-menu-items 25)
(global-set-key "\C-x\ \C-r" 'recentf-open-files)

;;Note: for the outline-minor-mode-prefix to be successfully set to C-o,
;;this desktop setting must be placed after the settings of the outline
;;mode, especially the (setq outline-minor-mode-prefix "C-o")
(setq desktop-path (quote ("C:/home/zhangda/emacs-desktop-dir/")))
(setq desktop-dirname "C:/home/zhangda/emacs-desktop-dir")
(setq desktop-load-locked-desktop t)
(setq desktop-save-mode t)
(setq history-length 250)
(desktop-read) ; enable desktop function, which save all the buffers opened
               ; before exiting

;;}}} Desktop and recentf {end}--------------------



;;{{{ Info customize {begin}--------------------

(define-key Info-mode-map (kbd "M-n") 'forward-paragraph)

;;}}} Info customize {end}--------------------



;;{{{ my customized keybindings {begin}--------------------

;; global set key bindings for function keys

;; (global-set-key [f1] 'toggle-linum-mode)

;; (global-set-key [(f2)]                  'bm-toggle)
;; (global-set-key [(control f2)]          'bm-previous)
;; (global-set-key [(shift f2)]            'bm-next)
;; (global-set-key [(meta f2)]             'bm-show-all)
;; (global-set-key [(control shift f2)]    'bm-remove-all-current-buffer)

;; (global-set-key [(f3)]                  'bm-next)
;; (global-set-key [(control f3)]          'bm-previous)

(global-set-key [f4] 'repeat-complex-command)
(global-set-key [C-f4] 'call-last-kbd-macro)
(global-set-key [M-f4] 'ido-kill-buffer)

;; (define-key muse-mode-map [f5] 'muse-project-publish-this-file)

;; (global-set-key [f6] 'da-color-theme)
(global-set-key [C-f6] 'compile)

(global-set-key [f7] 'next-error)
(global-set-key [C-f7] 'previous-error)

(global-set-key [f8] 'da-revert-buffer)

(global-set-key [f9] 'dired)
(global-set-key [C-f9] 'speedbar-get-focus)
(global-set-key [M-f9] 'open-buffer-path)

(global-set-key [f10] 'anything)
;; (global-set-key [C-f10]
;;   (lambda() (interactive)
;;     (anything
;;      :prompt "Switch to: "
;;      :candidate-number-limit 10                 ;; up to 10 of each 
;;      :sources
;;      '( anything-c-source-buffers               ;; buffers 
;;         anything-c-source-recentf               ;; recent files 
;;         anything-c-source-bookmarks             ;; bookmarks
;;         anything-c-source-files-in-current-dir+)))) ;; current dir
;; ;;        anything-c-source-locate)))              ;; use 'locate'


(global-set-key [f11] 'query-replace-regexp)

;; (global-set-key [f12] 'remember)
;; (global-set-key [C-f12] 'gtd)
;; (global-set-key [M-f12] 'weblogger-start-entry)

;; comment/uncomment out region
(global-set-key (kbd "C-c ;") 'comment-region)
(global-set-key (kbd "C-c :") 'uncomment-region)

;; for my convinence, set M-n and M-p as follows
(global-set-key (kbd "M-n") 'forward-paragraph)
(global-set-key (kbd "M-p") 'backward-paragraph)

;; keybinding for backward C-k
(global-set-key ( kbd "C-S-k")
                 '(lambda () (interactive) (kill-line 0)))

(global-unset-key (kbd "C-z"))
(global-set-key (kbd "C-z") 'undo)
(global-set-key (kbd "C-S-z") 'redo)
;; enable the undo-tree mode: C-x u will open the undo-tree buffer for visualization
(require 'undo-tree)
(global-undo-tree-mode)

;; go to the  matching parenthesis or square bracket
(defun da-match-paren (arg)
  "Go to the matching paren if on a paren."
  (interactive "p")
  (cond ((and mark-active (looking-at "\\s\(")) (forward-list 1))
        ((and mark-active (looking-back "\\s\)")) (backward-list 1))
        ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
        ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
        ))

(global-set-key (kbd "M-[") 'da-match-paren)

(defun combine-lines (&optional arg)
  (interactive "P")
  (let ((rexp "\\(?:\\s-\\|\n\\)"))
    (progn
      (while (looking-back rexp)
        (delete-backward-char 1))
      (while (looking-at rexp)
        (delete-char 1))
      (unless arg
        (insert " ")))))

(global-set-key (kbd "M-]") 'combine-lines)

;; set up for temporary mark in files
(global-set-key (kbd "M-.") 'ska-point-to-register)
(global-set-key (kbd "M-,") 'ska-jump-to-register)
;; (global-set-key [(control \.)] 'ska-point-to-register)
;; (global-set-key [(control \,)] 'ska-jump-to-register)

(defun ska-point-to-register()
  "Store cursor position _fast_ in a register.
Use ska-jump-to-register to jump back to the stored
position."
  (interactive)
  (message "Point to register")
  (setq zmacs-region-stays t)
  (point-to-register 8))

(defun ska-jump-to-register()
  "Switches between current cursor position and position
that was stored with ska-point-to-register."
  (interactive)
  (message "Jump to register")
  (setq zmacs-region-stays t)
  (let ((tmp (point-marker)))
        (jump-to-register 8)
        (set-register 8 tmp)))

;; go-to-char
(global-set-key (kbd "C-c C-a") 'wy-go-to-char)

(defun wy-go-to-char (n char)
  "Move forward to Nth occurence of CHAR.
Typing `wy-go-to-char-key' again will move forwad to the next Nth
occurence of CHAR."
  (interactive "p\ncGo to char: ")
  (search-forward (string char) nil nil n)
  (while (char-equal (read-char) char)
    (search-forward (string char) nil nil n))
  (setq unread-command-events (list last-input-event)))

;; ;; hide region
;; (require 'hide-region)
;; (global-set-key (kbd "C-c r") 'hide-region-hide)
;; (global-set-key (kbd "C-c R") 'hide-region-unhide)

;; hide lines
(autoload 'hide-lines "hide-lines" "Hide lines based on a regexp" t)
(global-set-key (kbd "C-c M-l") 'hide-lines)
(global-set-key (kbd "C-c M-L") 'show-all-invisible)

;; word search
(global-set-key (kbd "M-s") 'word-search-forward)
(global-unset-key (kbd "M-r"))
(global-set-key (kbd "M-r") 'word-search-backward)

;; go to other window
(global-set-key [backtab] 'other-window)

;; global set key bindings for goto line
(global-set-key (kbd "M-g") 'goto-line)

;; global set key bindings for M-Spcace for set mark
(global-set-key (kbd "M-<SPC>") 'set-mark-command)

;; zoom in and out for emacs (text size adjust)
(global-set-key (kbd "<C-kp-add>") 'text-scale-increase)
(global-set-key (kbd "<C-kp-subtract>") 'text-scale-decrease)

(global-set-key (kbd "C-x C-f") 'ido-find-file)

(define-key org-mode-map (kbd "C-c [") 'reftex-citation)

;; (setq w32-enable-caps-lock nil)
;; (global-set-key [capslock] 'execute-extended-command) 

;;}}} my customized keybindings {end}--------------------



;;{{{ web blogger {begin}--------------------

;; (load-file "weblogger.el")
;; (require 'weblogger)

;; (add-hook 'weblogger-entry-mode-hook
          ;; (lambda ()
          ;;   (auto-fill-mode nil)))
;; (global-set-key [M-f12] 'weblogger-start-entry)

;; (autoload 'markdown-mode "markdown-mode.el"
;;    "Major mode for editing Markdown files" t)
;; (setq auto-mode-alist
;;    (cons '("\\.text" . markdown-mode) auto-mode-alist))

;; org2blog mode
(require 'org2blog-autoloads)
(setq org2blog/wp-blog-alist
      '(("wordpress"
         :url "http://zhangda.wordpress.com/xmlrpc.php"
         :username "zhangda"   
         :tags-as-categories nil)))

(global-set-key [C-M-f12] 'org2blog/wp-new-entry)

;;}}} web blogger {end}--------------------



;;{{{ Visual Basic {begin}--------------------

;; autoload visual-basic-mode
(autoload 'visual-basic-mode "visual-basic-mode" "Visual Basic mode." t)
(add-to-list 'auto-mode-alist '("\\.vbs\\'" . visual-basic-mode)) ;VBscript
(add-to-list 'auto-mode-alist '("\\.vb\\'" . visual-basic-mode))  ;visual basic .NET file
(add-to-list 'auto-mode-alist '("\\.bas\\'" . visual-basic-mode)) ;visual basic form
(add-to-list 'auto-mode-alist '("\\.frm\\'" . visual-basic-mode)) ;basic language source
;; (add-to-list 'auto-mode-alist '("\\.cls\\'" . visual-basic-mode)) ;C++ class definition file
(setq-default visual-basic-mode-indent 4)

;;}}} Visual Basic {end}--------------------



;;{{{ Emacs ppt {begin}--------------------

(defun org-mode-reftex-setup ()
  (load-library "reftex")
  (and (buffer-file-name)
       (file-exists-p (buffer-file-name))
       (reftex-parse-all))
  (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
  )
(add-hook 'org-mode-hook 'org-mode-reftex-setup)

;; for ditaa support in org mode
(require 'org-exp-blocks)

;; ditaa: java package to convert text graphics to png files, very good for flow charts
(setq ditaa-cmd "java -jar C:/downloads/software/ditaa/ditaa0_6b.jar")
(defun draw (saveas)
  (interactive "FSave As: ")
  (shell-command
    (concat ditaa-cmd " \"" buffer-file-name "\"" " " "\"" saveas "\""))) ;; use \" to pass "" for the path name

;; org mode && beamer integration
;; allow for export=>beamer by placing
;; #+LaTeX_CLASS: beamer in org files
(unless (boundp 'org-export-latex-classes)
  (setq org-export-latex-classes nil))

(add-to-list 'org-export-latex-classes
             '("beamer" 
               "\\documentclass[red]{beamer}\n
     \\usetheme{Darmstadt}\n
     \\usefonttheme[onlylarge]{structurebold}\n
     \\setbeamerfont*{frametitle}{size=\\normalsize,series=\\bfseries}\n
     \\setbeamertemplate{navigation symbols}{}\n
     \\usepackage[english]{babel}\n
     \\usepackage{times}\n
     \\usepackage[T1]{fontenc}\n
     \\usepackage{graphicx}\n
     \\usepackage{color}\n
     \\usepackage{tikz}\n
     \\usetikzlibrary{arrows}\n
     \\tikzstyle{block}=[draw opacity=0.7,line width=1.4cm]\n
     \\usepackage{listings}
     \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
     frame=single,
     basicstyle=\\small,
     showspaces=false,showstringspaces=false,
     showtabs=false,
     keywordstyle=\\color{blue}\\bfseries,
     commentstyle=\\color{red},
     }\n
     \\institute{Mass General Imaging}\n"
               ("\\section{%s}" . "\\section*{%s}")
               ("\\begin{frame}[fragile]\\frametitle{%s}"
                "\\end{frame}"
                "\\begin{frame}[fragile]\\frametitle{%s}"
                "\\end{frame}")))

(add-to-list 'org-export-latex-classes
             '("article"
               "\\documentclass [letterpaper, 11pt]{article}\n
\\usepackage{fullpage}\n
\\usepackage{setspace}\n
\\doublespacing\n
\\usepackage{amssymb}\n
\\usepackage{graphicx}\n
\\usepackage{subfigure}\n
\\usepackage{float}\n
\\usepackage{amsmath}\n
\\usepackage{cite}\n
\\usepackage{times}\n
\\usepackage[pdfpagemode = colorlinks, pdffitwindow = true, bookmarks = true, pdftoolbar = false, pdfmenubar = true, pdfnewwindow = true]{hyperref}\n
\\usepackage[left]{lineno}\n"
               ("\\section{%s}" . "\\section*{%s}")))

(add-to-list 'org-export-latex-classes
             '("compact"
               "\\documentclass [letterpaper, 10pt]{article}\n
\\usepackage{fullpage}\n
\\usepackage{setspace}\n
\\singlespacing\n
\\usepackage{times}\n
\\usepackage[compact]{titlesec}\n
\\titlespacing{\\section}{0pt}{*0}{*0}\n
\\titlespacing{\\subsection}{0pt}{*0}{*0}\n
\\titlespacing{\\subsubsection}{0pt}{*0}{*0}\n
\\usepackage{mdwlist}\n
\\usepackage[left=2cm,top=1cm,right=2cm,nohead,nofoot]{geometry}\n"
               ("\\section{%s}" . "\\section*{%s}")))

(add-to-list 'org-export-latex-classes
             '("MP"
               "\\documentclass [aip, numerical, linenumbers, preprint, prb, groupedaddress]{revtex4-1}\n
\\usepackage{graphicx}\n
\\usepackage{float}\n
\\usepackage{subfigure}\n
\\usepackage{amssymb}\n
\\usepackage{amsmath}\n"
               ("\\section{%s}" . "\\section*{%s}")))

;;}}} Emacs ppt {end}--------------------



;;{{{ Org to S5 {begin}--------------------

(load-file "C:/Emacs/site-lisp/org-export-as-s5.el")
(setq org-s5-theme "railscast")   ; based off `color-theme-railscasts'
(setq org-s5-theme "default")     ; the default S5 theme
(setq org-s5-theme "i18n")        ; the i18n theme by the author of S5

;;}}} Org to S5 {end}--------------------



;;{{{ Ediff {begin}--------------------

;; Diff the current buffer with the file contents
(global-set-key (kbd "C-c w") 'diff-buffer-with-file)

;;}}} Ediff {end}--------------------


;;{{{ CUA {begin}--------------------

;; only use the rectangular functionality of CUA mode
(setq cua-enable-cua-keys nil) ;; only for rectangles
(cua-mode t)
;; (global-set-key (kbd "<C-M-return>") 'cua-set-rectangle-mark)

;;}}} CUA {end}--------------------



;;{{{ Comment line {begin}--------------------

(defun comment-line ()
  "comment line at point."
  (interactive)
  (beginning-of-line)
  (let
      ((beg (point)))
    (end-of-line)
    (comment-region beg (point))))

(global-set-key (kbd "C-M-;") 'comment-line)

;;}}} comment line {end}--------------------



;;{{{ windmove {begin}--------------------

;; Windmove is a package that allows you to move point from window to window
;; using Shift and the arrow keys. This is easier to type than C-x o and, for
;; some users, may be more intuitive
(when (fboundp 'windmove-default-keybindings)
  (windmove-default-keybindings))

;;}}} windmove {end}--------------------



;;{{{ sml modeline {begin}--------------------

(if (require 'sml-modeline nil 'noerror)    ;; use sml-modeline if available
  (progn 
    (sml-mode t)                   ;; show buffer pos in the mode line
    ;; (scroll-bar-mode -1)
    )                   ;; turn off the scrollbar
  (scroll-bar-mode 1)                       ;; otherwise, show a scrollbar...
  (set-scroll-bar-mode 'right))             ;; ... on the right

;;}}} sml modeline {end}--------------------



;;{{{ format bib {begin}--------------------

(require 'fbib)

;;}}} format bib {end}--------------------



;;{{{ C++ Programming {begin}--------------------

;; C++ coding style definition
;; (defconst *my-cc-style*
;;   '((c-basic-offset . 4)
;;     (c-comment-only-line-offset 0 . 0)
;;     (c-comment-only-line-offset . 0)
;;     (c-hanging-braces-alist . ((brace-list-open)
;;                                (brace-entry-open)
;;                                (block-close . c-snug-do-while)
;;                                (arglist-cont-nonempty)
;;                                (substatement-open before after)))
;;     (c-cleanup-list . (brace-else-brace))
;;     (c-offsets-alist . ((statement-block-intro . +)
;;                         (knr-argdecl-intro     . 0)
;;                         (label . 0)
;;                         (statement-case-open . +)
;;                         (statement-cont . +)
;;                         (substatement-open     . 0)
;;                         (substatement-label    . 0)
;;                         (arglist-intro . c-lineup-arglist-intro-after-paren)
;;                         (arglist-close . c-lineup-arglist)
;;                         (inline-open . 0)
;;                         (innamespace           . 0)
;;                         (case-label            . +)
;;                         (brace-list-open . +)
;;                         (topmost-intro-cont first c-lineup-topmost-intro-cont c-lineup-gnu-DEFUN-intro-cont)
;;                         (statement-cont        . +)))
;;     (c-special-indent-hook . c-gnu-impose-minimum)
;;     (c-block-comment-prefix . "")))

(defun my-c-initialization-hook ()
  (define-key c-mode-base-map "\C-m" 'c-context-line-break)
  (define-key c-mode-base-map (kbd "RET") 'reindent-then-newline-and-indent))

(add-hook 'c-initialization-hook 'my-c-initialization-hook)
;; (setq c-offsets-alist '((member-init-intro . ++)))

;; (c-add-style "PERSONAL" *my-cc-style*)

(defun my-c-mode-common-hook ()
  (c-set-style "stroustrup") ;;PERSONAL
  (setq tab-width 4
        indent-tabs-mode nil
        c-hungry-delete-key t)
  (c-toggle-auto-newline 1)
  (linum-mode 1))

(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

(add-hook 'c++-mode-common-hook 'my-c-mode-common-hook)

;;}}} C++ Programming {end}--------------------



;;{{{ rainbow mode {begin}--------------------

;; for colorful display of color names when setting up emacs colors
(require 'rainbow-mode)

;;}}} rainbow mode {end}--------------------



;;{{{ folding {begin}--------------------

;; folding: hide/show marked region from viewing. Key bindings are prefixed with
;; "C-c@" instead of old "C-c". To use the old keyboard bindings, uncomment the
;; following lines: (setq folding-default-keys-function
;; 'folding-bind-backward-compatible-keys)

(if (load "folding" 'nomessage 'noerror)
    (folding-mode-add-find-file-hook))

;; whether to fold buffer when starting the Folding mode
(setq folding-folding-on-startup t)
(setq folding-narrow-by-default t)
(if (load "folding" 'nomessage 'noerror)
	(folding-mode-add-find-file-hook))

;; (global-set-key (kbd "C-c @ C-e") 'folding-show-current-entry)
(global-set-key (kbd "C-c f") 'folding-toggle-show-hide)

;;}}} folding {end}--------------------



;;{{{ cedet 1.0 {begin}--------------------

;; Load CEDET.
;; See cedet/common/cedet.info for configuration details.
(load-file "C:/Emacs/site-lisp/cedet/common/cedet.el")


;; Enable EDE (Project Management) features
(global-ede-mode 1)

;; Enable EDE for a pre-existing C++ project
;; (ede-cpp-root-project "NAME" :file "~/myproject/Makefile")


;; Enabling Semantic (code-parsing, smart completion) features
;; Select one of the following:

;; * This enables the database and idle reparse engines
(semantic-load-enable-minimum-features)

;; * This enables some tools useful for coding, such as summary mode
;;   imenu support, and the semantic navigator
(semantic-load-enable-code-helpers)

;; * This enables even more coding tools such as intellisense mode
;;   decoration mode, and stickyfunc mode (plus regular code helpers)
;; (semantic-load-enable-gaudy-code-helpers)

;; * This enables the use of Exuberent ctags if you have it installed.
;;   If you use C++ templates or boost, you should NOT enable it.
;; (semantic-load-enable-all-exuberent-ctags-support)
;;   Or, use one of these two types of support.
;;   Add support for new languges only via ctags.
;; (semantic-load-enable-primary-exuberent-ctags-support)
;;   Add support for using ctags as a backup parser.
;; (semantic-load-enable-secondary-exuberent-ctags-support)

;; Enable SRecode (Template management) minor-mode.
;; (global-srecode-minor-mode 1)

;; To use additional features for names completion, and displaying of information for tags & classes
(require 'semantic-ia)

;; C/C++, semantic automatically load /usr/include as index database
(setq semanticdb-search-system-databases t)

;; Semantic can automatically find path, where system include files are located when gcc is used
(require 'semantic-gcc)

;; add the following gcc include libraries to the semantic system include list
(eval-after-load "semantic-c"
  '(dolist (d (list "C:/cygwin/lib/gcc/i686-pc-cygwin/3.4.4/include"
                    "C:/cygwin/lib/gcc/i686-pc-cygwin/3.4.4/include/c++"
                    "C:/cygwin/lib/gcc/i686-pc-cygwin/3.4.4/include/i686-pc-cygwin"
                    "C:/cygwin/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/backward"
                    "C:/cygwin/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits"
                    "C:/cygwin/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/debug"
                    "C:/cygwin/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/ext"
                    "C:/cygwin/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/i686-pc-cygwin/bits"
                    "C:/cygwin/usr/local/include"
                    "C:/cygwin/usr/include/w32api"
                    ))
     (semantic-add-system-include d)))

;; set up cedet
(autoload 'speedbar-frame-mode "speedbar" "Popup a speedbar frame" t)
(autoload 'speedbar-get-focus "speedbar" "Jump to speedbar frame" t)
(define-key-after (lookup-key global-map [menu-bar tools])
  [speedbar]
  '("Speedbar" .
    speedbar-frame-mode)
  [calendar])

;; set up the default path for semantic to store its analysis results
(setq semanticdb-default-save-directory
(expand-file-name "~/.emacs.d/semanticdb"))

;; prevent semantic use too much of CPU time
(setq-default semantic-idle-scheduler-idle-time 432000)

;; key bindings for auto completion
(defun my-cedet-hook ()
  (local-set-key [(meta return)] 'semantic-ia-complete-symbol)
  (local-set-key "\C-c?" 'semantic-ia-complete-symbol-menu)
  (local-set-key "\C-c>" 'semantic-complete-analyze-inline)
  (local-set-key "\C-cp" 'semantic-analyze-proto-impl-toggle)
  (local-set-key "." 'semantic-complete-self-insert)
  (local-set-key ">" 'semantic-complete-self-insert))
(add-hook 'c-mode-common-hook 'my-cedet-hook)

;; project root path
(setq semanticdb-project-roots
      (list
       (expand-file-name "/")))

(autoload 'senator-try-expand-semantic "senator")

;; speedbar key binding, n and p for "next" and "previous" movement, + and - as
;; show or hide directory, g for refresh
;; speed bar settings
(setq speedbar-show-unknown-files t) ; display all directories and files
;; (setq dframe-update-speed nil) ; don't use automatic refresh of speed bar, press g instead
;; (setq speedbar-update-flag nil)
;; (setq speedbar-use-images nil) ; don't use image
(setq speedbar-verbosity-level 0)
;; (require 'wisent)
;;}}} cedet 1.0 {end}--------------------



;;{{{ matlab-emacs {begin}--------------------
(add-to-list 'load-path "c:/Emacs/site-lisp/matlab-emacs/")
(require 'matlab-load)

;; Enable CEDET feature support for MATLAB code. (Optional)
(matlab-cedet-setup)

(setq-default matlab-highlight-cross-function-variables t)

(add-hook 'matlab-mode-hook
          '(lambda ()
             (define-key matlab-mode-map "\M-;" 'comment-dwim)
             (linum-mode 1)))

;; some settings for the matlab-mode
(setq matlab-auto-fill nil)
(setq matlab-comment-anti-indent 0)
(setq matlab-indent-level 4)
(setq matlab-comment-column default-fill-column)
(setq matlab-comment-line-s "% ")
(setq matlab-comment-on-line-s " % ")
(setq matlab-comment-region-s "% ")
(setq matlab-completion-technique (quote increment))
(setq matlab-fill-fudge 5)
(setq matlab-fill-fudge-hard-maximum 100)
(setq matlab-fill-strings-flag nil)

(setq matlab-functions-have-end nil)

(setq matlab-highlight-cross-function-variables t)
(setq matlab-highlight-block-match-flag t)

(setq matlab-return-add-semicolon nil)
;; (setq-default matlab-show-mlint-warnings t)
;; (setq mlint-programs (quote ("mlint" "win32/mlint" "C:\\MATLAB2008a\\bin\\win32\\mlint.exe")))

(setq matlab-fill-code t)

;; turn off auto-verify on save
(setq matlab-verify-on-save-flag nil)

;; if you want function bodies indented
(setq-default matlab-indent-function nil)
(setq-default matlab-indent-function-body nil)

;;}}} old matlab emacs integration {end}--------------------



;;{{{ regexp helper {begin}--------------------

(require 're-builder)
(setq reb-re-syntax 'string)

;;}}} regexp helper {end}--------------------



;;{{{ auto byte-compile if .elc exist {begin}--------------------

(defun auto-byte-recompile ()
  "If the current buffer is in emacs-lisp-mode and there already exists an `.elc'
file corresponding to the current buffer file, then recompile the file."
  (interactive)
  (when (and (eq major-mode 'emacs-lisp-mode)
             (file-exists-p (byte-compile-dest-file buffer-file-name)))
    (byte-compile-file buffer-file-name)))

(add-hook 'after-save-hook 'auto-byte-recompile)

;; ignore byte-compile warnings
(setq byte-compile-warnings '(not nresolved
                                  free-vars
                                  callargs
                                  redefine
                                  obsolete
                                  noruntime
                                  cl-functions
                                  interactive-only
                                  ))

;;}}} auto byte-compile if .elc exist {end}--------------------



;;{{{ rainbow matching delimiters {begin}--------------------

(when (require 'rainbow-delimiters nil 'noerror) 
  (add-hook 'scheme-mode-hook 'rainbow-delimiters-mode)
  (add-hook 'emacs-lisp-mode-hook 'rainbow-delimiters-mode)
  (add-hook 'c-mode-hook 'rainbow-delimiters-mode)
  )

;;}}} rainbow matching delimiters {end}--------------------



;;{{{ browser and google search {begin}--------------------
    
;;point to the appropriate browser
(setq browse-url-firefox-program "C:/Program Files/Mozilla Firefox/firefox.exe")

(setq browse-url-browser-function 'browse-url-firefox
          browse-url-new-window-flag nil
          browse-url-firefox-new-window-is-tab nil)

(defun region-or-word (prompt)
  "Read a string from the minibuffer, prompting with PROMPT.
If `transient-mark-mode' is non-nil and the mark is active,
it defaults to the current region, else to the word at or before
point. This function returns a list (string) for use in `interactive'."
  (list (read-string prompt (or (and transient-mark-mode mark-active
                                     (buffer-substring-no-properties
                                      (region-beginning) (region-end)))
                                (current-word)))))
(defun google (string)
  "Ask a WWW browser to google string.
Prompts for a string, defaulting to the active region or the current word at
or before point."
  (interactive (region-or-word "Google: "))
  (browse-url (concat "http://google.com/search?num=100&q=" string)))

;;}}} browser and google search {end}--------------------



;;{{{ CUSTOM {begin}--------------------

;; these are setups come from the interactive customization tool CUSTOM:
;; Options-->Customize Emacs-->Browse Customization Groups-->...actually I don't
;; remember.

(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.
 '(TeX-electric-escape nil)
 '(TeX-electric-sub-and-superscript t)
 '(TeX-insert-braces t)
 '(TeX-newline-function (quote reindent-then-newline-and-indent))
 '(TeX-output-view-style (quote (("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$" "dvips %d -o && start \"\" %f") ("^dvi$" "." "yap -1 %dS %d") ("^pdf$" "." "pdfviewm \"\" %f") ("^html?$" "." "start \"\" %o"))))
 '(TeX-source-specials-places (quote ("cr" "display" "hbox" "math" "par" "parend" "vbox")))
 '(ediff-diff-options "--binary -w")
 '(focus-follows-mouse t)
 '(ido-create-new-buffer (quote never))
 '(ido-enable-flex-matching t)
 '(ido-enable-last-directory-history nil)
 '(ido-enable-regexp nil)
 '(ido-max-directory-size 300000)
 '(ido-max-file-prompt-width 0.1)
 '(ido-use-filename-at-point nil)
 '(ido-use-url-at-point t)
 '(ido-use-virtual-buffers t)
 '(ispell-choices-win-default-height 3)
 '(muse-file-extension "muse")
 '(muse-html-charset-default "utf-8")
 '(muse-html-encoding-default (quote utf-8))
 '(muse-html-meta-content-encoding (quote utf-8))
 '(muse-ignored-extensions (quote ("bz2" "gz" "[Zz]" "rej" "orig" "png" "hgignore" "gif" "css" "jpg" "html" "sh" "lftp" "pdf")))
 '(muse-mode-auto-p nil)
 '(muse-wiki-allow-nonexistent-wikiword nil)
 '(muse-wiki-use-wikiword nil)
 '(org-agenda-files (quote ("c:/H/GTD/this_week.org")))
 '(org-export-latex-tables-column-borders nil)
 '(org-modules (quote (org-bbdb org-bibtex org-gnus org-info org-jsinfo org-irc org-mew org-mhe org-rmail org-vm org-wl org-w3m org-exp-blocks)))
 '(org-tags-column -110)
 '(overflow-newline-into-fringe nil)
 '(preview-auto-cache-preamble t)
 '(preview-gs-command "gs")
 '(preview-image-type (quote pnm))
 '(preview-preserve-counters t)
 '(preview-transparent-border nil)
 '(preview-transparent-color (quote (default :background)))
 '(revert-without-query (quote (".*.m")))
 '(uniquify-after-kill-buffer-p t)
 '(uniquify-buffer-name-style (quote post-forward-angle-brackets) nil (uniquify))
 '(uniquify-ignore-buffers-re "^\\*")
 '(uniquify-separator "|")
 '(w32shell-cygwin-bin "C:\\cygwin\\bin")
 '(weblogger-config-alist (quote (("default" "http://zhangda.wordpress.com/xmlrpc.php" "zhangda" "" "7259137")))))

 ;; '(preview-gs-command "C:/Program Files/gs/gs8.64/bin/gswin32c.exe")
;; MS default font set as andale mono, 13 pt (height) these are setups come from
;; the interactive customization tool CUSTOM: Options-->Customize Emacs-->Browse
;; Customization Groups-->Faces-->Basic Faces-->Face Default-->height

(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 (:height 120 :width normal :foundry "outline" :family "Bitstream Vera Sans Mono"))))
 '(matlab-cellbreak-face ((t (:foreground "YellowGreen" :weight bold))))
 '(sml-end-face ((t (:inherit match :background "gray30" :foreground "DarkOrange" :weight bold))))
 '(sml-vis-face ((t (:inherit region :weight bold :foreground "orange")))))

;;}}} CUSTOM {end}--------------------



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;temporarily disabled;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;{{{ old matlab emacs integration {begin}--------------------

;; ;; from Matlab 6.5
;; ;; Edit the path in the following line to reflect the
;; ;; actual location of the MATLAB root directory on your system.
;; ;; (add-to-list (add-to-list 'load-path "c:/Matlab6p5/java/extern/EmacsLink/lisp/"))
;; ;; (autoload 'matlab-eei-connect "matlab-eei"
;; ;;   "Connects Emacs to MATLAB's external editor interface.")

;; ;; (autoload 'matlab-mode "matlab" "Enter Matlab mode." t)
;; ;; (setq auto-mode-alist (cons '("\\.m\\'" . matlab-mode) auto-mode-alist))
;; ;; (autoload 'matlab-shell "matlab" "Interactive Matlab mode." t)

;; ;; from Matlab 7 or later
;; ;; Edit the path in the following line to reflect the
;; ;; actual location of the MATLAB root directory on your system.

;; ;; (add-to-list 'load-path "C:/MATLAB2008a/java/extern/EmacsLink/lisp")

;; (autoload 'matlab-eei-connect "matlab-eei" 
;;   "Connects Emacs to MATLAB's external editor interface.")

;; (autoload 'matlab-mode "matlab" "Enter Matlab mode." t)

;; (add-to-list 'auto-mode-alist '("\\.m\\'" . matlab-mode))

;; (autoload 'matlab-shell "matlab" "Interactive Matlab mode." t)

;; ;; Uncomment the next four lines to enable use of the tlc mode 
;; ;; (require 'tlc)
;; ;; (autoload 'tlc-mode "tlc" "tlc Editing Mode" t)
;; ;; (add-to-list 'auto-mode-alist '("\\.tlc$" . tlc-mode))
;; ;; (setq tlc-indent-function t)


;; ;; Uncomment the next two lines to enable use of the mlint package provided
;; ;; with EmacsLink.

;; (setq-default matlab-show-mlint-warnings t)
;; (setq-default matlab-highlight-cross-function-variables t)

;; ;; Note: The mlint package checks for common M-file coding
;; ;; errors, such as omitting semicolons at the end of lines.
;; ;; mlint requires Eric Ludlam's cedet package.

;; (add-hook 'matlab-mode-hook
;;           '(lambda ()
;;              (imenu-add-to-menubar "Find")
;;              (define-key matlab-mode-map "\M-;" 'comment-dwim)
;;              (linum-mode 1)))
;; ;; if you want function bodies indented
;; (setq-default matlab-indent-function nil)
;; (setq-default matlab-indent-function-body nil)

;; ;; turn off auto-verify on save
;; (setq matlab-verify-on-save-flag nil)

;; ;; some settings for the matlab-mode
;; (setq matlab-auto-fill nil)
;; (setq matlab-comment-anti-indent 0)
;; (setq matlab-comment-column default-fill-column)
;; (setq matlab-comment-line-s "% ")
;; (setq matlab-comment-on-line-s " %")
;; (setq matlab-comment-region-s "% ")
;; (setq matlab-completion-technique (quote increment))
;; (setq matlab-fill-fudge 5)
;; (setq matlab-fill-fudge-hard-maximum 100)
;; (setq matlab-fill-strings-flag nil)

;; (setq matlab-functions-have-end nil)

;; (setq matlab-highlight-cross-function-variables t)
;; (setq matlab-highlight-block-match-flag t)

;; (setq matlab-return-add-semicolon nil)
;; (setq mlint-programs (quote ("mlint" "win32/mlint" "C:\\MATLAB2008a\\bin\\win32\\mlint.exe")))

;; (setq matlab-fill-code t)

;; (defun my-matlab-mode-hook ()
;;   (imenu-add-to-menubar "Find"))		; where auto-fill should wrap
;; (add-hook 'matlab-mode-hook 'my-matlab-mode-hook)

;; ;; mode specific key bindings: for matlab-mode, press F5 for save and go.
;; ;; (add-hook 'matlab-mode-hook
;; ;;           '(lambda ()
;; ;;              (define-key matlab-mode-map [f5] 'matlab-shell-save-and-go)
;; ;;              (define-key matlab-mode-map [S-f5] 'matlab-eei-exit-debug)
;; ;;              (define-key matlab-mode-map [f9] 'matlab-eei-go-until-cursor)
;; ;;              (define-key matlab-mode-map [f10] 'matlab-eei-step)
;; ;;              (define-key matlab-mode-map [S-f10] 'matlab-eei-continue)
;; ;;              (define-key matlab-mode-map [f11] 'matlab-eei-step-in)
;; ;;              (define-key matlab-mode-map [S-f11] 'matlab-eei-step-out)
;; ;;              (define-key matlab-mode-map [f12] 'matlab-eei-breakpoint-set-clear)
;; ;;              (define-key matlab-mode-map [S-f12] 'matlab-eei-clear-breakpoints)))

;;}}} old matlab emacs integration {end}--------------------



;;{{{ cscope {begin}--------------------

;; (require 'xcscope)
;; (global-set-key "\C-xg" 'cscope-find-global-definition-no-prompting)

;;}}} cscope {end}--------------------



;;{{{ Smart Tab {begin}--------------------
;; ;; Smart Tab
;; (defvar smart-tab-using-hippie-expand t
;;   "turn this on if you want to use hippie-expand completion.")

;; ;; (global-set-key [(tab)] 'smart-tab)
;; (defun smart-tab (prefix)
;;   "Needs `transient-mark-mode' to be on. This smart tab is
;; minibuffer compliant: it acts as usual in the minibuffer.

;; In all other buffers: if PREFIX is \\[universal-argument], calls
;; `smart-indent'. Else if point is at the end of a symbol,
;; expands it. Else calls `smart-indent'."
;;   (interactive "P")
;;   (if (minibufferp)
;;       (minibuffer-complete)
;;     (if (smart-tab-must-expand prefix)
;;         (if smart-tab-using-hippie-expand
;;             (hippie-expand nil)
;;           (dabbrev-expand nil))
;;       (smart-indent))))

;; (defun smart-indent ()
;;   "Indents region if mark is active, or current line otherwise."
;;   (interactive)
;;   (if mark-active
;;       (indent-region (region-beginning)
;;                      (region-end))
;;     (indent-for-tab-command)))

;; (defun smart-tab-must-expand (&optional prefix)
;;   "If PREFIX is \\[universal-argument], answers no.
;; Otherwise, analyses point position and answers."
;;   (unless (or (consp prefix)
;;               mark-active)
;;     (looking-at "\\_>")))

;;}}} Smart Tab {end}--------------------



;;{{{ enable the auto indent so that emacs automatically indent {begin}--------------------

;; (global-set-key "\C-j" 'newline)
;; (global-set-key (kbd "RET") 'reindent-then-newline-and-indent)

;; ;; (global-set-key "\C-m" 'newline-and-indent)
;; ;; OR:
;; ;; (add-hook 'c-mode-common-hook
;; ;;           (lambda ()
;; ;;             (define-key c-mode-map
;; ;;              "\C-m" 'reindent-then-newline-and-indent)))

;;}}} enable the auto indent so that emacs automatically indent {end}--------------------



;;{{{ use hideshow minor mode in programming modes {begin}--------------------

;; ;; add hook to the following major modes so that the hideshow minor mode starts automatically
;; (load-library "hideshow")
;; (add-hook 'c-mode-hook 'hs-minor-mode)
;; (add-hook 'c++-mode-hook 'hs-minor-mode)
;; (add-hook 'java-mode-hook 'hs-minor-mode)
;; (add-hook 'perl-mode-hook 'hs-minor-mode)
;; (add-hook 'php-mode-hook 'hs-minor-mode)
;; (add-hook 'emacs-lisp-mode-hook 'hs-minor-mode)
;; (add-hook 'matlab-mode-hook 'hs-minor-mode)
;; ;;(add-hook 'LaTeX-mode-hook 'hs-minor-mode) ;;==> I think hideshow is better for programs, probably

;; ;; set up some key bindings so that we can use
;; ;; C-c bh to hide a block
;; ;; C-c bs to show a block
;; ;; see the code below for more key bindings
;; ;; (global-set-key (kbd "C-c bh") 'hs-hide-block)
;; ;; (global-set-key (kbd "C-c bs") 'hs-show-block)
;; ;; (global-set-key (kbd "C-c as") 'hs-show-all)
;; ;; (global-set-key (kbd "C-c ah") 'hs-hide-all)
;; ;; (global-set-key (kbd "C-c th") 'hs-toggle-hiding)
;; ;; (global-set-key (kbd "C-c hl") 'hs-hide-level)

;;}}} use hideshow minor mode in programming modes {end}--------------------



;;{{{ predictive {begin}--------------------

;; ;; predictive install location
;; (add-to-list 'load-path "C:/Emacs/site-lisp/predictive")
;; ;; dictionary locations
;; (add-to-list 'load-path "C:/Emacs/site-lisp/predictive/latex/")
;; (add-to-list 'load-path "C:/Emacs/site-lisp/predictive/texinfo/")
;; (add-to-list 'load-path "C:/Emacs/site-lisp/predictive/html/")
;; ;; load predictive package
;; (autoload 'predictive-mode "C:/Emacs/site-lisp/predictive/predictive"
;;   "Turn on Predictive Completion Mode." t)

;;}}} predictive {end}--------------------



;;{{{ ECB {begin}--------------------

;; (add-to-list 'load-path
;;                      "C:/Emacs/site-lisp/ecb-snap/")
;; (require 'ecb-autoloads)

;;}}} ECB {end}--------------------



;;{{{ occur related {begin}--------------------

;; ;; for occur command, listing lines matching a regexp in a buffer called "occur"
;; ;; Tired of having to decide whether to hit M-x occur, or whether SwitchingBuffers
;; ;; to the OccurBuffer Occur is more appropriate? Here is a defun to do either-or,
;; ;; inspired by MeatBall:HumaneInterface:
;; (defun my-occur ()
;;   "Switch to *Occur* buffer, or run `occur'."
;;   (interactive)
;;   (if (get-buffer "*Occur*")
;;       (switch-to-buffer "*Occur*")
;;     (call-interactively 'occur)))
;; (global-set-key (kbd "C-c o") 'my-occur)

;; ;; This is a slightly different version - keeps the top window displaying the
;; ;; original buffer when typing 'C-c o' for the second time (that is, when
;; ;; both the Occur buffer and the original buffer are visible). The Occur buffer
;; ;; becomes active. Pressing RET (or mouse-2) on an item in the Occur buffer makes
;; ;; the original window active again and moves the point to the occurrence. Thus you
;; ;; can jump back and forth without the windows swapping.

;; ;; Also, once you're done with the Occur buffer (when you no longer need that
;; ;; list), and the original buffer is active, here's a key binding that allows you
;; ;; to kill the Occur buffer. If you only remove the window Occur, and not the
;; ;; buffer Occur (say, as happens with C-x 1), the next time you press
;; ;; 'C-c o', Emacs assumes you're looking for the same regexp (unless you've
;; ;; pressed 'z' in the Occur buffer).

;; (global-set-key (kbd "C-c C-o")
;;                 '(lambda ()
;;                    "Kill the *Occur* buffer"
;;                    (interactive)
;;                    (kill-buffer "*Occur*")
;;                    (delete-other-windows)))

;; (require 'color-moccur)
;; (require 'moccur-edit)

;;}}} occur related {end}--------------------



;;{{{ find function {begin}--------------------

;; (require 'find-func)
;; (defun find-function-setup-keys ()
;;   "Define some key bindings for the find-function family of functions."
;;   (define-key ctl-x-map "F" 'find-function)
;;   (define-key ctl-x-4-map "F" 'find-function-other-window)
;;   (define-key ctl-x-5-map "F" 'find-function-other-frame)
;;   (define-key ctl-x-map "K" 'find-function-on-key)
;;   (define-key ctl-x-map "V" 'find-variable)
;;   (define-key ctl-x-4-map "V" 'find-variable-other-window)
;;   (define-key ctl-x-5-map "V" 'find-variable-other-frame))

;; (find-function-setup-keys)

;;}}} find function {end}--------------------



;;{{{ save macro {begin}--------------------

;;   (defun save-macro (name)                  
;;     "save a macro. Take a name as argument
;;      and save the last defined macro under 
;;      this name at the end of your .emacs"
;;      (interactive "SName of the macro :")         ; ask for the name of the macro    
;;      (kmacro-name-last-macro name)                ; use this name for the macro    
;;      (find-file "C:/Emacs/site-lisp/my_lisp.el")  ; open the .emacs file 
;;      (goto-char (point-max))                      ; go to the end of the .emacs
;;      (newline)                                    ; insert a newline
;;      (insert-kbd-macro name)                      ; copy the macro 
;;      (newline)                                    ; insert a newline
;;      (switch-to-buffer nil))                      ; return to the initial buffer

;;}}} save macro {end}--------------------



;;{{{ duplicate line {begin}--------------------

;; (defun djcb-duplicate-line (&optional commentfirst)
;;   "comment line at point; if COMMENTFIRST is non-nil, comment the original"
;;   (interactive)
;;   (beginning-of-line)
;;   (let
;;       ((beg (point)))
;;     (end-of-line)
;;     (let ((str (buffer-substring beg (point))))
;;       (when commentfirst
;;         (comment-region beg (point)))
;;       (insert-string
;;        (concat (if (= 0 (forward-line 1)) "" "\n") str "\n"))
;;       (forward-line -1))))

;; ;; or choose some better bindings....

;; ;; duplicate a line
;; (global-set-key (kbd "C-c y") 'djcb-duplicate-line)

;; ;; duplicate a line and comment the first
;; (global-set-key (kbd "C-c c") (lambda()(interactive)(djcb-duplicate-line t)))

;;}}} duplicate line {end}--------------------



;;{{{ ESS mode {begin}--------------------

;; ;;; ESS
;; ;;;
;; ;; Load ESS and activate the nifty feature showing function arguments
;; ;; in the minibuffer until the call is closed with ')'.
;; (require 'ess-site)
;; (require 'ess-eldoc)

;; ;; Following the "source is real" philosophy put forward by ESS, one
;; ;; should not need the command history and should not save the
;; ;; workspace at the end of an R session. Hence, both options are
;; ;; disabled here.
;; (setq-default inferior-R-args "--no-restore-history --no-save ")

;; ;; Set code indentation following the standard in R sources.
;; (setq ess-default-style 'C++)

;; ;; Automagically delete trailing whitespace when saving R script
;; ;; files. One can add other commands in the ess-mode-hook below.
;; (add-hook 'ess-mode-hook
;; 	  '(lambda()
;; 	     (add-hook 'write-file-functions
;;                            (lambda ()
;;                              (ess-nuke-trailing-whitespace)))
;; 	     (setq ess-nuke-trailing-whitespace-p t)))

;; ;; Path to R executable. Uncomment and edit as needed if R is
;; ;; installed in such an unusual place that ESS can't find it. (And
;; ;; then keep updating with each R update!)
;; ;(setq-default inferior-R-program-name
;; ;              "c:/program files/r/r-2.7.1/bin/rterm.exe")

;; ;; Path to S-Plus GUI; needed only to use ESS with the S-Plus GUI.
;; ;(setq-default inferior-S+6-program-name
;; ;              "c:/program files/insightful/splus7/cmd/splus.exe")
;; ;(custom-set-variables '(inferior-ess-start-args "-j"))

;; ;; Path to lightweight Sqpe.exe; needed only to use S-Plus in the
;; ;; Emacs window.
;; ;(setq-default inferior-Sqpe+6-program-name
;; ;              "c:/program files/insightful/splus7/cmd/sqpe.exe")
;; ;(setq-default inferior-Sqpe+6-SHOME-name
;; ;              "c:/program files/insightful/splus7/")

;;}}} ESS mode {end}---a-----------------



;; ;;{{{ w3m {begin}--------------------

;; (add-to-list 'load-path "c:/Emacs/site-lisp/w3m/")
;; ;; (add-to-list 'load-path "C:/Emacs/site-lisp/w3m")
;; (require 'w3m-load)
;; (add-hook 'w3m-mode-hook
;;           (lambda ()
;;               (define-key w3m-mode-map (kbd "C-x b") nil)
;;   (define-key w3m-mode-map "C" 'w3m-print-this-url)
;;   (define-key w3m-mode-map "A" 'w3m-bookmark-add-current-url)
;;   (define-key w3m-mode-map "D" 'w3m-download-this-url)
;;   (define-key w3m-mode-map "s" 'w3m-search)
;;   (define-key w3m-mode-map "f" 'w3m-view-this-url-new-session)
;;   (define-key w3m-mode-map "F" 'w3m-view-this-url)
;;   (define-key w3m-mode-map "g" 'w3m-goto-url)
;;   (define-key w3m-mode-map "G" 'w3m-goto-url-new-session)
;;   (define-key w3m-mode-map "h" 'w3m-history)
;;   (define-key w3m-mode-map "p" 'w3m-scroll-down-or-previous-url)
;;   (define-key w3m-mode-map "n" 'w3m-scroll-up-or-next-url)
;;   ;; I don't often w3m to edit pages, so I'm borrowing o and e (right
;;   ;; below , / . for tab navigation) for page navigation instead.
;;   (define-key w3m-mode-map "o" 'w3m-view-previous-page)
;;   (define-key w3m-mode-map "e" 'w3m-view-next-page)
;;   ;; i is a more useful mnemonic for toggling images
;;   (define-key w3m-mode-map "i" 'w3m-toggle-inline-image)
;;   (define-key w3m-mode-map "I" 'w3m-toggle-inline-images)
;;   ;; and X for closing the buffer
;;   (define-key w3m-mode-map "x" 'w3m-delete-buffer)
;;   ;; and b for bookmarks
;;   (define-key w3m-mode-map "b" 'w3m-bookmark-view)
;;   (define-key w3m-mode-map (kbd "C-b") 'backward-char)
;;   (define-key w3m-mode-map (kbd "C-p") 'previous-line)
;;   (define-key w3m-mode-map (kbd "C-n") 'next-line)
;;   (define-key w3m-mode-map (kbd "C-f") 'forward-char)
;;   ;; Browse in new sessions by default
;;   (define-key w3m-mode-map (kbd "RET") 'w3m-view-this-url)
;;   (define-key w3m-mode-map [(shift return)] 'w3m-view-this-url-new-session)
;;   ;; Use cursor keys to scroll
;;   (define-key w3m-mode-map [(left)] 'backward-char)
;;   (define-key w3m-mode-map [(right)] 'forward-char)
;;   (define-key w3m-mode-map [(shift left)] 'w3m-shift-right)
;;   (define-key w3m-mode-map [(shift right)] 'w3m-shift-left)
;;   ;; Which means I can now use , and . to switch pages
;;   (define-key w3m-mode-map "." 'w3m-next-buffer)
;;   (define-key w3m-mode-map "," 'w3m-previous-buffer)
;;             ))
;; (setq-default w3m-display-inline-images t)

;; ;;}}} w3m {end}--------------------



;; ;;{{{ dictionary {begin}--------------------

;; ;;  Loading the package You have to insert some instructions into your .emacs
;; ;;    file to load the dictionary package whenever needed. If you installed this
;; ;;    dictionary package as Debian package or XEmacs package you don't need the
;; ;;    autoloads, they are already supplied. Other users I suggest using the
;; ;;    following lines:
;; (autoload 'dictionary-search "dictionary"
;;   "Ask for a word and search it in all dictionaries" t)
;; (autoload 'dictionary-match-words "dictionary"
;;   "Ask for a word and search all matching words in the dictionaries" t)
;; (autoload 'dictionary-lookup-definition "dictionary"
;;   "Unconditionally lookup the word at point." t)
;; (autoload 'dictionary "dictionary"
;;   "Create a new dictionary buffer" t)
;; (autoload 'dictionary-mouse-popup-matching-words "dictionary"
;;   "Display entries matching the word at the cursor" t)
;; (autoload 'dictionary-popup-matching-words "dictionary"
;;   "Display entries matching the word at the point" t)
;; (autoload 'dictionary-tooltip-mode "dictionary"
;;   "Display tooltips for the current word" t)
;; (autoload 'global-dictionary-tooltip-mode "dictionary"
;;   "Enable/disable dictionary-tooltip-mode for all buffers" t)

;; ;; In  addition, some key bindings for faster access can be useful. I use
;; ;; the following ones in my installation:
;; ;; key bindings
;; (global-set-key "\C-cd" 'dictionary-lookup-definition)
;; (global-set-key "\C-cs" 'dictionary-search)
;; (global-set-key "\C-cm" 'dictionary-match-words)

;; ;; choose a dictionary server
;; (setq dictionary-server "dict.org")

;; ;; choose the dictionary: "wn" for WordNet
;; ;; "web1913" for Webster's Revised Unabridged Dictionary(1913)
;; ;; so on
;; (setq dictionary-default-dictionary "wn")
;; (setq dictionary-tooltip-dictionary "wn")

;; ;;}}} dictionary {end}--------------------



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; .emacs ends here

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#10192: Emacs 24.0.92 windows build, fatal error with M-< or M->
  2011-12-02  5:20 bug#10192: Emacs 24.0.92 windows build, fatal error with M-< or M-> Da Zhang
@ 2011-12-02  7:53 ` Eli Zaretskii
       [not found]   ` <4ED9DECF.6000500@gmail.com>
  2011-12-02 14:08 ` Stefan Monnier
  1 sibling, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2011-12-02  7:53 UTC (permalink / raw)
  To: Da Zhang; +Cc: 10192

> Date: Fri, 02 Dec 2011 00:20:21 -0500
> From: Da Zhang <zhangda82@gmail.com>
> 
> 1. after the .emacs file is loaded into the pretest Emacs, when I press M-< or M->, the program abort with a fatal error: "A fatal error has occurred! Would you like to attach a debugger? Select Yes to debug, No to abort Emacs..."

Does this happen with "emacs -Q"?  If not, there's something in your
customizations that triggers these aborts.  Your .emacs is 3000-line
long, and there are obviously many optional packages that you load
there, so it's not easy to guess which customizations are responsible.

We need a reproducible recipe for causing these aborts, to be able to
find the reason.  Could you please bisect your .emacs and find the
minimal set of customizations that cause these aborts?  Then post only
those parts here.

Thanks.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#10192: Emacs 24.0.92 windows build, fatal error with M-< or M->
  2011-12-02  5:20 bug#10192: Emacs 24.0.92 windows build, fatal error with M-< or M-> Da Zhang
  2011-12-02  7:53 ` Eli Zaretskii
@ 2011-12-02 14:08 ` Stefan Monnier
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2011-12-02 14:08 UTC (permalink / raw)
  To: Da Zhang; +Cc: 10192

> 2. certain part of eieio is not available, and the emacs prompts with
> "Symbol's function definition is void: eieio--defgeneric-init-form"

eieio--defgeneric-init-form is defined in eieio.el, so maybe you have
some other eieio.el(c) somewhere in your load-path, or maybe you use
a package that does something incorrect like (eval-when-compile
(require 'eieio))?


        Stefan





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#10192: Emacs 24.0.92 windows build, fatal error with M-< or M->
       [not found]   ` <4ED9DECF.6000500@gmail.com>
@ 2011-12-03 10:05     ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2011-12-03 10:05 UTC (permalink / raw)
  To: Da Zhang; +Cc: 10192-done

> Date: Sat, 03 Dec 2011 03:33:19 -0500
> From: Da Zhang <zhangda82@gmail.com>
> 
> The system quit with fatal error after  running this code:
> ;; for smooth scrolling and disabling the automatical recentering of emacs when moving the cursor
> (setq-default scroll-margin 0
>        scroll-conservatively 0
>        scroll-up-aggressively 0.01
>        scroll-down-aggressively 0.01)

This should be fixed now (revision 106588 on the trunk).

If you can rebuild Emacs, the patch is below.  If you cannot rebuild,
set scroll-margin to 1, it should avoid the crashes.  (A better
solution is below, read on.)

By the way, if these customizations were needed to prevent Emacs from
recentering the display, you can now do it like this:

  (setq scroll-conservatively 101)

That is, set this single variable to a value larger than 100.  Then
Emacs will never recenter (and the crashes you had will also
disappear, even if you don't rebuild).  In previous versions of Emacs,
all kinds of weird tricks, such as the strange settings of
scroll-up-aggressively you show above, were necessary to prevent
recentering.  But in Emacs 24, no recentering will ever happen if
scroll-conservatively is set to a large number.

Here's the patch to prevent aborts with your original customizations:

=== modified file 'src/xdisp.c'
--- src/xdisp.c	2011-12-03 07:59:23 +0000
+++ src/xdisp.c	2011-12-03 09:55:27 +0000
@@ -15617,7 +15617,7 @@ redisplay_window (Lisp_Object window, in
 	      pt_offset = float_amount * WINDOW_BOX_TEXT_HEIGHT (w);
 	      if (pt_offset == 0 && float_amount > 0)
 		pt_offset = 1;
-	      if (pt_offset)
+	      if (pt_offset && margin > 0)
 		margin -= 1;
 	    }
 	  /* Compute how much to move the window start backward from






^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-12-03 10:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-02  5:20 bug#10192: Emacs 24.0.92 windows build, fatal error with M-< or M-> Da Zhang
2011-12-02  7:53 ` Eli Zaretskii
     [not found]   ` <4ED9DECF.6000500@gmail.com>
2011-12-03 10:05     ` Eli Zaretskii
2011-12-02 14:08 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).