我的emacs的配置文件。



(require 'bookmark+)
;(add-to-list 'load-path "d:/software/emacs-22.1/site-lisp/company-0.4.3/")
;(autoload 'company-mode "company" nil t)


;(require 'volume)
;(autoload 'keisen-mode "keisen-mouse" "MULE table" t)
;(autoload 'keisen-mode "keisen-mule" "MULE table" t)
;(require 'bookmark-search)
(autoload 'rotate-text "rotate-text" nil t)
(autoload 'rotate-text-backward "rotate-text" nil t)

(require 'minimap)
(require 'lively)

(provide 'mon-color-utils)
(defun uniquify-all-lines-region (start end)
    "Find duplicate lines in region START to END keeping first occurrence."
    (interactive "*r")
    (save-excursion
      (let ((end (copy-marker end)))
        (while
            (progn
              (goto-char start)
              (re-search-forward "^//(.*//)/n//(//(.*/n//)*//)//1/n" end t))
          (replace-match "//1/n//2")))))
 
  (defun uniquify-all-lines-buffer ()
    "Delete duplicate lines in buffer and keep first occurrence."
    (interactive "*")
    (uniquify-lines-region (point-min) (point-max)))

;(set-default-font  "-outline-segoe ui-bold-r-normal-normal-*-*-96-96-p-*-iso8859-2")
;; (require 'pushy)

;; (pushy-iswitchb-setup)
;; (pushy-mode t)

;(add-to-list 'load-path "site-lisp/Emacs-PDE-0.2.16/lispc:/perl/path/to/pde/")

(add-to-list 'load-path "~/site-lisp/Emacs-PDE-0.2.16/lisp/")
(load "pde-load")


(require 'sregex)
(set-buffer-file-coding-system 'chinese-iso-8bit)

(add-to-list 'load-path "~/site-lisp/")
(require 'contentswitch)
(require  'anything)
(defun wl-anything-delayed-occur-candidates ()
  (setq anything-occur-buf (get-buffer-create "*Anything Occur*"))
  (with-current-buffer anything-occur-buf
    (erase-buffer)
    (let ((count (occur-engine anything-pattern
                               (list anything-c-source-occur-current-buffer)
                               anything-occur-buf
                               list-matching-lines-default-context-lines
                               (if (and case-fold-search search-upper-case)
                                   (isearch-no-upper-case-p anything-pattern t)
                                 case-fold-search)
                               list-matching-lines-buffer-name-face
                               nil list-matching-lines-face
                               (not (eq occur-excluded-properties t)))))
      (when (> count 0)
        (let ((lines (split-string (buffer-string) "/n" t)))
          (cdr lines))))))

(defvar wl-anything-c-source-delayed-occur
  '((name . "Occur")
    (init . (lambda ()
              (setq anything-c-source-occur-current-buffer
                    (current-buffer))))
    (candidates . wl-anything-delayed-occur-candidates)
    (action . (("Goto line" .
                (lambda (candidate)
                  (goto-line (string-to-number candidate)
                             anything-c-source-occur-current-buffer)))))
    (requires-pattern . 3)
    (volatile)
    (delayed)))

(defun wl-search ()
  (interactive)
  (anything 'wl-anything-c-source-delayed-occur nil nil nil nil "*Anything Occur*"))

;(require 'anything-match-plugin)

(require 'thing-edit)
(require 'filecache)
(require 'line-comment-banner)
(global-set-key (kbd "C-;") 'comment-or-uncomment-region)
(require 'highlight-80+)
(require 'traverselisp)
;(require 'traverse-lisp)
(setq max-lisp-eval-depth 40000)
(require 'file-journal)
(setq w32-pass-rwindow-to-system nil)
(setq w32-rwindow-modifier 'hyper)
(setq w32-pass-lwindow-to-system nil)
(setq w32-lwindow-modifier 'hyper)
(setq w32-pass-apps-to-system nil)
(setq w32-apps-modifier 'super)
(global-set-key [(super ?z)] 'netstat)
(global-set-key [(hyper ?z)] 'netstat)


;; (require 'idle-require)
;; ;(setq idle-require-symbols '(cedet nxml-mode)) ;; <- Specify packages here.
;; ;(idle-require 'cedet) ;; <- Or like this.
;; (idle-require-mode 1) ;; starts loading

(require 'highlight-symbol)

;; (global-set-key [(control f3)] 'highlight-symbol-at-point)
;; (global-set-key [f3] 'highlight-symbol-next)
;; (global-set-key [(shift f3)] 'highlight-symbol-prev)
;; (global-set-key [(meta f3)] 'highlight-symbol-prev)
;; (global-set-key [(control meta ?y)] 'yank-secondary-or-swap-w-region)
;; (global-set-key [(meta ?y)]         'yank-secondary-or-swap-w-region)
;; (define-key esc-map "y"             'yank-pop-commands)

(require 'dropdown-list)
(set-variable 'inferior-lisp-program "c:/Program Files/GCL-2.6.1/bin/gcl.exe")
(autoload 'fi:common-lisp "fi-site-init" "" t)
(require 'smart-snippet)
(require 'register-list)
;;
(local-unset-key   "/C-c/C-o" )
(local-set-key  "/C-c/C-o" 'moccur)

(require 'power-macros)
(global-set-key [(M-f9)] 'netstat)
(require 'visible-mark)
(require 'crosshairs)
(global-set-key [(control ?+)] 'crosshairs-flash)

(add-to-list 'load-path "d:/software/emacs-22.1/site-lisp/icicles/")
(require 'icicles)
(require 'doremi)
(require 'zoom-frm)
(require 'facemenu+)
;(require 'menu-bar+)
;(require 'setup-keys)

 (define-key global-map [S-mouse-1] 'zoom-frm-in)
 (define-key global-map [C-S-mouse-1] 'zoom-frm-out)
 ;; Get rid of `mouse-set-font':
 (define-key global-map [S-down-mouse-1] nil)

;; (defun yodao-dict-search-wordap (&optional word)
;; "Use python script dict to look up word under point"
;; (interactive)
;; (or word (setq word (current-word)))
;; (shell-command (format "yodaodict %s" word))
;; )
;;(global-set-key (kbd "M-5") 'yodao-dict-search-wordap)


;; (create-fontset-from-fontset-spec
;;  "-misc-fixed-medium-r-*-*-16-*-*-*-c-*-fontset-global,
;;   chinese-gb2312:-*-*-medium-r-normal-*-16-*-*-*-*-*-gb2312.1980-*")

;; (setq default-frame-alist
;;       (append '((font . "fontset-global")) default-frame-alist))


;(set-language-environment 'Chinese-GB)
;; (set-keyboard-coding-system 'euc-cn)
;; (set-clipboard-coding-system 'euc-cn)
;; (set-terminal-coding-system 'euc-cn)
;; (set-buffer-file-coding-system 'euc-cn)
;; (set-selection-coding-system 'euc-cn)
;; (prefer-coding-system 'euc-cn)
;; (setq default-process-coding-system 'euc-cn)
;; (setq-default pathname-coding-system 'euc-cn)

(require 'moccur-edit)
(require 'unicad)

(defun add-number-grouping (number &optional separator)
  "Add commas to NUMBER and return it as a string.
    Optional SEPARATOR is the string to use to separate groups.
    It defaults to a comma."
  (let ((num (number-to-string number))
    (op (or separator ",")))
    (while (string-match "//(.*[0-9]//)//([0-9][0-9][0-9].*//)" num)
      (setq num (concat
         (match-string 1 num) op
         (match-string 2 num))))
    num))

;; Note that you can also specify a different separator:

;;     (add-number-grouping 123459994)
;;     => "12'345"


(require 'shell-current-directory)


(defun runperl()
  (interactive)
                    ;(save-buffer)
  (let ((filename buffer-file-name)
    (cmd "")
    (oldbuf (current-buffer))
    (end (point-max)))
    (if filename
    (save-buffer)
      (save-excursion
    (setq filename (concat (getenv "tmp") "/temp.pl"))
    (set-buffer (create-file-buffer filename))
    (insert-buffer-substring oldbuf 1 end)
    (write-file filename)
    (kill-buffer (current-buffer))))
    (setq cmd (concat "perl -w " filename))
    (message "%s  ..." cmd)
    (shell-command cmd)))

;(global-set-key [C-f5] 'runperl)



(fset 'my-toshiba
   (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ([26 5 134217847 return 25 1 16 3 97 44 44 44 2 24 114 105 97 3 97 44 44 2 24 114 105 97 14 1 3 97 44 44 44 2 24 114 105 98 3 97 44 44 2 24 114 105 98 3 97 44 44 44 44 44 44 44 6 4 4 24 114 105 99 3 97 44 26 3 97 44 2 backspace 48 46 48 48 49 1 3 97 44 44 2 backspace 48 16 backspace 48 14 134217826 32 40 43 32 134217830 32 50 48 32 2 41 21 24 5 134217826 1 3 97 44 134217820 f8 backspace 14 1] 0 "%d")) arg)))



(eval-after-load "isearch" '(require 'isearch+))
(defun clear ()
  "04Dec2001 - sailor, to clear the eshell buffer."
  (interactive)
  (let ((inhibit-read-only t))
    (erase-buffer)))

(require 'multiselect)
(multiselect-install-default-keybindings)
(require 'highlight-context-line)
(require 'watch-sexp)
(require 'quick-yes)
(global-set-key (kbd "C-c C-s") 'hidesearch)
(global-set-key (kbd "C-c C-a") 'show-all-invisible)

(require 'thumbs)
(auto-image-file-mode t)
(require 'usage-memo)
(umemo-initialize)

(require 'rep-words)
;(add-to-list 'load-path "G:/software/emacs-22.1/site-lisp/predictive")
;(require 'predictive)
;(autoload 'resize-minibuffer-mode "rsz-minibuf" nil t)
(autoload 'kill-ring-search "kill-ring-search"
 "Search the kill ring in the minibuffer."
 (interactive))
(global-set-key "/M-/C-y" 'kill-ring-search)


 (require 'company-mode)
 (require 'company-bundled-completions)
 (company-install-bundled-completions-rules)

(require 'tempo-snippets)

(require 'calculator)
(defun number-to-bin-string (number)
  (let ((calculator-output-radix 'bin)
        (calculator-radix-grouping-mode nil))
    (calculator-number-to-string number)))

(defun ywb-change-window-size (n char)
  "Use {}^v to change window size, any key to quit"
  (interactive "p/ncdirect({}^v): ")
  (while (string-match (char-to-string char) "{}^v")
    (cond ((char-equal ?/{ char)
           (enlarge-window-horizontally (- n)))
          ((char-equal ?/} char)
           (enlarge-window-horizontally n))
          ((char-equal ?^ char)
           (enlarge-window (- n)))
          ((char-equal ?v char)
           (enlarge-window n)))
    (setq char (read-char))))
(defun ywb-favorite-window-config (&optional percent)
  "Split window to proper portion"
  (interactive "P")
  (or percent (setq percent 64))
  (setq percent (/ percent 100.0))
  (let (buf)
    (if (> (length (window-list)) 1)
        (setq buf (window-buffer (next-window))))
    (delete-other-windows)
    (let ((maxwidth (window-width)))
      (split-window-horizontally (round (* maxwidth percent))))
    (if buf (save-selected-window
               (next-window)
             (pop-to-buffer buf)))))

(add-to-list 'load-path "d:/software/emacs-22.1/site-lisp/vj-complete/")

(require 'vj-complete-elisp) ;; currently steals C-t (will be fixed)
(add-hook 'foo-mode-hook 'vj-complete-foo-setup)

(defun vj-complete-foo-setup ()
  (setq vj-complete-get-completions-function
  'vj-complete-get-foo-completions)
  (local-set-key (kbd "C-t") 'vj-complete)
  (global-set-key [(mouse-3)] 'vj-complete)
)           
;; Return a list of completion records (COMPLETION DOCLINE TYPECODE)
(defun vj--complete-get-foo-completions ()
  (setq vj-complete-current--begin-point
    (save-excursion
      (skip--chars-backward "A-Za-z_0-9-" (point-at-bol)) ;; your symbol regex
      (point)))
  ;; -- your code here --
  ;; Find completions for the prefix:
  ;;  (buffer-substring-no-properties vj-complete-current-begin-point (point))
  ;; --
  (list '("name" "doc" "F") '("name2" "doc2" "V")))

;; Optional "hook". Called after creating the completion buffer.
;; (setq vj-complete-insert-header-function 'vj-complete-foo-insert-header)

(require 'vj-complete-completion-ui)
;; 
;; Enable the completion-ui interface in a buffer with
;;
;;   M-x auto-completion-mode


(defun totd ()
  (interactive)
  (with-output-to-temp-buffer "*Tip of the day*"
    (let* ((commands (loop for s being the symbols
                           when (commandp s) collect s))
           (command (nth (random (length commands)) commands)))
      (princ
       (concat "Your tip for the day is:/n"
               "========================/n/n"
               (describe-function command)
               "/n/nInvoke with:/n/n"
               (with-temp-buffer
                 (where-is command t)
                 (buffer-string)))))))

(global-set-key [(meta s)] 'totd)

(define-key isearch-mode-map (kbd "C-o")
  (lambda ()
    (interactive)
    (let ((case-fold-search isearch-case-fold-search))
      (occur (if isearch-regexp isearch-string
               (regexp-quote isearch-string))))))
(defun my-show-last-command ()
  (let (message-log-max)
    (unless (minibuffer-window-active-p (selected-window))
      (message "Keys: %s, command: %S"
               (key-description (this-command-keys)) this-command))))

(define-minor-mode my-show-last-command-mode
  "A mode to show what you command you call."
  :global t
  (let ((hooks (default-value 'post-command-hook)))
    (if my-show-last-command-mode
        (setq-default post-command-hook
                      (add-to-list 'hooks 'my-show-last-command))
      (setq-default post-command-hook
                    (delq 'my-show-last-command hooks)))))


;(require 'tagger)

(require 'ipa)
(require 'policy-switch)

;autoload 'keyboard-macro-timer-start "keyboard-macro-timer"
 ; "Execute last keyboard macro with a timer." t)

(require 'linum)
(require 'highlight-current-line)
(highlight-current-line-on t)
 
;; To customize the background color
(set-face-background 'highlight-current-line-face "light blue")

(require 'light-symbol)
(defun copy-previous-line-char ()
       "copy-previous-line-char"
       (interactive)
       (previous-line)
       (setq char1 (char-to-string (following-char)))
       (next-line)
       (insert char1))
;;
 (global-set-key (quote [67108960]) (quote copy-previous-line-char))


   (autoload 'igrep "igrep"
      "*Run `grep` PROGRAM to match EXPRESSION in FILES..." t)
   (autoload 'igrep-find "igrep"
      "*Run `grep` via `find`..." t)
   (autoload 'igrep-visited-files "igrep"
      "*Run `grep` ... on all visited files." t)
   (autoload 'dired-do-igrep "igrep"
      "*Run `grep` on the marked (or next prefix ARG) files." t)
   (autoload 'dired-do-igrep-find "igrep"
      "*Run `grep` via `find` on the marked (or next prefix ARG) directories." t)
   (autoload 'Buffer-menu-igrep "igrep"
     "*Run `grep` on the files visited in buffers marked with '>'." t)
   (autoload 'igrep-insinuate "igrep"
     "Define `grep' aliases for the corresponding `igrep' commands." t)

   (autoload 'grep "igrep"
      "*Run `grep` PROGRAM to match EXPRESSION in FILES..." t)
   (autoload 'egrep "igrep"
      "*Run `egrep`..." t)
   (autoload 'fgrep "igrep"
      "*Run `fgrep`..." t)
   (autoload 'agrep "igrep"
      "*Run `agrep`..." t)
   (autoload 'grep-find "igrep"
      "*Run `grep` via `find`..." t)
   (autoload 'egrep-find "igrep"
      "*Run `egrep` via `find`..." t)
   (autoload 'fgrep-find "igrep"
      "*Run `fgrep` via `find`..." t)
   (autoload 'agrep-find "igrep"
      "*Run `agrep` via `find`..." t)

(require 'anything-config)        ; loads anything.el too

(setq anything-sources (list anything-c-source-buffers
                 anything-c-source-emacs-commands
                 anything-c-source-locate ))

(setq anything-type-actions (list anything-c-actions-buffer
                  anything-c-actions-file
                  anything-c-actions-command
                  anything-c-actions-function
                  anything-c-actions-sexp ))

(setq anything-action-transformers
      '((buffer   . anything-c-transform-buffer-actions)
    (file     . anything-c-transform-file-actions)
    (command  . anything-c-transform-command-actions)
    (function . anything-c-transform-function-actions)
    (sexp     . anything-c-transform-sexp-actions)))

(setq anything-candidate-transformers
      '((buffer   . anything-c-transform-buffers)
    (file     . anything-c-transform-files)
    (command  . anything-c-transform-commands)
    (function . anything-c-transform-functions)
    (sexp     . anything-c-transform-sexps)))


(setq totd-file "~/emacsTOTD")
(require 'cl)
;; (defun totd()
;;   (random t)
;;   (let ((stars "*****************************")
;;     ( tip (with-temp-buffer
;;            (insert-file-contents totd-file)
;;            (goto-line (1+ (random
;;                    (count-lines (point-min)
;;                         (point-max)))))
;;            (buffer-substring (point) (line-end-position)))))
;;     (momentary-string-display
;;      (concat "/n/n" stars "/n"
;;          "Tip of the Day/n"
;;          random-command "/n"
;;          stars "/n/n")
;;      (window-start) ?/r
;;      "Hit any key when done reading")))

(setq scheme-program-name "mzscheme")
(require 'eaksearch)
(require 'file-search)
(require 'exec-abbrev-cmd) ;; Load it.
(global-set-key (kbd "C-x x") 'exec-abbrev-cmd)

(require 'gse-underline-previous-line)
(require 'czscm)
(require 'scrmable)
(add-hook 'dired-load-hook
      (lambda ()
        (load "dired-column-widths.el") ))

(require 'file-props)
;;
;; If you want to activate display of comment and tags for Dired, put
;; this in your .emacs as well:
;;
(file-props-dired-activate-display)
;;
;; If you want to disable the display temporarily, do M-x
;; file-props-dired-deactivate-display
;;
;; To setup convenient Dired keybindings, put this:
;;
(file-props-dired-setup-keybindings)

;; Running   M-x sort-words   on:
;;   first, second, third - last.
;; produces:
;;   first, last, second - third.
;; and reversing the order can be done with   C-u M-x sort-words  :
;;   first, last, second - third.

(defun sort-words (reverse beg end)
  "Sort words in region alphabetically, in REVERSE if negative.
  Prefixed with negative //[universal-argument], sorts in reverse.
  The variable `sort-fold-case' determines whether alphabetic case
  affects the sort order.
  See `sort-regexp-fields'."
  (interactive "P/nr")
  (sort-regexp-fields reverse "//w+" "//&" beg end))



;;   first, second, third - last.
;; Running   M-x reverse-words   on this sentence with the region starting from the beginning but not including the period:
;;   last - third, second, first.

(defun reverse-words (beg end)
  "Reverse the order of words in region."
  (interactive "r")
  (insert
   (apply
    'concat
    (reverse
     (split-string
      (delete-and-extract-region beg end) "//b")))))

(require 'frame-fns)
(require 'strings)
(require 'motion-fns)
(require 'spending)

(add-hook 'calendar-mode-hook           ;integrate with calendar mode
      (lambda ()
        (local-set-key (kbd "i s") 'spending-find-log-by-calendar-date)))

(require 'tree-imenu)
(global-set-key (kbd "<f5>") 'tr-imenu)

(add-hook 'tree-imenu-mode-hook
      (lambda ()
        (define-key tr-mode-map "j" 'next-line)
        (define-key tr-mode-map "k" 'previous-line)
        (define-key tr-mode-map "l" 'forward-char)
        (define-key tr-mode-map "h" 'backward-char)))

;; (add-to-list 'auto-mode-alist '("//.//([pP][Llm]//|al//)//'" . cperl-mode))
;; (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
;; (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
;; (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))


;; (add-hook 'cperl-mode-hook 'n-cperl-mode-hook t)
;; (defun n-cperl-mode-hook ()
;;   (setq cperl-indent-level 4)
;;   (setq cperl-continued-statement-offset 0)
;;   (setq cperl-extra-newline-before-brace t)
;;   )


;; (add-hook 'cperl-mode-hook
;;           '(lambda ()
;;          (setq cperl-brace-imaginary-offset 0
;;            cperl-brace-offset 0
;;            cperl-close-paren-offset -1
;;            cperl-comment-column 40
;;            cperl-continued-brace-offset -1
;;            cperl-continued-statement-offset 1
;;            cperl-electric-keywords nil
;;            cperl-electric-linefeed t
;;            cperl-extra-newline-before-brace t
;;            cperl-fix-hanging-brace-when-indent t
;;            cperl-indent-level 1
;;            cperl-label-offset -4
;;            cperl-merge-trailing-else nil
;;            cperl-tab-always-indent t)
;;          (set-face-background 'cperl-array-face "wheat")
;;          (set-face-background 'cperl-hash-face "wheat")
;;          )
;;       )





;; (defun cperl-prove ()
;;   (interactive)
;;   (shell-command (concat "prove -v"
;;              (shell-quote-argument (buffer-file-name)
;; ))))


;; (defun perl-eval (beg end)
;;   (interactive "r")
;;   (shell-command-on-region beg end "perl")
;;   )

;; (global-set-key [C-f5] 'perl-eval)

;;Perl ========================================
(defun run1perl()
  "run perl"
  (interactive)
                    ;(save-buffer)
  (let ((filename buffer-file-name)
    (cmd "")
    (oldbuf (current-buffer))
    (end (point-max)))
    (if filename
    (save-buffer)
      (save-excursion
    (setq filename (concat (getenv "tmp") "/temp.pl"))
    (set-buffer (create-file-buffer filename))
    (insert-buffer-substring oldbuf 1 end)
    (write-file filename)
    (kill-buffer (current-buffer))))
    (setq cmd (concat "perl -w " filename))
    (message "%s  ..." cmd)
    (shell-command cmd)))
(global-set-key[(meta h)] 'runperl)    ;bind-key alt+o:runperl


(defun toggle-window-split ()
  (interactive)
  (if (= (count-windows) 2)
      (let* ((this-win-buffer (window-buffer))
         (next-win-buffer (window-buffer (next-window)))
         (this-win-edges (window-edges (selected-window)))
         (next-win-edges (window-edges (next-window)))
         (this-win-2nd (not (and (<= (car this-win-edges)
                     (car next-win-edges))
                     (<= (cadr this-win-edges)
                     (cadr next-win-edges)))))
         (splitter
          (if (= (car this-win-edges)
             (car (window-edges (next-window))))
          'split-window-horizontally
        'split-window-vertically)))
    (delete-other-windows)
    (let ((first-win (selected-window)))
      (funcall splitter)
      (if this-win-2nd (other-window 1))
      (set-window-buffer (selected-window) this-win-buffer)
      (set-window-buffer (next-window) next-win-buffer)
      (select-window first-win)
      (if this-win-2nd (other-window 1))))))

(define-key ctl-x-4-map "t" 'toggle-window-split)


(eval-after-load "speedbar" '(load-library "sb-rfcview"))
(custom-set-variables
 '(speedbar-supported-extension-expressions
   (append
    speedbar-supported-extension-expressions
    '("rfc[0-9]+//.txt"))))

;;  (require 'english-menu)
;; (require 'chinese-menu)
;; (require 'mule-menu)


(defalias 'rs 'replace-string)
(defalias 'kab    'kill-all-buffers)
(defalias 'qrr 'query-replace-regexp)
(defun my-c-mode-auto-pair ()
  (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))
(add-hook 'c-mode-common-hook 'my-c-mode-auto-pair)
(add-hook 'cperl-mode-hook 'my-c-mode-auto-pair)
;; ;;}}}




;;;;;--------------------ido         -------------------------

(require 'ido)
(ido-mode t)


;;{{{ ido: fast switch buffers

(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
  (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)
    (define-key ido-mode-map [(meta backspace)] 'ido-delete-backward-word-updir)
    (define-key ido-mode-map [(control backspace)] 'ido-up-directory)

    ;; 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-mode t)
;;}}}

;;;;;;---------------------------ido      


(require 'chinese-calendar)

(setq transient-mark-mode t)




(defun my-beginning-of-line ()
  "If the point is not on beginning of current line, move point
to beginning of current line, as 'beginning-of-line' does.
if the point already is on the beginning of current line, then
move the point to the first non-space character, if it exists."
  (interactive)
  (if (not (eq (point) (line-beginning-position)))
      (beginning-of-line)
    (when (re-search-forward "/[^/[:blank:/]  /]" (line-end-position) t)
      (backward-char))
    ))



(global-set-key "/C-a" 'my-beginning-of-line)



(require 'blank-mode)
(require 'tramp)
(setq tramp-default-method "plink"
      tramp-password-end-of-line "/r/n")

;(require 'smart-compile)








(fset 'print-buffer 'ignore)
(setq lpr-command "")
(setq printer-name "")


(defun my-occur (regexp)
  (interactive
   (list
    (if (null buffer-file-name)
        (error "only for file!")
      (read-from-minibuffer
       (format "list lines %smatching regexp: "
               (if current-prefix-arg "not " ""))
       nil nil nil 'regexp-history))))
  (if regexp
      (grep (format "grep -%snih /"%s/" %s"
                    (if current-prefix-arg "v" "")
                    regexp buffer-file-name))))  

(require 'delim-col)
(setq delimit-columns-str-before "[ ")
(setq delimit-columns-str-after " ]")
(setq delimit-columns-str-separator ", ")
(setq delimit-columns-before "")
(setq delimit-columns-after "")
(setq delimit-columns-separator "/t")
(setq delimit-columns-format 'separator)
(setq delimit-columns-extra t)



(add-hook 'view-mode-hook
      (lambda ()
        (define-key view-mode-map "j" 'next-line)
        (define-key view-mode-map "k" 'previous-line)
        (define-key view-mode-map "l" 'forward-char)
        (define-key view-mode-map "h" 'backward-char)))

(require 'mysql)
;; for mysql
;;
;; show output on windows in buffer
(setq sql-mysql-options '("-c" "-t" "-f" "-n"))

(setq sql-mysql-program "c:/program fles/mysql/mysql tools for 5.0/mysqlquerybrowser.exe")

;; truncate lines for long tables
;; (add-hook 'sql-interactive-mode-hook
;; (function (lambda ()
;; (setq truncate-lines t))))

(setq auto-mode-alist
      (append
       (list
    ;; insert entries for other modes here if needed.
    (cons "//.sq$" 'sql-mode))
       auto-mode-alist))
(add-hook 'sql-mode-hook 'font-lock-mode)
;(require 'smart-compile)
(global-set-key (kbd "<mouse-5>") 'mouse-yank-at-click)
(require 'show-wspace)



(defun wcy-insert-local-set-key (key command)
  (interactive "kset key locally: /ncset key %s locally to command: ")
  (insert
   (format
    "(local-set-key (kbd %s) '%s)"
    (key-description key) command)))

(defun wcy-insert-global-set-key (key command)
  (interactive "kset key globally: /ncset key %s locally to command: ")
  (insert
   (format
    "(global-set-key (kbd %s) '%s)"
    (key-description key) command)))

                    ;(setq tramp-default-method t)
(global-set-key (kbd  "C-x C-2") 'clone-indirect-buffer)
(setq visible-bell t)




(require 'golisp)
(defun pg-kill-this-line (n)
  "kill the line point is on.
  with prefix arg, kill this many lines starting at the line point is on."
  (interactive "p")
  (kill-region (line-beginning-position)
           (progn (forward-line n) (point))))

(defun pg-duplicate-this-line (n)
  "duplicates the line point is on.
 with prefix arg, duplicate current line this many times."
  (interactive "p")
  (save-excursion
    (copy-region-as-kill (line-beginning-position)
                   (progn (forward-line 1) (point)))
    (while (< 0 n)
      (yank)
      (setq n (1- n)))))

;(set-default-font "-outline-monaco-normal-r-normal-normal-14-105-96-96-c-*-fontset-auto2")
;(set-default-font "-outline-lucida console-normal-r-normal-normal-14-108-120-120-c-*-fontset-auto5")
;(set-frame-font "-outline-lucida console-normal-r-normal-normal-18-108-120-120-c-*-fontset-auto5")

(if (locate-library "calculator")
    (progn
      (autoload 'calculator "calculator"
    "run the emacs calculator." t)
      (global-set-key [(control return)] 'calculator)))

(global-set-key  "/C-c/C-w" 'fff-find-emacs-lisp-library)




(autoload 'shell-toggle "shell-toggle"
  "toggles between the *shell* buffer and whatever buffer you are editing."
  t)

(global-set-key [M-f1] 'shell-toggle)



(require 'rain)
(require 'dope)



(setq tr-image-directory "~/dmacro/emacs/myconfig/images/tree/")
                    ; "-outline-lucida console-normal-r-normal-normal-20-120-120-120-c-*-fontset-auto3"); "-outline-arial black-normal-r-normal-normal-*-*-120-120-p-*-iso8859-13")

                    ; (prefer-coding-system 'utf-8-dos)
;; ;; (set-w32-system-coding-system 'utf-8)

;; ;; (set-language-environment 'utf-8)
;; ; (setq locale-coding-system 'utf-8)
;; ;; (setq current-language-environment "utf-8")
;;(set-language-environment 'chinese-gb)
(global-hi-lock-mode 1)
;; (require 'gnuserv)
;; (gnuserv-start)
(setq gnuserv-frame (selected-frame))
(setenv "group gnuserv_show_emacs" "1")
(setq visible-bell t)

;;         auto-fill   
;;(setq default-major-mode 'text-mode)
;;(add-hook 'text-mode-hook 'turn-on-auto-fill)

(setq default-directory "d:/")
(require 'ffap)

(let ((path))
  (setq path (parse-colon-path (getenv "include")))
  (while path
    (add-to-list 'ffap-c-path (car path))
    (print path)
    (setq path (cdr path))
    ))





(setq calendar-latitude +31.13)
(setq calendar-longitude +121.32)
(setq calendar-location-name "shanghai")
(setq custom-file "~/.emacs.d/.emacs_custom.el")
(load custom-file)

(setq abbrev-file-name "~/.emacs.d/.abbrev_defs")
(quietly-read-abbrev-file)
(setq-default save-abbrevs t)

(setq font-lock-maximum-decoration t)
(require 'align)

(global-hl-line-mode t)
(fset 'yes-or-no-p 'y-or-n-p)

(cond ((eq 'w32 window-system)
       (progn
     (defun w32-restore-frame ()
       "restore a minimized frame"
       (interactive)
       (w32-send-sys-command 61728))

     (defun w32-maximize-frame ()
       "maximize the current frame"
       (interactive)
       (w32-send-sys-command 61488))
;;; maximum windows frame
     (w32-maximize-frame)
     (global-set-key [(f12)] 'w32-maximize-frame)
     (global-set-key [(f11)] 'w32-restore-frame)

     )

       )
      (t)
      )

(defun w32-restore-frame ()
  "restore a minimized frame"
  (interactive)
  (w32-send-sys-command 61728))

(defun w32-maximize-frame ()
  "maximize the current frame"
  (interactive)
  (w32-send-sys-command 61488))
;;; maximum windows frame
(w32-maximize-frame)


(global-set-key [(f12)] 'w32-maximize-frame)
(global-set-key [(f11)] 'w32-restore-frame)



(menu-bar-mode nil)
(tool-bar-mode nil)



(setq scroll-step 1
      scroll-margin 3
      scroll-conservatively 1000000)

(setq frame-title-format "%f")

(setq bookmark-save-flag 1)
(setq insert-default-directory nil)

(setq auto-save-interval 2)


(setq search-highlight t)
(setq query-replace-highlight t)


;;                  
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
(display-time)

;; display line and column number
(setq column-number-mode t)
(setq line-number-mode t)

;; highlight marked block
(setq transient-mark-mode t)
(global-set-key "/C-c/C-v" 'view-mode)
(global-set-key "/M-o" 'other-window)
(set-scroll-bar-mode nil)     ; no scroll bar, even in x-window system

(cond ((fboundp 'global-font-lock-mode)
       ;; turn on font-lock in all modes that support it
       (global-font-lock-mode t)
       ;; maximum colors
       (setq font-lock-maximum-decoration t)))
(setq kill-ring-max 50)

;; backup settings
(setq version-control t)
(setq kept-old-versions 2)
(setq kept-new-versions 5)
(setq delete-old-versions t)
(setq backup-directory-alist '(("." . "~/backup")))
(setq backup-by-copying t)

;; make dired can copy and delete directory
(setq dired-recursive-copies 'top)
(setq dired-recursive-deletes 'top)

;;(global-set-key [(meta g)] 'goto-line)
;;(global-set-key [(control a)] 'speedbar)


(defun chunyu-dired-open-explorer ()
  (interactive)
  (let ((file-name (dired-get-file-for-visit)))
    (if (file-exists-p file-name)
    (w32-shell-execute "open" file-name nil 1))))



;; setup various dot file's location
(setq bookmark-default-file "~/.emacs.d/_emacs_bmk")
(setq abbrev-file-name "~/.emacs.d/_abbrev_defs")
;; ;;(setq custom-file "~/.emacs.d/_emacs_custom.el")
;; (setq bbdb-file "~/.emacs.d/_bbdb")
;; (setq todo-file-do "~/.emacs.d/todo-do")
;; (setq todo-file-done "~/.emacs.d/todo-done")
;; (setq todo-file-top "~/.emacs.d/todo-top")
;; (setq diary-file "~/.emacs.d/_diary")

(show-paren-mode t)
(setq show-paren-style 'parentheses)

(mouse-avoidance-mode 'animate)

(put 'scroll-left 'disabled nil)

(put 'set-goal-column 'disabled nil)

(load-file "~/.emacs.d/_emacs_tools.el")

(require 'dired)
(require 'dired-x)

(global-set-key "/C-x/C-j" 'dired-jump)
(define-key dired-mode-map "b" 'dired-mark-extension)
(define-key dired-mode-map "c" 'dired-up-directory)
(define-key dired-mode-map "e" 'dired-mark-files-containing-regexp)
(define-key dired-mode-map "o" 'chunyu-dired-open-explorer)
(define-key dired-mode-map "r" 'dired-mark-files-regexp)
(define-key dired-mode-map "/" 'dired-mark-directories)
(define-key dired-mode-map "k" 'dired-kill-subdir)
(define-key dired-mode-map [(control ?/)] 'dired-undo)



(define-key dired-mode-map "h" 'chunyu-dired-foobar2000-play)
(defun chunyu-dired-foobar2000-play ()
  (interactive)
  (let ((file-name (dired-get-filename 'no-dir)))
    (if (file-exists-p file-name)
    (progn
      (message "playing... %s" file-name)
      (w32-shell-execute
       nil "c:/program files/foobar2000/foobar2000.exe"
       (format "/"%s/"" file-name) 1)))))

(autoload 'mpg123 "mpg123" "a front-end to mpg123" t)
(setq mpg123-system-type 'nt)



(require 'bm)
;; (autoload 'bm-toggle   "bm" "toggle bookmark in current buffer." t)
;; (autoload 'bm-next     "bm" "goto bookmark."                     t)
;; (autoload 'bm-previous "bm" "goto previous bookmark."            t)
(global-set-key (kbd "<C-f2>") 'bm-toggle)
(global-set-key (kbd "<f2>")   'bm-next)
(global-set-key (kbd "<S-f2>") 'bm-previous)

(setq  bm-buffer-persistence t)
(setq  bm-repository t)
(setq  bm-regexp-history t)
(setq  bm-restore-repository-on-load t)
(require 'hl-sexp)
(autoload 'who-calls "who-calls" nil 0)
                    ;(define-key emacs-lisp-mode-map "/c-c/c-w" 'who-calls)
(autoload 'typing-of-emacs "the typing of emacs, a game." 0)
(add-hook 'dired-load-hook
          (lambda () (require 'dired-sort-menu)))


(delete-selection-mode 1)

(global-set-key (kbd "C-x r C-x") 'rm-exchange-point-and-mark)
(global-set-key (kbd "C-x r C-w") 'rm-kill-region)
(global-set-key (kbd "C-x r M-w") 'rm-kill-ring-save)
(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)


(defun kill-paren ()
  "kill matched paren in elisp, repeat undo the kill"
  (interactive "*")
  (save-excursion)
  (let (start end)
    (re-search-backward "//s/(")
    (setq start (point))
    (forward-list)
    (setq end (point))
    (kill-region start end)
    (setq this-command 'kill-paren)))

(global-set-key [(control ?0)] 'kill-paren)
;;; turn on debugger
(set-variable 'debug-on-error nil)
(add-hook 'shell-mode-hook 'wcy-shell-mode-hook-func)
(add-hook  'py-shell-hook 'wcy-shell-mode-hook-func)
(add-hook 'gdb-mode-hook 'wcy-shell-mode-hook-func)
(defun wcy-shell-mode-hook-func  ()
  (set-process-sentinel (get-buffer-process (current-buffer))
            'wcy-shell-mode-kill-buffer-on-exit)
  )


(defun wcy-shell-mode-kill-buffer-on-exit (process state)
  (message "%s" state)
  (if (or
       (string-match "exited abnormally with code.*" state)
       (string-match "finished" state)
       (string-match "debugger finished" state)
       (string-match "use ctrl-z plus return to exit" state))
      (kill-buffer (current-buffer))))

(make-variable-buffer-local 'search-ring)


(global-set-key [(f8)] 'mark-sexp)

;(require 'smart-compile)
(defun joc-enlarge-by-ten()
  "enlarges a window 10 lines"
  (interactive)
  (enlarge-window 10))

(global-set-key [C-f3] 'joc-enlarge-by-ten)
(defalias 'vi 'find-file)
(add-hook 'after-save-hook
      (lambda ()
        (mapcar
         (lambda (file)
           (setq file (expand-file-name file))
           (when (string= file (buffer-file-name))
         (save-excursion (byte-compile-file file))))
         '("~/.emacs" "~/.emacs.d/_emacs_macro.el" "~/.emacs.d/_emacs_modes.el" "~/.emacs.d/_emacs_tools.el"
           "~/.emacs.d/.emacs_custom.el"))))

(require 'color-theme)
(setq my-color-themes
      (list 'color-theme-gtk-ide
        'color-theme-xp
        'color-theme-high-contrast
        'color-theme-blippblopp
        'color-theme-montz
        'color-theme-marquardt
        'color-theme-billw
        'color-theme-jsc-dark
        'color-theme-sitaramv-solaris
        'color-theme-resolve
        'color-theme-classic
        'color-theme-kingsajz
        'color-theme-shaman
        'color-theme-sitaramv-nt
        'color-theme-wheat))

(defun my-theme-set-default ()        ; set the first row
  (interactive)
  (setq theme-current my-color-themes)
  (funcall (car theme-current)))

(defun my-describe-theme ()        ; show the current theme
  (interactive)
  (message "%s" (car theme-current)))

(setq theme-current my-color-themes)
(setq color-theme-is-global nil)    ; initialization
(my-theme-set-default)
(global-set-key [C-f12] 'my-theme-cycle)
(defun  my-theme-cycle ()
  (interactive)
  (setq theme-current  (rotlist-back theme-current))
  (if (null theme-current)
      (setq theme-current my-color-themes))
  (funcall (car theme-current))
  (if (equal (car theme-current) 'color-theme-sitaramv-solaris)
      (message "%s" (car theme-current))
    (message "%s" (car theme-current))))

(defun rotlist(list)
  ""
  (if (<= (length list) 1)
      list
    (let (res
      (las (cdr list))
      (prev (car list)))
      (setq res      (append las (cons prev nil) ))
      res)))


(defun rotlist-back(list)
  ""
  (if (<= (length list) 1)
      list
    (let (res
      (prev  (nth (1- (length list)) list))
      (las (cl-set-nthcdr  (1- (length list)) list  nil)))
      (setq res      (append  (cons prev nil) las ))
      res)))

(defun  my-theme-back_cycle ()
  (interactive)
  (setq theme-current  (rotlist theme-current))
  (if (null theme-current)
      (setq theme-current my-color-themes))
  (funcall (car theme-current))
  (if (equal (car theme-current) 'color-theme-sitaramv-solaris)
      (message "%s" (car theme-current))
    (message "%s" (car theme-current))))

(global-set-key [C-f10] 'my-theme-back_cycle)
(require 'timestamp)
(setq-default cursor-type 'bar)        ;          
(require  'w32-dev)
(add-hook 'lisp-mode-hook 'turn-on-eldoc-mode)
(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
(add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)

(setq auto-mode-alist
      (union
       '(
     ("//.h$" . c++-mode)
     ("//.c$" . c++-mode)
     ("//.cxx$" . c++-mode)
     ("//.cpp$" . c++-mode)
     ("//.hpp$" . c++-mode)
     )
       auto-mode-alist))


(add-to-list 'interpreter-mode-alist '("python" . python-mode))

(require 'dired-tar)

;;(add-hook 'write-file-hooks 'time-stamp)

(global-set-key [f6] 'eshell)           ;      elisp      shell



(global-set-key "/C-c/C-z" 'pop-global-mark)




(define-prefix-command 'meta-m-map)
(global-set-key "/M-m" 'meta-m-map)
(define-key meta-m-map "/M-m" 'back-to-indentation)
(define-key meta-m-map "/M-i" 'imenu)
(define-key meta-m-map "/M-e" 'ediff-buffers)
(autoload 'py-shell "python-mode" "python shell" t)
(define-key meta-m-map "/M-p" 'py-shell)
(define-key meta-m-map "/M-l" 'goto-line)
(define-key meta-m-map "/M-s" 'sams-apply-macro-on-region)

(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 ""))))))


(defun sof/dired-sort ()
  "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 'sof/dired-sort)

;; c-x c-j open the directory of current buffer
(global-set-key (kbd "C-x C-j")
                (lambda ()
                  (interactive)
                  (if (buffer-file-name)
                      (dired default-directory))))


(setq dired-omit-extensions '("cvs/" ".o" "~" ".bin" ".lbin" ".bak"  ".chi" ".chw" ".pyc"
                  ".fasl" ".ufsl" ".a" ".ln" ".blg"
                  ".bbl" ".elc" ".lof" ".glo" ".idx"
                  ".lot" ".fmt" ".tfm" ".class" ".fas" ".lib" ".x86f"
                  ".sparcf" ".lo" ".la" ".toc" ".log" ".aux" ".cp"
                  ".fn" ".ky" ".pg"
                  ".tp" ".vr" ".cps" ".fns" ".kys" ".pgs" ".tps" ".vrs"
                  ".idx" ".lof" ".lot" ".glo" ".blg" ".bbl" ".cp" ".cps"
                  ".fn" ".fns" ".ky"
                  ".kys" ".pg" ".pgs" ".tp" ".tps" ".vr" ".vrs" ".pyo"))


(require 'apropos+)


;; we have to set this variable _before_ we load it...  kind of
;; screwey... oh well... :)
(defvar *cltl2-local-file-pos* (expand-file-name "~/site-lisp/cltl_ht/cltl/clm")
  "a directory where the cltl2 can be found. note that this assumes
 to be the top-level of the directory structure which should be the
 same as in the hypertext version as provided by the cmu ai repository.
 defaults to /usr/doc/html/cltl/ note the / at the end.")

(define-key ctl-x-map "r/C-z" 'rm-set-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)


;;   (require 'abbrev-sort)
;;   (abbrev-sort-mode 1)
(global-set-key "/C-cc" 'counter)
;; will do that binding.  also include this code
(autoload 'counter "counter" nil t)
(require 'color-mode)
(require 'c-comment-edit)

(require 'dabbrev-hover)

(require 'list-register)

(autoload 'mapreplace-string "mapreplace" nil t)
(autoload 'mapreplace-regexp "mapreplace" nil t)
(autoload 'query-mapreplace "mapreplace" nil t)
(autoload 'query-mapreplace-regexp "mapreplace" nil t)
(require 'multi-region)
;; (require 'orwell)
(require 'uniq)
(require 'ws-trim)
(require  'info-apropos)
(require 'gse-number-rect)
(global-set-key "/C-xru" 'gse-number-rectangle)


(defun sams-apply-macro-on-region (start end command) ;[jesper]
  "evaluate a given function (or the last defined macro) on region.
i.e. it will continue until the point is position
outside the region.

this function is much like the function apply-macro-to-region-lines,
which is shipped with emacs. it has one difference though. it
executes the macros until point is below the end of the region."
  (interactive "r/nacommand name (default:last keyboard macro).")
  (goto-char end)
  (let ((mark (point-marker)))
    (goto-char start)
    (while (< (point) (marker-position mark))
      (if (not (fboundp command))
      (call-last-kbd-macro)
    (command-execute command)))))

(require 'scrat)


;; (defun scratch () (interactive)
;;   (scratch "*scratch*" ))

(defun switch-to-scratch ()
  "switch to scratch buffer.
create one in `emacs-lisp-mode' if not exists."
  (interactive)
  (let ((previous (get-buffer "*scratch*")))
    (switch-to-buffer "*scratch*")
    ;; don't change current mode
    (unless previous (emacs-lisp-mode))))

(defun it () (interactive)
  (scratch "*itch*"))

(defun n1() (interactive)
  (scratch "*1*"))

(defun n2() (interactive)
  (scratch "*2*"))

(defun n3() (interactive)
  (scratch "*3*"))

(defun n4() (interactive)
  (scratch "*4*"))

(defun n5() (interactive)
  (scratch "*5*"))

(defun nt () (interactive)
  (scratch "*notes*" 'text-mode))


(defun nt1 () (interactive)
  (scratch "*notes1*" 'text-mode))


(defun nt2 () (interactive)
  (scratch "*notes2*" 'text-mode))

(defun nt3 () (interactive)
  (scratch "*notes3*" 'text-mode))


(defun nt4 () (interactive)
  (scratch "*notes4*" 'text-mode))


(defun nt5 () (interactive)
  (scratch "*notes5*" 'text-mode))


(defun nt6 () (interactive)
  (scratch "*notes6*" 'text-mode))


(defun nt7 () (interactive)
  (scratch "*notes7*" 'text-mode))


(defun music () (interactive)
  (scratch "*music*" 'fundamental-mode
       'musical-letters-mode
       'auto-fill-mode))


(defun cpp () (interactive)
  (scratch "*cpp*" 'c++-mode
       ))



(put 'downcase-region 'disabled nil)



(require 'tabbar)
(tabbar-mode)

(global-set-key [M-up] 'tabbar-backward-group)
(global-set-key [M-down] 'tabbar-forward-group)
(global-set-key [M-left] 'tabbar-backward)
(global-set-key [M-right] 'tabbar-forward)
;; set tabbar to show all tabs. but does not work...
(setq tabbar-buffer-groups-function 'tabbar-buffer-ignore-groups)

(defun tabbar-buffer-ignore-groups (buffer)
  "return the list of group names buffer belongs to.
return only one group for each buffer."
  (with-current-buffer (get-buffer buffer)
    (cond
     ((or (get-buffer-process (current-buffer))
          (memq major-mode
                '(comint-mode compilation-mode)))
      '("process")
      )
     ((member (buffer-name)
              '("*scratch*" "*messages*" "*itch*" "*cpp*" "*notes*"))
      '("common")
      )
     ((eq major-mode 'dired-mode)
      '("dired")
      )
     ((memq major-mode
            '(help-mode apropos-mode info-mode man-mode))
      '("help")
      )
     ((memq major-mode
            '(rmail-mode
              rmail-edit-mode vm-summary-mode vm-mode mail-mode
              mh-letter-mode mh-show-mode mh-folder-mode
              gnus-summary-mode message-mode gnus-group-mode
              gnus-article-mode score-mode gnus-browse-killed-mode))
      '("mail")
      )
     ((memq major-mode
            '(c++-mode c-mode))
      '("programming")
      )
     (t
      (list
       "default" ;; no-grouping
       (if (and (stringp mode-name) (string-match "[^ ]" mode-name))
           mode-name
         (symbol-name major-mode)))
      )

     )))

(defun my-kill-ring-save (&optional line)
  "this function is a enhancement of `kill-ring-save', which is normal used
to copy a region.  this function will do exactly as `kill-ring-save' if
there is a region selected when it is called. if there is no region, then do
copy lines as `yy' in vim."
  (interactive "p")
  (unless (or line (and mark-active (not (equal (mark) (point)))))
    (setq line 1))
  (if line
      (let ((beg (line-beginning-position))
            (end (line-end-position)))
        (when (>= line 2)
          (setq end (line-end-position line)))
        (when (<= line -2)
          (setq beg (line-beginning-position (+ line 2))))
        (if (and my-kill-ring-save-include-last-newline
                 (not (= end (point-max))))
            (setq end (1+ end)))
        (kill-ring-save beg end))
    (call-interactively 'kill-ring-save)))
;; set the following var to t if you like a newline to the end of copied text.
(setq my-kill-ring-save-include-last-newline nil)
;; bind it



(defun my-kill-region (&optional line)
  "this function is a enhancement of `kill-region', which is normal used to
kill a region to kill-ring.  this function will do exactly as `kill-region'
if there is a region selected when it is called. if there is no region, then
do kill lines as `dd' in vim."
  (interactive "p")
  (unless (or line (and mark-active (not (equal (mark) (point)))))
    (setq line 1))
  (if line
      (let ((beg (line-beginning-position))
            (end (line-end-position)))
        (when (>= line 2)
          (setq end (line-end-position line)))
        (when (<= line -2)
          (setq beg (line-beginning-position (+ line 2))))
        (if (and my-kill-region-include-last-newline
                 (not (= end (point-max))))
            (setq end (1+ end)))
        (kill-region beg end))
    (call-interactively 'kill-region)))
;; set the following var to t if you like a newline in the end of killed text.
(setq my-kill-region-include-last-newline t)
;; bind it

(global-set-key [/C-w] 'my-kill-region)
(global-set-key [/M-w] 'my-kill-ring-save)





(require 'dired-single)

;(define-key dired-mode-map (kbd "ret") 'joc-dired-single-buffer)
(define-key dired-mode-map (kbd ".")
;; type . to go back to the parent directory
'(lambda ()
(interactive)
(let ((current-dir (dired-current-directory)))
(joc-dired-single-buffer "..")
(dired-goto-file current-dir))))




;; convert text files between unix and dos
(defun dos-unix () (interactive)
  (goto-char (point-min))
  (while (search-forward "/r" nil t) (replace-match "")))
(defun unix-dos () (interactive)
  (goto-char (point-min))
  (while (search-forward "/n" nil t) (replace-match "/r/n")))


(setq sql-ms-options '("-w" "100" "-n"))
(toggle-truncate-lines nil)

(autoload 'icmp-lookup "icmp-info" "perform an icmp lookup" t)
(autoload 'icmp-list   "icmp-info" "list icmp types and codes" t)
(autoload 'protocols-lookup      "protocols" "perform a protocol lookup" t)
(autoload 'protocols-clear-cache "protocols" "clear the protocols cache" t)

;;; final version: `while'
(defun count-words-region (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))))))




(require 'ascii-table)

(require 'popup-ruler)
(global-set-key [f9]    'popup-ruler)

(require 'remember)
(require 'line-num)


(require  'markerpen)



(defun markerpen-mark-region-seq ()
  "change markerpen with sequence of calls."
  (interactive)
  (flet ((prefix-numeric-value (x) (identity x)))
    (markerpen-clear-region)
    (markerpen-mark-region (1+ (seq-times 'markerpen-mark-region-seq 10)))))




(require 'color-moccur)
           



(require 'w32-find-dired)
(require 're-builder)

(defun insert-date (prefix)
  "insert the current date. with prefix-argument, use iso format. with
   two prefix arguments, write out the day and month name."
  (interactive "p")
  (let ((format (cond
         ((not prefix) "%d.%m.%y")
         ((equal prefix '1) "%y-%m-%d")
         ((equal prefix '2) "%a,%y-%m-%d")
         ((equal prefix '3) "%a, %d. %b %y")))
    (system-time-locale "de_de"))
    (insert (format-time-string format))))

(require 'savehist-20+)

(savehist-load)


(require 'browse-kill-ring+)

(global-set-key "/C-cy" '(lambda ()
                           (interactive)
                           (popup-menu 'yank-menu)))


(require  'map-lines)

(require 'protbuf)
(require 'cl)

(defvar *c-sources-extensions* '("cc" "c" "m" "cpp" "c"))

(defun* swap-h-c ()
  (interactive)
  (let* ((name (buffer-file-name))
         (exte (file-name-extension name)))
    (cond ((string= "h" exte)
       (dolist (ext *c-sources-extensions*)
         (let ((other (format "%s.%s"
                  (file-name-sans-extension name) ext)))
           (when (file-exists-p other)
         (find-file other)
         (return-from swap-h-c)
         )
           )
         )
       (find-file  (format "%s.%s"
                   (file-name-sans-extension name)
                   (first  *c-sources-extensions*)
                   )
               )
       )
      ((member* exte *c-sources-extensions* :test (function string=))
       (find-file (format "%s.%s"
                  (file-name-sans-extension name) "h")))
      (t (beep)
         )
      )
    )
  )

(global-set-key (kbd "<M-f6>") 'swap-h-c)




(autoload 'textmenu "textmenu" "text mode substitute for menubar" t)
(global-set-key [f7] 'textmenu)



;;;;;;;;;;;;;;;;;
;;; functions ;;;
;;;;;;;;;;;;;;;;;
(defvar fc-old-command "")

(defun fc-insert-process-output ()
  "runs a shell command and insert the output before point"
  (interactive)
  (setq fc-old-command
        (read-from-minibuffer "insert output of: " fc-old-command))
  (call-process "sh" nil t nil "-c" fc-old-command))

(defun fc-send-region-to-process (beg end)
  "sends the region as input to a shell command and discards the output"
  (interactive "r")
  (setq fc-old-command
        (read-from-minibuffer "send region to: " fc-old-command))
  (call-process-region beg end "sh" nil nil nil "-c" fc-old-command))

(defun fc-pipe-region-through-process (beg end)
  "pipes the region through a shell command and replaces it with the output"
  (interactive "r")
  (setq fc-old-command
        (read-from-minibuffer "pipe region through: " fc-old-command))
  (call-process-region beg end "sh" t t nil "-c" fc-old-command))

(defun fc-eval-and-replace ()
  "replace the preceding sexp with its value."
  (interactive)
  (backward-kill-sexp)
  (prin1 (eval (read (current-kill 0)))
         (current-buffer)))

(defun fc-add-rectangle (start end)
  "add all the lines in the region-rectangle and put the result in the
kill ring."
  (interactive "r")
  (let ((sum 0))
    (mapc (lambda (line)
            (string-match "-?[0-9.]+" line)
            (setq sum (+ sum (string-to-number (match-string 0 line)))))
          (extract-rectangle start end))
    (kill-new (number-to-string sum))
    (message "%s" sum)))

(defun fc-kill-to-beginning-of-line ()
  "kill from the beginning of the line to point."
  (interactive)
  (let* ((beg (point-at-bol))
         (end (point))
         (str (buffer-substring beg end)))
    (delete-region beg end)
    (kill-new str)))

(defun fc-remove-text-properties (text)
  "remove all text properties from text."
  (with-temp-buffer
    (insert text)
    (buffer-substring-no-properties (point-min) (point-max))))




(require 'find-files)
;;and you may rebind "c-x c-f" by also adding the following line
(global-set-key [(control x) (control f)] 'find-files-glob)
(require 'dirtree)
(put 'upcase-region 'disabled nil)

(defun line-to-top()
  "puts the current line at the top of the window"
  (interactive)
  (recenter 3))

(global-set-key [(control ?l)] 'line-to-top)

(global-set-key "/M-g" 'eval-current-buffer)
(global-set-key "/C-c/C-z" 'pop-global-mark)
(add-hook 'tree-imenu-mode-hook
      (lambda ()
        (define-key tr-mode-map "j" 'next-line)
        (define-key tr-mode-map "k" 'previous-line)
        (define-key tr-mode-map "l" 'forward-char)
        (define-key tr-mode-map "h" 'backward-char)))
(setq tr-dir-windows-width  nil)
(global-set-key (kbd "<M-f3>") 'shrink-frame-horizontally)
(global-set-key (kbd "<M-f4>") 'enlarge-frame-horizontally)
(autoload 'df-mode "df-mode" nil t)
(df-mode 1)

(require 'toggle-case)
(global-set-key [(control /`)] 'joc-toggle-case)
(global-set-key [(control ~)] 'joc-toggle-case-backwards)
(global-set-key [(meta /`)] 'joc-toggle-case-by-word)
(global-set-key [(meta ~)] 'joc-toggle-case-by-word-backwards)




(set-face-foreground 'bold-italic "blue")
(add-hook 'scheme-mode-hook (function font-lock-mode))
(add-hook 'scheme-mode-hook
      (lambda ()
        (add-hook 'post-command-hook
              'scheme-post-command-highlight-function)))

(defun scheme-post-command-highlight-function ()
  "flash matching opening paren after cursor movement commands."
  (and
   (memq this-command
     '(backward-char forward-char previous-line next-line
             backward-delete-char-untabify))
   (memq (preceding-char) '(93 41 125))
   (unwind-protect
       ;; bind temporarily matching delay to 2 seconds & face to bold
       ;; change 2 to whatever - delay is broken on first user action
       (let ((blink-matching-delay 2)
         (region-face 5))
     (push-mark nil t)
     ;; show the region
     ;; this is very cheap, but will have to do - for now.
     (setq transient-mark-mode t)
     (blink-matching-open))
     (pop-mark))))




(defun wy-scheme-mode-hook ()
  (defun scheme-send-region (start end)
    "send the current region to the inferior scheme process."
    (interactive "r")
    (let ((origbuffer (current-buffer))
          (proc (get-buffer-process (if (eq major-mode 'inferior-scheme-mode)
                                        (current-buffer)
                      scheme-buffer))))
      (or proc
          (progn
            (run-scheme scheme-program-name)
            (pop-to-buffer (process-buffer (scheme-proc)) t)
            (goto-char (point-max))
            (pop-to-buffer origbuffer))))

    (comint-send-region (scheme-proc) start end)
    (comint-send-string (scheme-proc) "/n")
    (scheme-display-buffer))
  )

(add-hook 'scheme-mode-hook 'wy-scheme-mode-hook)

(defun scheme-display-buffer ()
  "display the inferior-maxima-process buffer so the recent output is visible."
  (interactive)
  (let ((origbuffer (current-buffer)))
    (pop-to-buffer (process-buffer (scheme-proc)) t)
    (goto-char (point-max))
    (pop-to-buffer origbuffer)))

(defun scheme-send-line ()
  "send the line to the inferior scheme process."
  (interactive)
  (scheme-send-region
   (save-excursion
     (beginning-of-line) (point))
   (save-excursion
     (progn (end-of-line) (point)))))

;(define-key scheme-mode-map (kbd "c-c c-c") 'scheme-send-line)
;; jbank@alum.mit.edu
;; 10/2000
;;
;; provides key bindings and functions for moving around the mark ring.
;; exports: prev-mark, next-mark
;; bindings: m-p, m-n

;;for reference, the original is in simple.el
(defun my-set-mark-command (arg)
  "see doc for set-mark-command"
  (interactive "p")
  (if (null arg)
      (progn
    (set-mark-command arg))
    (if (< arg 0)
        (set-mark-command arg)
      (progn
        (rev-pop-mark)
        (goto-char (mark t))))))

;;based on pop-mark in simple.el
(defun rev-pop-mark ()
  (if mark-ring
      (let ((mark-ring-last (car (reverse mark-ring))))
    (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring))
    (set-marker (mark-marker) (+ 0 mark-ring-last) (current-buffer))
    (deactivate-mark)
    (move-marker mark-ring-last nil)
    (if (null (mark t)) (ding))
    (setq mark-ring (reverse (cdr (reverse mark-ring)))))))

(defun prev-mark ()
  (interactive)
  (my-set-mark-command -1))

(defun next-mark ()
  (interactive)
  (my-set-mark-command 1))
(global-set-key "/M-p" 'prev-mark)
(global-set-key "/M-n" 'next-mark)
;(global-unset-key "/M-p" )
; (global-unset-key "/M-n" )
;; jbank@alum.mit.edu
;; 10/2000
;;
;; provide simple function to create named shell buffers.
;; very useful.
;;
;; exports: nshell

(defun nshell (command-line)
  (interactive (list (read-from-minibuffer "new shell name: ")))
  (if (not (comint-check-proc (format "*%sshell*" command-line)))
      (let* ((prog (or explicit-shell-file-name
                       (getenv "eshell")
                       (getenv "shell")
                       "/bin/sh"))
             (name (file-name-nondirectory prog))
             (startfile (concat "~/.emacs_" name))
             (xargs-name (intern-soft (concat "explicit-" name "-args"))))
        (set-buffer (apply 'make-comint (format "%sshell" command-line) prog
                           (if (file-exists-p startfile) startfile)
                           (if (and xargs-name (boundp xargs-name))
                               (symbol-value xargs-name)
                             '("-i"))))
        (shell-mode)))
  (switch-to-buffer (format "*%sshell*" command-line)))




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; jbank@alum.mit.edu
;; 10/2000
;;
;; some simple buffer positioning commands and bindings.
;;
;; exports: center-to-top, next-def-to-top, prev-def-to-top, split-small
;; bindings: c-x 9, c-x l, c-x p, m-l, c-cc

(defun center-to-top ()
  "pull current cursor postion to top of screen"
  (interactive)
  (recenter 0))

(defun next-def-to-top ()
  "pull the next definition to the top of the screen"
  (interactive)
  (end-of-defun 2)
  (beginning-of-defun)
  (center-to-top))

(defun prev-def-to-top ()
  "pull the next definition to the top of the screen"
  (interactive)
  (beginning-of-defun)
  (center-to-top))

(defun split-small ()
  "split the screen with-bottom small"
  (interactive)
  (split-window-vertically -10))
                    ;(global-set-key "/c-xm" 'ctl-x-m-map)
(global-set-key "/C-x9" 'split-small)
(global-set-key "/C-xl" 'next-def-to-top)
(global-set-key "/C-xp" 'prev-def-to-top)
(defun turn-emacs-into-word ()
  "Make Emacs look more like a wordprocessor than Emacs."
  (interactive)
  (set-default-font "-outline-Times New Roman-normal-r-normal-normal-*-*-96-96-p-*-iso8859-1")
  )

(require  'color-theme-maker)
(require  'foreach)
(require  'tjic-shell.el)
(require 'tjicutil-funcs)
;;                    

(require 'tree-dir)
(require 'tree-info)

(require 'tree)


(defmacro dolist-if ( pair condtion body)
  (list 'let '(result)
        (list 'dolist  (append pair '(result))
              (list 'if condtion
                    (list 'setq 'result
                          (list 'append 'result
                                (list 'list
                                      (list 'progn
                                            body))))))))
(setq compilation-last-buffer
      "*notes1*"
      )
(defvar wcy-find-grep-file-class
  '(( ".*//.h$"
      ".*//.c$"
      ".*//.cc$"
      ".*//.cxx$"
      ".*//.cpp$")
    (".*//.el$")))
(defvar wcy-find-grep-file-class-history nil)

(if (boundp 'tool-bar-map)
    (tool-bar-add-item "search-in-file"
                       'wcy-find-grep
                       'wcy-find-grep
                       :help "search in files"))

(defun wcy-find-grep-internal (  regexp dir-name regexp-for-filter-file)
  (let ((my-grep-command (concat " grep  -e '"
                                 (mapconcat 'identity regexp-for-filter-file "//|")
                                 "'" )))
    (setq dir-name (expand-file-name dir-name))
    (grep-find (concat "find "
                       dir-name
                       "  -type f -print | "
                       my-grep-command
                       " | xargs -e grep -h -n -e '"
                       regexp
                       "'")))
  (with-current-buffer compilation-last-buffer
    (local-set-key (kbd "c-l") 'wcy-find-grep-hide-dirname)
    (setq default-directory dir-name)
    (wcy-find-grep-hide-dirname)
    ))

(defun wcy-find-grep-hide-dirname ()
  (interactive)
  (if (not (eq major-mode 'compilation-mode))
      (error "must run this command under grep-find mode buffer")
    (save-excursion
      (goto-char (point-min))
      (let* ((dir-name default-directory)
             (r (re-search-forward (concat "^" (regexp-quote dir-name)) nil t))
             begin end)progn
         (while r
           (setq begin (match-beginning 0))
           (setq end (match-end 0))
           (let* ((x (overlays-in begin end))
              (e (or (and x (car x)) (make-overlay begin end))))
         (overlay-put e 'invisible (not (overlay-get e 'invisible))))
           (setq r (re-search-forward (concat "^" (regexp-quote dir-name)) nil t )))))))


(defun wcy-find-grep ( regexp dir-name regexp-for-fileter-file)
  (interactive (list  (read-from-minibuffer "regexp:"
                                            (concat "//<"
                                                    (regexp-quote (current-word))
                                                    "//>") ;; initial content is nil
                                            nil    ;; key map is nil
                                            nil    ;; read as lisp expression, false;
                                            'regexp-history
                                            nil    ;; not default
                                            nil ;;inherit-input-method
                                            )
                      (read-file-name (format "directory(recursively):" )
                                      nil default-directory nil)
                      (if (buffer-file-name (current-buffer))
                          nil
                        (read-from-minibuffer "file regexp:"
                                              nil
                                              nil
                                              nil
                                              'wcy-find-grep-file-class-history
                                              nil
                                              nil))))
  (let ((files-filter
         (if (null regexp-for-fileter-file)
         (dolist-if (var wcy-find-grep-file-class)
            (string-match
             (mapconcat 'identity var "//|")
             (buffer-file-name (current-buffer)))
            var)
           (list (list regexp-for-fileter-file)))))
    (wcy-find-grep-internal regexp  dir-name (apply 'append files-filter))))

(eval-after-load "fff" '(fff-install-map))
(autoload 'fff-find-emacs-lisp-library                "fff-elisp" nil t)
(autoload 'fff-insert-emacs-lisp-library              "fff-elisp" nil t)
(autoload 'fff-locate-emacs-lisp-library              "fff-elisp" nil t)
(autoload 'fff-find-loaded-elisp-function-or-variable "fff-elisp" nil t)
(require 'win-disp-util)
;;    (require 'eval-expr)
(require 'eval-expr)
(eval-expr-install)
(require 'horoscope)
(require 'flame)
(require 'fshell)
;(pc-selection-mode)
;;;better registers!
(require 'better-registers)
(better-registers-install-save-registers-hook)
(load better-registers-save-file)

(setq fill-column 90)
(autoload 'columnize-text "columnize"
  "formats a list of items into columns (pillars)" t)
(load "columnize" nil t)

(global-set-key [/c-x ?c] 'columnize-text)
(require 'column-marker)
;; use `c-c m' interactively to highlight with `column-marker-1-face'.
(global-set-key [/c-c ?n] 'column-marker-1)
(require 'face-list)
(require 'grep-edit)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;
(require 'sql)
(setq sql-user "ipofas")
(setq sql-password "sagacity")
(setq sql-database "ipofas")
(setq sql-server "yexiuy")

(add-hook 'sql-interactive-mode-hook 'abbrev-mode)
(defun sql-sql-logons (instance username)
  (fset (intern (concat instance "-" username))
        `(lambda () "hello" (interactive)
           (let ((sql-user ,username)
                 (sql-password ,username)
                 (sql-database ,instance))
             (defalias 'sql-get-login 'ignore)
             (sql-ms))
           (let ((sql-alternate-buffer-name (concat "osql: " ,instance "/" ,username)))
             (sql-rename-buffer)))))

(defun ora-sql-logons (instance username)
  (fset (intern (concat instance "-" username))
        `(lambda () "hello" (interactive)
           (let ((sql-user ,username)
                 (sql-password ,username)
                 (sql-database ,instance))
             (defalias 'sql-get-login 'ignore)
             (sql-ms))
           (let ((sql-alternate-buffer-name (concat "ora: " ,instance "/" ,username)))
             (sql-rename-buffer)))))

(add-to-list 'auto-mode-alist '("//.sql$" . sql-mode))


(define-abbrev sql-mode-abbrev-table  "esc" "exec sp_columns @table_name=/'null/'" nil)
(define-abbrev sql-mode-abbrev-table  "est" "exec sp_tables null, null, null,/"'table'/"/n go" nil)
(define-abbrev sql-mode-abbrev-table  "se" "show errors" nil)
(define-abbrev sql-mode-abbrev-table  "ss" "select * from" nil)
(define-abbrev sql-mode-abbrev-table  "scd" "select count(distinct" nil)
(define-abbrev sql-mode-abbrev-table  "cd" "count(distinct" nil)
(define-abbrev sql-mode-abbrev-table  "sd" "select distinct" nil)
(define-abbrev sql-mode-abbrev-table  "cr" "create or replace" nil)
(define-abbrev sql-mode-abbrev-table  "d" "distinct" nil)
(define-abbrev sql-mode-abbrev-table  "da" "@desc_all" nil)
(define-abbrev sql-mode-abbrev-table  "i" "insert" nil)
(define-abbrev sql-mode-abbrev-table  "s" "select" nil)
(define-abbrev sql-mode-abbrev-table  "f" "from" nil)
(define-abbrev sql-mode-abbrev-table  "g" "group by" nil)
(define-abbrev sql-mode-abbrev-table  "o" "order by" nil)
(define-abbrev sql-mode-abbrev-table  "w" "where" nil)
(define-abbrev sql-mode-abbrev-table  "l" "like '%%'" nil)
(define-abbrev sql-mode-abbrev-table  "tt" "truncate table" nil)
(define-abbrev sql-mode-abbrev-table  "dt" nil nil)
(define-abbrev sql-mode-abbrev-table  "ct" "create table" nil)
(define-abbrev sql-mode-abbrev-table  "ii" "insert into" nil)
(define-abbrev sql-mode-abbrev-table  "over" "over (partition by" nil)
(define-abbrev sql-mode-abbrev-table  "case" "case when xxx then yyy else zzz end" nil)
(define-abbrev sql-mode-abbrev-table  "ei" "execute immediate" nil)
(define-abbrev sql-mode-abbrev-table  "ask" "alter system kill session" nil)
(define-abbrev sql-mode-abbrev-table  "xfg" "explain plan set statement_id = 'gboyersplan' into plan_table for" nil)
(define-abbrev sql-mode-abbrev-table  "xf" "explain plan for" nil)
(define-abbrev sql-mode-abbrev-table  "x" "@explain" nil)
(define-abbrev sql-mode-abbrev-table  "xg" "@explain_galen" nil)
(define-abbrev sql-mode-abbrev-table  "xd" "@explain_distributed" nil)
(define-abbrev sql-mode-abbrev-table  "xpart" "@explain_partitioned" nil)
(define-abbrev sql-mode-abbrev-table  "xparr" "@explain_parrallel" nil)
(define-abbrev sql-mode-abbrev-table  "do" "dbms_output.put_line(':' || );" nil)
(define-abbrev sql-mode-abbrev-table "ash" "alter session set hash_area_size=" nil)
(define-abbrev sql-mode-abbrev-table "ast" "alter session set timed_statistics=;" nil)
(define-abbrev sql-mode-abbrev-table "asst" "alter session set sql_trace=")
(define-abbrev sql-mode-abbrev-table "asev" "alter session set events '10046 trace name context forever, level 12';")
(define-abbrev sql-mode-abbrev-table "sl" "set linesize")
(define-abbrev sql-mode-abbrev-table "st" "set timing")
(define-abbrev sql-mode-abbrev-table "cfs" "@columnformatstrings")
(define-abbrev sql-mode-abbrev-table "u" "update")

(require 'tempo)
(tempo-define-template
 "plsql-create-function" ;; template name
 '((p "name of plsql block: " plsqlname 'noinsert)
   "create or replace function "
   (s plsqlname) "("n>
   "    l_###  varchar2" n>
   ",   l_###  number" n>
   ")" n>
   "as" n>
   "  l_var  xxx;" n>
   "begin"   n>
   "    null;" n>
   "end " (s plsqlname) ";" n>
   "/"
   ))

(tempo-define-template
 "select-count-group-by" ;; template name
 '((p "table selected from: " tsf 'noinsert)
   (p "fields to group on: " fgo 'noinsert)
   "select "
   (s fgo)
   ",count(*) " n>
   "from "
   (s tsf) n>
   " group by "
   (s fgo)
   ";"))

;(define-abbrev sql-mode-abbrev-table  "sc" "select count(*) from" nil)
;(define-abbrev sql-mode-abbrev-table  "scg" "" 'tempo-template-select-count-group-by)

(tempo-define-template
 "sql-column-format"
 '((p "varchar column name: " column-name 'noinsert)
   (p "column length: " column-length 'noinsert)
   "column "
   (s column-name)
   " format a"
   (s column-length)))

;(define-abbrev sql-mode-abbrev-table "cf" "" 'tempo-template-sql-column-format)

(tempo-define-template
 "select-count-group-by-having"    ;; template name
 '((p "table selected from: " tsf 'noinsert)
   (p "fields to group on: " fgo 'noinsert)
   "select "
   (s fgo)
   ",count(*) " n>
   "from "
   (s tsf) n>
   " group by "
   (s fgo) n>
   " having count(*) > "))

;(define-abbrev sql-mode-abbrev-table  "scgh" "" 'tempo-template-select-count-group-by-having)

(tempo-define-template
 "createall" ;; template name
 '((p "filename: " filename 'noinsert)
   "select 'executing sql in file "
   (s filename)
   "' what from dual;" n>
   "@@"
   (s filename)))
;(define-abbrev sql-mode-abbrev-table  "createall" "" 'tempo-template-createall)

(tempo-define-template
 "public-synonym" ;; template name
 '((p "objectname: " object_name 'noinsert)
   "create public synonym  "
   (s object_name)
   " for "
   (s object_name)
   ";" n>
   "grant references on "
   (s object_name)
   " to public;"))
;(define-abbrev sql-mode-abbrev-table  "pubsyn" "" 'tempo-template-public-synonym)

(tempo-define-template
 "sql-create-package" ;; template name
 '((p "package name: " package_name 'noinsert)
   "create or replace package "
   (s package_name) n>
   "as" n>
   "    procedure truncate_table;" n>
   "    procedure load_table;" n>
   "end;" n>
   "/" n> n>
   "show errors" n>
   "-------------------------------------" n>
   "create or replace package body "
   (s package_name) n>
   "as" n>
   "    procedure truncate_table as" n>
   "    begin" n>
   "        null" n>
   "    end;" n>
   "    procedure load_table as" n>
   "    begin" n>
   "        null" n>
   "    end;" n>
   "end;" n>
   "/" n>
   "show errors" n>
   ))

(tempo-define-template
 "sql-create-view" ;; template name
 '((p "view name: " view-name 'noinsert)
   "/********************************************************************" n>
   "* name: "
   (s view-name) n>
   "*" n>
   "* description: " n>
   "*" n>
   "* excel xref: report# " n>
   "*" n>
   "* questions: " n>
   "*" n>
   "********************************************************************/" n>
   "create or replace view "
   (s view-name) n>
   "as" n>
   "select '1' as hello_world " n>
   "from  dual   " n>
   "where 1=1  " n>
   ";" n>
   ))

(tempo-define-template
 "sql-documentation-view" ;; template name
 '((p "view name: " view-name 'noinsert)
   "/********************************************************************" n>
   "* name: "
   (s view-name) n>
   "*" n>
   "* description: " n>
   "*" n>
   "*" n>
   "********************************************************************/"
   ))
;(define-abbrev sql-mode-abbrev-table  "docv" "" 'tempo-template-sql-documentation-view)

;; if you use your favorite sqlmode entry function such as
;; sql-oracle, you will be popped to the other buffer. that means,
;; the screen will split horizontally if it is not already split,
;; and the other window will show the sqli buffer.

;; if you prefer the behaviour of switch-to-buffer, then put code
;; similar to this one into your ~/.emacs file:

(defun my-sql-oracle ()
  "switch to buffer before popping."
  (interactive)
  (if (and (boundp 'sql-buffer)
           (buffer-live-p sql-buffer))
      (switch-to-buffer sql-buffer)
    (sql-oracle)))
(define-key sql-mode-map (kbd "tab") 'indent-relative)

(defun eat-sqlplus-junk (str)
  "eat the line numbers sql*plus returns.
    put this on `comint-preoutput-filter-functions' if you are
    running sql*plus.

    if the line numbers are not eaten, you get stuff like this:
    ...
      2    3    4       from v$parameter p, all_tables u
              *
    error at line 2:
    ora-00942: table or view does not exist

    the mismatch is very annoying."
  (interactive "s")
  (while (string-match " [ 1-9][0-9]  " str)
    (setq str (replace-match "" nil nil str)))
  str)

(defun install-eat-sqlplus-junk ()
  "install `comint-preoutput-filter-functions' if appropriate.
    add this function to `sql-interactive-mode-hook' in your .emacs:
    /(add-hook 'sql-mode-hook 'install-eat-sqlplus-junk)"
  (if (string= (car (process-command (get-buffer-process sql-buffer)))
               sql-oracle-program)
      (add-to-list 'comint-preoutput-filter-functions
                   'eat-sqlplus-junk)))

(add-hook 'sql-interactive-mode-hook 'install-eat-sqlplus-junk)

;; when you are using sqlmode, you can send text from your sql
;; buffer to your sqli buffer. this text is usually not added to the
;; history of sql statements in the sqli buffer. if you want that,
;; add the following piece of advice to your .emacs file:
(defadvice sql-send-region (after sql-store-in-history)
  "the region sent to the sqli process is also stored in the history."
  (let ((history (buffer-substring-no-properties start end)))
    (save-excursion
      (set-buffer sql-buffer)
      (message history)
      (if (and (funcall comint-input-filter history)
               (or (null comint-input-ignoredups)
                   (not (ring-p comint-input-ring))
                   (ring-empty-p comint-input-ring)
                   (not (string-equal (ring-ref comint-input-ring 0)
                                      history))))
          (ring-insert comint-input-ring history))
      (setq comint-save-input-ring-index comint-input-ring-index)
      (setq comint-input-ring-index nil))))
(ad-activate 'sql-send-region)

(setq sql-imenu-generic-expression
      '(("comments" "^-- //(.+//)" 1)
        ("function definitions" "^//s-*//(function//|procedure//)[ /n/t]+//([a-z0-9_]+//)[ /n/t]*([a-z0-9 _,/n/t]*)[ /n/t]*//(return[ /n/t]+[a-z0-9_]+[ /n/t]+//)?[ai]s//b" 2)
        ("function prototypes" "^//s-*//(function//|procedure//)[ /n/t]+//([a-z0-9_]+//)[ /n/t]*([a-z0-9 _,/n/t]*)[ /n/t]*//(return[ /n/t]+[a-z0-9_]+[ /n/t]*//)?;" 2)
        ("indexes" "^//s-*create//s-+index//s-+//(//w+//)" 1)
        ("tables" "^//s-*create//s-+table//s-+//(//w+//)" 1)))


(defun sql-previous-where-clause ()
  "insert the previous where clause at point."
  (interactive)
  (let* ((previous-line (comint-previous-input-string 1))
     (case-fold-search nil)
     (where-index (string-match "where" previous-line)))
    (if where-index
    (insert-string (substring previous-line where-index nil)))))

(add-hook 'sql-mode-hook
      (function (lambda ()
              (local-set-key "/c-cw" 'sql-previous-where-clause))))

(add-hook 'sql-interactive-mode-hook
      (function (lambda ()
              (local-set-key "/c-cw" 'sql-previous-where-clause))))



(require  'sql-complete)


(setq sql-data-dictionary '(("tb_er_abb_pteventcall" "tb_port" "tb_dev_protect_base" "tb_dev_waverec_base"  "tb_sys_config"  "tb_downloadfile"  "tb_sys_group "  "tb_sys_group_func"  "tb_sys_func"  "tb_pt_ai"  "tb_pt_di"  "tb_pt_didata"  "tb_pt_alarm_def" "tb_pt_event_def" "tb_pt_settingconfig" "tb_pt_settingdata"  "tb_pt_action"  "tb_pt_alarm" "tb_pt_action_character" "tb_pt_osc_ai" "tb_pt_osc_di" "tb_pt_common_group" "tb_pt_group_type" "tb_pt_softboard" "tb_pt_softboard_data" "tb_pt_device_inf" "tb_pt_run_status" "tb_osc_status" "tb_soe_config" "tb_pt_type" )))

(setq sql-data-dictionary '(("tb_port" "tb_dev_protect_base" "tb_dev_waverec_base"  "tb_sys_config"  "tb_downloadfile"  "tb_sys_group "  "tb_sys_group_func"  "tb_sys_func"  "tb_pt_ai"  "tb_pt_di"  "tb_pt_didata"  "tb_pt_alarm_def" "tb_pt_event_def" "tb_pt_settingconfig" "tb_pt_settingdata"  "tb_pt_action"  "tb_pt_alarm" "tb_pt_action_character" "tb_pt_osc_ai" "tb_pt_osc_di" "tb_pt_common_group" "tb_pt_group_type" "tb_pt_softboard" "tb_pt_softboard_data" "tb_pt_device_inf" "tb_pt_run_status" "tb_osc_status" "tb_soe_config" "tb_pt_type" "a" "addr" "addr103" "cmd" "cmdname" "autoupload" "b" "com_id" "cpu" "crc" "ctposition" "channel" "channel1" "channel2" "codename" "code_name" "dll_name" "device_id" "device_type" "frequencyno" "fromcpu" "fromzone" "fun" "gin" "generalname" "group" "group_id" "id" "inf" "inf101" "installtype" "iskg" "is_not" "item" "keyname" "kind" "limits" "manufactory" "maxvalue" "minvalue" "model" "model_id" "name" "no" "notes" "onlychanged" "pt_func" "pt_id" "pt_type" "ptype" "password" "phase" "precision" "property" "propertyname" "protect_type" "ratio" "reserve1" "reserve2" "screenno" "serialno" "special" "station_id" "status" "stepvalue" "syscreate" "sysversion" "time" "tocpu" "tozone" "type" "unit" "vpicklist" "vtype" "value" "value1" "value2" "voltage" "element" "ms")))


(add-hook 'sql-interactive-mode-hook
      (function (lambda ()
              (setq comint-completion-autolist t)
              (local-set-key  (kbd "<tab>")  'sql-complete)
              (local-set-key   [(shift tab)] 'marshalyyx-sql-complete))))


(defun marshalyyx-delete-space(str_str)
  (if (string-match "^[^a-za-z0-9-]*//([a-za-z0-9_-]+//)[ ]*$"  str_str)
      (setq str_str (substring  str_str (match-beginning 1) (match-end 1))

        ))
  str_str)

(defvar column-data-col nil)

(defun marshalyyx-column ()
  (interactive)
  (let* ((symb (cond ((fboundp 'symbol-nearest-point) (symbol-nearest-point))
             ((fboundp 'symbol-at-point) (symbol-at-point))
             (t nil)))
     (str (format "select '('+name+')' from syscolumns where id=/( select distinct  id from sysobjects where name='%s'/) order by colid /n go" (symbol-name symb)))
     (temp-column-data-col nil)
     (column-data-col nil)
     )
    (setq temp-column-data-col(marshalyyx-sql-data-dictionary str))
    (setq column-data-col(copy-tree temp-column-data-col))
    (get-buffer-create "column-completion")
    (split-small)
    (other-window 1)
    (switch-to-buffer "column-completion")
    (erase-buffer)
    (insert (format "%s:  /n"(symbol-name symb)))
    (while temp-column-data-col
      (if (= (% (length temp-column-data-col) 6) 0)
      (insert "/n"))
      (insert (format "%-15s" (car temp-column-data-col)))
      (setq temp-column-data-col (cdr temp-column-data-col))
      )
    (goto-char (point-min))
                    ;    (edebug)
    (other-window 1)
    ))

(defun marshalyyx-sql-data-dictionary (statement)
  "return table and columns from the oracle data dictionary using sql.
statement must be a sql statement that returns the data dictionary
one column per line.  each line must look like this:

/(/"table-name/" /"column-name/")

any lines not looking like this will be skipped to allow for column
headers and other fancy markup.

this currently depends very much on a good `comint-prompt-regexp'."
  (when (null sql-buffer)
    (error "no sqli buffer available"))
  (save-excursion
    (switch-to-buffer sql-buffer)
    (erase-buffer)
    (let (result end
         (return-column-name nil))
      (sql-send-string statement)
      (accept-process-output (get-process "osql") 1)
      (goto-char(point-min))
      (comint-line-beginning-position)
                    ;      (edebug)
      (while (= 0 (forward-line 1))
                    ;    (message "%s" (point))
    (when (looking-at "^[ ]*//((.*)//)[ ]*$")
      (mark-sexp)
      (setq point-begin (point)   )
      (exchange-point-and-mark-nomark)
      (setq point-end (point)   )
      (setq before-str  (buffer-substring-no-properties point-begin point-end))
      (setq before-str  (substring before-str 2 (- (length before-str) 1)))
      (setq return-column-name (cons before-str return-column-name ))
      ))
      (bury-buffer)
      (reverse return-column-name)
      )))

(global-set-key "/C-cm" 'marshalyyx-column)


(defun marshalyyx-sql-complete ()
  (interactive)
  (let ((completions (apply 'append (marshalyyx-get-column-name))))
    (comint-dynamic-simple-complete
     (comint-word "a-za-z_")
     completions)))

(defun marshalyyx-get-column-name()
  (interactive)
  (let ((ret-column-name-list nil) temp-string result)
    (get-buffer-create "column-completion")
    (switch-to-buffer "column-completion")
    (goto-char (point-min))
    (setq temp-string (buffer-substring-no-properties (point-min) (point-max)))
    (bury-buffer)
    (setq ret-column-name-list (split-string temp-string ))
    (let* ((entry  ret-column-name-list)
       (table (car entry))
       (column (cadr entry))
       (item (cdr (assoc table result))))
      (if item
      (nconc item (list column))
    (setq result (append (list entry) result))))
    ))

(global-set-key "/C-cm" 'marshalyyx-column)
(defun my-retate-windows ()
  (interactive)
  (if (= (count-windows) 2)
      (let* ((wl    (window-list))
             (w1    (frame-first-window))
             (w2    (if (equal w1 (car wl)) (cadr wl) (car wl)))
             (b1    (window-buffer w1))
             (b2    (window-buffer w2))
             (first (if (equal (current-buffer) b1) t nil)))
        (if (= (window-width) (frame-width))
            (split-window-horizontally)
          (split-window-vertically))
        (other-window 2)
        (delete-window)
        (switch-to-buffer b1)
        (other-window 1)
        (switch-to-buffer b2)
        (when first (other-window 1)))
    (message "there are not exactly 2 windows.")))
(require 'less)
(require 'string-fns)
(require 'list-fns)
(add-hook  'find-file-hooks 'auto-less-minor-mode)
(add-hook  'tetris-mode-hook  (lambda ()
                (interactive)
                (define-key tetris-mode-map "d"    'tetris-move-left)
                (define-key tetris-mode-map "k"    'tetris-move-right)
                (define-key tetris-mode-map "f"    'tetris-rotate-prev)
                (define-key tetris-mode-map "j"    'tetris-rotate-next)
                ))

(require 'math-fns)
(require 'miscutils)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defmacro wcy-define-2bind-transient-mode (funname cmd-mark-active
                                                   cmd-mark-no-active)
  `(defun ,funname ()
     (interactive)
     (if mark-active
         (call-interactively ,cmd-mark-active)
       (call-interactively ,cmd-mark-no-active))))

(defun query-replace-selection (to-string &optional delimited start end)
  "query reqlace the current selection in transient mark mode."
  (interactive (list
                (read-from-minibuffer (format "query replace %s with: "
                                              (buffer-substring (point) (mark)))
                                      nil nil nil
                                      query-replace-to-history-variable
                                      (buffer-substring (point) (mark))

                                      t)
                nil nil nil
                ))
  (perform-replace (buffer-substring (point) (mark)) to-string t nil delimited
           nil nil start end))
(wcy-define-2bind-transient-mode
 wcy-query-replace-or-query-replace-selection
 'query-replace-selection
 'query-replace)
(global-set-key (kbd "M-%") 'wcy-query-replace-or-query-replace-selection)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



(autoload 'gtags-mode "gtags" "" t)

(setq c-mode-hook
      '(lambda ()
     (gtags-mode 1)
     ))



(defun backward-to-non-blank (&optional arg)
  "go to nth (def=1) non blank (after blank) to left"
  (interactive "p")
  (setq arg (or arg 1))
  (if (re-search-backward "[ /t/n][^ /t/n]" (point-min) t arg)
      (forward-char 1)
    (if (string-match "[^ /t/n]" (buffer-substring 1 2))
    (goto-char (point-min)))))


(defun buffer-name-not-mini ()
  "return the name of current buffer, as a string.
if current buffer is the *mini-buffer* return name of previous-window."
  (buffer-name (if (window-minibuffer-p)
           (if (eq (get-lru-window) (next-window))
               (window-buffer (previous-window))
             (window-buffer (next-window)))
         nil)))

(defun insert-word-or-file-name ()
  "copy word cursor is on or file name to minibuff input"
  (interactive)
  (let* ((bfl (current-buffer))
     (str ""))
    (set-buffer (buffer-name-not-mini))
    (cond
     ((eq major-mode 'dired-mode)
      (setq str (dired-get-filename t t)))
     ((eq major-mode 'audit-mode)
      (setq str (audit-get-filename t t)))
     (t
      (let (bch ech)
    (forward-char 1)
    (backward-to-non-blank)
    (setq bch (point))
    (re-search-forward "[^ /t/n][ /t/n]" (point-max) t)
    (setq ech (1- (point)))
    (setq str (buffer-substring bch ech)))))
    (set-buffer bfl)
    (insert str)))



;; replacment of set-variable from simple.el
(defun set-variable (var &optional val)
  "hacked by ehud karni (sw). added automatic help for the variable set.
set variable to value.  value is a lisp object.
when using this interactively, supply a lisp expression for value.
if you want value to be a string, you must surround it with doublequotes (/")."
  (interactive
   (let* ((var (intern (completing-read "set variable: " obarray 'boundp 1)))
      (prop (get var 'variable-interactive)))
     (describe-variable var)
     (list var
       (if prop ;; see original defintion in simple.el
           (call-interactively `(lambda (arg)
                      (interactive ,prop)
                      arg))
         (eval-minibuffer (format "set %s to value: " var)
                  (and (boundp var)
                   (prin1-to-string (symbol-value var))))))))
  (set var val))

(setq my-list-buffers-window-height 16)

(defun my-list-buffers (&optional files-only)
  (interactive "p")
  (let ((buffer (list-buffers-noselect files-only))
        window)
    (display-buffer buffer)
    (setq window )
    (enlarge-window (max (- (window-height (get-buffer-window buffer))
                            my-list-buffers-window-height)
                         (- window-min-height (window-height))))))

(substitute-key-definition 'list-buffers 'my-list-buffers global-map)


(add-to-list 'special-display-buffer-names
             '("*buffer list*" (height . 16) (width . 80)))

(add-hook 'isearch-mode-hook '(lambda ()
                (define-key isearch-mode-map "/C-h" 'isearch-delete-char)
                (define-key isearch-mode-map [h-h] 'isearch-mode-help)))

(add-hook 'c++-mode-hook
      (lambda ()
        (local-set-key "/C-c/t" 'complete-symbol)
        (local-set-key "/C-m" 'newline-and-indent)
        (setq mslk-c++-key (make-keymap))
        (local-set-key "/C-j" mslk-c++-key)
        (define-key mslk-c++-key "/c-j" 'complete-symbol)
        (define-key mslk-c++-key "/c-o" 'hs-hide-all)
        (define-key mslk-c++-key "/c-p" 'hs-show-all)
        (define-key mslk-c++-key "/c-h" 'hs-hide-block)
        (define-key mslk-c++-key "/c-u" 'hs-show-block)
        (define-key mslk-c++-key "/c-l" 'hs-hide-level)
        (define-key mslk-c++-key "/c-m" 'hs-toggle-hiding)
        (local-set-key [f11] 'dd-open-h-cpp)
        ))

(require 'eval-expr)
(eval-expr-install)
(require 'idle-scroll)

(require 'lib-requires)

(add-hook 'c-mode-hook 'turn-on-auto-revert-mode)
(require 'visible-mark-mode)
(require 'ibuf-ext nil t)
(when (featurep 'ibuf-ext)
  (add-hook 'ibuffer-mode-hook (lambda ()
                                 (setq ibuffer-filter-groups
                       '(
                     ("*buffer*" (name . "//*.*//*"))
                     ("tags" (name . "^tags//(<[0-9]+>//)?$"))
                     ("dired" (mode . dired-mode))
                     ("c++" (mode . c++-mode))
                     ("lisp" (mode . emacs-lisp-mode))
                     ("ini" (mode . conf-windows-mode))
                     ("py" (mode . python-mode))
                     ))))
  )

(unless (fboundp 'prefix-region)
  (defun prefix-region (prefix)
    "add a prefix string to each line between mark and point."
    (interactive "sprefix string: ")
    (if prefix (let ((count (count-lines (mark) (point)))) (goto-char (min (mark) (point))) (while (> count 0) (setq count (1- count)) (beginning-of-line 1) (insert prefix) (end-of-line 1) (forward-char 1))))))

(autoload 'query-replace-by-example "query-replace-by-example"
  "get replace string by example." t)
(global-set-key (kbd "C-%") 'query-replace-by-example)
;;;; [2006/02/10] kill-ring / register
(defun kill-ring-save-x (s e)
  (interactive "r")
  (if (eq last-command 'kill-ring-save-x)
      (call-interactively 'copy-to-register)
    (call-interactively 'kill-ring-save)))

(define-key esc-map "w" 'kill-ring-save-x)
;;;; [2006/02/25] kill-region / register
(defun kill-region-x (s e)
  (interactive "r")
  (if (eq last-command 'kill-region)    ;kill-region-x ?
      (call-interactively 'my-kill-ring-to-register)
    (call-interactively 'kill-region)))
(defun my-kill-ring-to-register (register)
  (interactive "ccopy to register: ")
  (set-register register (car kill-ring)))

(define-key global-map "/C-w" 'kill-region-x)
(require 'minibuf-isearch)
(defun p-non-whitespace()
  "search backwards for first non-whitespace character."
  (interactive)
  (cond
   ((eq t (looking-back "[ /n/t]"))
    (while (looking-back "[ /n/t]")
      (backward-char nil)))
   ((eq t (looking-at "[ /n/t]"))
    (while (looking-at "[ /n/t]")
      (forward-char nil)))
   ))

(global-set-key "/M-m/M-m" 'p-non-whitespace)


(defun match-paren (arg)
  (interactive "p")
  (cond ((looking-at      "//s/(") (forward-list 1) (backward-char 1))
        ((looking-at "//s/)") (forward-char 1) (backward-list 1))))
(global-set-key (kbd "C-]") 'match-paren)




(defun geosoft-forward-word ()
  ;; move one word forward. leave the pointer at start of word
  ;; instead of emacs default end of word. treat _ as part of word
  (interactive)
  (forward-char 1)
  (backward-word 1)
  (forward-word 2)
  (backward-word 1)
  (backward-char 1)
  (cond ((looking-at "_") (forward-char 1) (geosoft-forward-word))
    (t (forward-char 1))))

(defun geosoft-backward-word ()
  ;; move one word backward. leave the pointer at start of word
  ;; treat _ as part of word
  (interactive)
  (backward-word 1)
  (backward-char 1)
  (cond ((looking-at "_") (geosoft-backward-word))
    (t (forward-char 1))))

;;bind the functions to ctrl-left and ctrl-right with:

(global-set-key [c-right] 'geosoft-forward-word)
(global-set-key [c-left] 'geosoft-backward-word)

(require 'winring)
(winring-initialize)

(define-key isearch-mode-map (kbd "C-e") 'isearch-move-point)
(define-key isearch-mode-map (kbd "C-a") 'isearch-move-point)
(define-key isearch-mode-map (kbd "M-a") 'isearch-move-point)
(define-key isearch-mode-map (kbd "C-M-e") 'isearch-move-point)
(define-key isearch-mode-map (kbd "C-M-a") 'isearch-move-point)
(define-key isearch-mode-map (kbd "C-f") 'isearch-move-point)
(define-key isearch-mode-map (kbd "C-b") 'isearch-move-point)
(define-key isearch-mode-map (kbd "M-f") 'isearch-move-point)
(define-key isearch-mode-map (kbd "M-b") 'isearch-move-point)
(define-key isearch-mode-map (kbd "C-M-f") 'isearch-move-point)
(define-key isearch-mode-map (kbd "C-M-b") 'isearch-move-point)

(defun isearch-move-point ()
  (interactive)
  (when isearch-success
    (save-excursion
      (let ((overriding-terminal-local-map nil)
            (old-point (or isearch-other-end (point))))
        (call-interactively (key-binding (this-command-keys)))
        (setq isearch-string (buffer-substring-no-properties  old-point
                                                              (point))
              isearch-message
              (mapconcat 'isearch-text-char-description
                         isearch-string "")
              ;; don't move cursor in reverse search.
              isearch-forward (cond
                               ((< old-point (point)) t)
                               ((> old-point (point)) nil)
                               ((= old-point (point)) isearch-forward))
              )))
    (isearch-search-and-update)))

(defalias 'qrr 'query-replace-regexp)


(defun another-line (&optional arg)
  "copy line, preserving cursor column, and increment any numbers found.
this should probably be generalized in the future."
  (interactive "p")
  (let* ((col (current-column))
         (bol (progn (beginning-of-line) (point)))
         (eol (progn (end-of-line) (point)))
         (line (buffer-substring bol eol)))
    (beginning-of-line)
    (if arg
    (if  (re-search-forward "[0-9]+" eol t arg)
        (let ((num (string-to-int (buffer-substring
                       (match-beginning 0) (match-end 0)))))
          (replace-match (int-to-string (1+ num)))))

      (progn
    (while (re-search-forward "[0-9]+" eol t)
      (let ((num (string-to-int (buffer-substring
                     (match-beginning 0) (match-end 0)))))
        (replace-match (int-to-string (1+ num)))))

    )
      )
    (beginning-of-line)
    (insert line "/n")
    (move-to-column col)))

(defun nea-kill-all-comments-in-region (begin end)
  "kill all comments in region."
  (interactive "r")
  (save-excursion
    (goto-char begin)
    (kill-comment (count-lines begin end))))

(defun bnum (n)
  "returns positive number n represented in boolean, as a string."
  (if (= 0 n)
      "0"
    (let ((s ""))
      (while (/= 0 n)
        (setq s (concat (if (= 0 (% n 2)) "0" "1") s))
        (setq n (/ n 2)))
      s)))




(require 'regadhoc)
(global-set-key "/C-xrj" 'regadhoc-jump-to-registers)
(global-set-key "/C-x/" 'regadhoc-register)
(setq regadhoc-register-char-list (list ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)) ;; optional
;;; 'regadhoc-register-char-list is list of your "favorite" register's char.


(defmacro dolist-if ( pair condtion body)
  (list 'let '(result)
        (list 'dolist  (append pair '(result))
              (list 'if condtion
                    (list 'setq 'result
                          (list 'append 'result
                                (list 'list
                                      (list 'progn
                                            body))))))))





(require 'c-toggle-dot-pointer)


(defun sucha-simple-journal-add-entries  (heading)
  "open the local diary file and add entries today."

;;; if you need backup, remove the ';' beginning of the line
                    ;(shell-command "tar -czpf backup_filename.tgz ~/path-to/files-dir/;
                    ;  mv backup_filename.tgz ~/path-to/backup-dir/")

  (find-file (format "~/journal/dir/%s"
                     (format-time-string "%y-%m")))

  (goto-char (point-min))
  (unless (re-search-forward "^# " nil t)
    (insert "# user's journal created "
            (format-time-string "%y-%m-%d/n") "/n"))

  (forward-line 1)
  (insert "/n/n/n/n")
  (forward-line -3)
  (insert (concat
           "<"
           (format-time-string "%e")"  ,   "
           (format-time-string "%a ")
           (format-time-string "%h:%m")
           ">  "
           heading
           "/n    "))
  (text-mode))

(defun sucha-simple-journal-add-heading ()
  "get the local journal heading from minibuffer."
  (interactive)
  (sucha-simple-journal-add-entries
   (read-from-minibuffer "journal heading: ")))


(require 'split-window-multi)

(require 'multiverse.el)

(require  'mwe-log-commands)
(add-hook 'text-mode-hook (function mwe:log-keyboard-commands))
(require 'mwe-color-boxes)
(custom-set-faces
 '(mwe:nesting-face-0 ((((class color)) (:background "#90b0f0"))))
 '(mwe:nesting-face-1 ((((class color)) (:background "#b090f0"))))
 '(mwe:nesting-face-2 ((((class color)) (:background "#f0b090"))))
 '(mwe:nesting-face-3 ((((class color)) (:background "#90b0f0"))))
 '(mwe:nesting-face-4 ((((class color)) (:background "#90f0b0"))))
 '(mwe:nesting-face-5 ((((class color)) (:background "#b0f090"))))
 '(mwe:nesting-face-6 ((((class color)) (:background "#b090f0"))))
 '(mwe:nesting-face-7 ((((class color)) (:background "#90b0f0"))))
 '(mwe:nesting-face-8 ((((class color)) (:background "#b0f090")))))


(require 'utils)

(put 'erase-buffer 'disabled nil)

                    ;(require 'pymacs)
(autoload 'pymacs-load "pymacs" nil t)
(autoload 'pymacs-eval "pymacs" nil t)
(autoload 'pymacs-apply "pymacs")
(autoload 'pymacs-call "pymacs")
(eval-after-load "pymacs"  '(add-to-list   pymacs-load-path "d:/emacs/site-lisp/pymacs-0.22"))

(require 'colorcomp)

(require  'lib-requires)

(require 'narrow-undo)

(require 'super-fold)

(setq counter-format "%d/n")

(require 'vmsh-mode)

(require  'winpoint)




(defun py-next-block ()
  "go to the next block.  cf. `forward-sexp' for lisp-mode"
  (interactive)
  (py-mark-block nil 't)
  (back-to-indentation))



(defun xor (b1 b2)
  "exclusive or of its two arguments."
  (or (and b1 b2)
      (and (not b1) (not b2))))

(defun move-border-left-or-right (arg dir)
  "general function covering move-border-left and move-border-right. if dir is
     t, then move left, otherwise move right."
  (interactive)
  (if (null arg) (setq arg 5))
  (let ((left-edge (nth 0 (window-edges))))
    (if (xor (= left-edge 0) dir)
    (shrink-window arg t)
      (enlarge-window arg t))))

(defun move-border-left (arg)
  "if this is a window with its right edge being the edge of the screen, enlarge
     the window horizontally. if this is a window with its left edge being the edge
     of the screen, shrink the window horizontally. otherwise, default to enlarging
     horizontally.

     enlarge/shrink by arg columns, or 5 if arg is nil."
  (interactive "p")
  (move-border-left-or-right arg t))

(defun move-border-right (arg)
  "if this is a window with its right edge being the edge of the screen, shrink
     the window horizontally. if this is a window with its left edge being the edge
     of the screen, enlarge the window horizontally. otherwise, default to shrinking
     horizontally.

     enlarge/shrink by arg columns, or 5 if arg is nil."
  (interactive "p")
  (move-border-left-or-right arg nil))

(global-set-key (kbd "M-[") 'move-border-left)
(global-set-key (kbd "M-]") 'move-border-right)


(require 'acme-search)
;(global-set-key [(mouse-3)] 'acme-search-forward)
;(global-set-key [(shift mouse-3)] 'acme-search-backward)
(require 'help-mode+)

(require 'flashcard)
(add-to-list 'auto-mode-alist '("//.deck//'" . flashcard-mode))
(defun kill-all-buffers ()
  (interactive "")
  (mapcar 'kill-buffer (buffer-list)))
(require 'dired-isearch)

(define-key dired-mode-map (kbd "C-s") 'dired-isearch-forward)
(define-key dired-mode-map (kbd "C-r") 'dired-isearch-backward)
(define-key dired-mode-map (kbd "ESC C-s") 'dired-isearch-forward-regexp)
(define-key dired-mode-map (kbd "ESC C-r") 'dired-isearch-backward-regexp)

;;; many thanks to ilovecpp
(defvar switch-major-mode-last-mode nil)
(make-variable-buffer-local 'switch-major-mode-last-mode)

(defun major-mode-heuristic (symbol)
  (and (fboundp symbol)
       (string-match ".*-mode$" (symbol-name symbol))))

(defun switch-major-mode (mode)
  (interactive
   (let ((fn switch-major-mode-last-mode)
         val)
     (setq val
           (completing-read
            (if fn
                (format "switch major mode to (default %s): " fn)
              "switch major mode to: ")
            obarray 'major-mode-heuristic t nil nil (symbol-name fn)))
     (list (intern val))))
  (let ((last-mode major-mode))
    (funcall mode)
    (setq switch-major-mode-last-mode last-mode)))
                    ;(global-set-key (kbd "c-c m") 'switch-major-mode)




(defun ywb-insert-item ()
  (interactive)
  (let (curr next)
    (beginning-of-line)
    (cond ((looking-at "//(//s-*//)//([0-9]+//)//.//s-*")
           (setq curr (string-to-number (buffer-substring (match-beginning 2)
                                                          (match-end 2))))
           (setq next (number-to-string (1+ curr)))
           (end-of-line)
           (insert "/n" (buffer-substring (match-beginning 1)
                                          (match-end 1))
                   next ". ")
           (ywb-sync-item))
          ((looking-at "//s-*[-+]//s-*")
           (progn
             (end-of-line)
             (insert "/n" (buffer-substring (match-beginning 0)
                                            (match-end 0)))))
          (t
           (progn
             (end-of-line)
             (newline-and-indent))))))

(defun ywb-sync-item ()
  (interactive)
  (save-excursion
    (beginning-of-line)
    (if (looking-at "//(//s-*//)//([0-9]+//)//.//s-*")
        (let ((curr (string-to-number (buffer-substring (match-beginning 2)
                                                        (match-end 2))))
              (blank1 (buffer-substring (match-beginning 1)
                                        (match-end 1)))
              (blank2 (buffer-substring (match-end 2)
                                        (match-end 0))))
          (while (progn
                   (beginning-of-line 2)
                   (looking-at "//s-*[0-9]+//.//s-*"))
            (setq curr (1+ curr))
            (delete-region (match-beginning 0) (match-end 0))
            (insert blank1 (number-to-string curr) blank2))))))


(defun ywb-toggle-display-point (&optional arg)
  (interactive "p")
  (if (null arg)
      (setq arg 0))
  (message "arg: %d" arg)
  (let ((point-format '(:eval (format " %d " (point))))
        (off (null (member point-format global-mode-string))))
    (cond ((> arg 0)
           (if off
               (setq global-mode-string
                     (append global-mode-string (list point-format)))))
          ((< arg 0)
           (if (not off)
               (setq global-mode-string
                     (remove point-format global-mode-string))))
          ;; if arg 0, if off turn on, else turn off
          (off
           (ywb-toggle-display-point 1))
          (t
           (ywb-toggle-display-point -1)))))


(global-set-key (kbd "C-c u") 'revert-buffer)

(require 'windmove nil t)

(when (featurep 'windmove)
  (global-set-key (kbd "C-c n") 'windmove-down)
  (global-set-key (kbd "C-c p") 'windmove-up)
  (global-set-key (kbd "C-c ,") 'windmove-left)
  (global-set-key (kbd "C-c .") 'windmove-right)
  (windmove-default-keybindings))


;; (setq tetris-update-speed-function
;;       (lambda (shapes rows)
;;         (/ 10.0 (+ 80.0 rows))))

(setq sentence-end "//([      ]//|    //|[.?!][]/"')}]*//($//|[ /t]//)//)[ /t/n]*")
;;;###autoload
(defun ywb-dired-copy-fullname-as-kill (&optional arg)
  "in dired mode, use key w to get the full name of the file"
  (interactive "p")
  (let (file)
    (setq file (dired-get-filename nil t))
    (or (not arg)
        (cond ((= arg 1)
               (setq file (convert-standard-filename file)))
              ((= arg 2)
               (setq file (ywb-convert-to-cygwin-path file)))
              ((= arg 3)
               (setq file (convert-standard-filename (file-name-directory file))))))
    (if (eq last-command 'kill-region)
        (kill-append file nil)
      (kill-new file))
    (message "%s" file)))

(defvar ywb-dired-quickview-buffer nil)
(defun ywb-dired-quickview ()
  (interactive)
  (if (buffer-live-p ywb-dired-quickview-buffer)
      (kill-buffer ywb-dired-quickview-buffer))
  (setq ywb-dired-quickview-buffer
        (find-file-noselect (dired-get-file-for-visit)))
  (display-buffer ywb-dired-quickview-buffer))


(defun ywb-dired-compress-dir ()
  (interactive)
  (let ((files (dired-get-marked-files t)))
    (if (and (null (cdr files))
             (string-match "//.//(tgz//|tar//.gz//)" (car files)))
        (shell-command (concat "tar -xvf " (car files)))
      (let ((cfile (concat (file-name-nondirectory
                            (if (null (cdr files))
                                (car files)
                              (directory-file-name default-directory))) ".tgz")))
        (setq cfile
              (read-from-minibuffer "compress file name: " cfile))
        (shell-command (concat "tar -zcvf " cfile " " (mapconcat 'identity files " ")))))
    (revert-buffer)))



(add-hook 'dired-mode-hook (lambda ()
                 (define-key dired-mode-map "z" 'ywb-dired-compress-dir)
                 (define-key dired-mode-map "j" 'ywb-dired-jump-to-file)
                 (define-key dired-mode-map "w" 'ywb-dired-copy-fullname-as-kill)
                 (define-key dired-mode-map "/C-q" 'ywb-dired-quickview)))




;;;###autoload
(defun ywb-replace-in-rectangle (beg end)
  (interactive "r/n")
  (let ((replace (query-replace-read-args "replace string" nil)))
    (apply-on-rectangle (lambda (s e)
                          (setq s (progn (move-to-column s) (point))
                                e (progn (move-to-column e) (point)))
                          (replace-string (car replace) (cadr replace) nil s e))
                        beg end)))



;;;###autoload
(defun ywb-sort-lines-1 (reverse beg end predicate)
  (save-excursion
    (save-restriction
      (narrow-to-region beg end)
      (goto-char (point-min))
      (sort-subr reverse 'forward-line 'end-of-line nil nil
                 predicate))))
;;;###autoload
(defun ywb-org-table-sort-lines (reverse beg end numericp)
  (interactive "p/nr/nssorting method: [n]=numeric [a]=alpha: ")
  (setq numericp (string-match "[nn]" numericp))
  (org-table-align)
  (save-excursion
    (setq beg (progn (goto-char beg) (line-beginning-position))
          end (progn (goto-char end) (line-end-position))))
  (let ((col (org-table-current-column))
        (cmp (if numericp
                 (lambda (a b) (< (string-to-number a)
                                  (string-to-number b)))
               'string<)))
    (ywb-sort-lines-1 reverse beg end
                      (lambda (pos1 pos2)
                        (let ((dat1 (split-string (buffer-substring-no-properties
                                                   (car pos1) (cdr pos1))
                                                  "//s-*|//s-*"))
                              (dat2 (split-string (buffer-substring-no-properties
                                                   (car pos2) (cdr pos2))
                                                  "//s-*|//s-*")))
                          (funcall cmp (nth col dat1) (nth col dat2)))))
    (dotimes (i col) (org-table-next-field))))



(autoload 'ascii-on        "ascii" "turn on ascii code display."   t)
(autoload 'ascii-off       "ascii" "turn off ascii code display."  t)
(autoload 'ascii-display   "ascii" "toggle ascii code display."    t)
(autoload 'ascii-customize "ascii" "customize ascii code display." t)

(require 'hexrgb)



(autoload 'visual-basic-mode "visual-basic-mode" "visual basic mode." t)
(setq auto-mode-alist (append '(("//.//(frm//|bas//|cls//)$" .
                                 visual-basic-mode)) auto-mode-alist))



(defun slick-copy ()
  (interactive)
  "copy the current line if region is inactive. otherwise it behaves just like kill-ring-save"
  (condition-case var (progn (mark) (kill-ring-save (region-beginning) (region-end)))
    ('mark-inactive
     (kill-ring-save (line-beginning-position) (line-beginning-position 2))
     (message "copy line"))))

(defcustom slick-save-to-kill-ring t
  "specify whether slick-cut should use the kill-ring.
 if nil, it will delete the line instead of kill it")

(defun slick-cut (toggle-save-to-kill-ring)
  (interactive "p")
  "cut the current line if region is inactive. otherwise it behaves just like kill-region.
 if prefix argument is specified, will use delete-region instead (in case you are deleting
 a bunch of junk and you don't want to pollute your kill-ring.)
 prefix argument will toggle back to kill-region again."
  (condition-case var (progn (mark) (kill-region (region-beginning) (region-end)))
    ('mark-inactive
     (if toggle-save-to-kill-ring
     (setq slick-save-to-kill-ring
           (if slick-save-to-kill-ring '() t)))
     (if slick-save-to-kill-ring
     (progn (kill-region (line-beginning-position) (line-beginning-position 2))
        (message "cut line"))
       (progn (delete-region (line-beginning-position) (line-beginning-position 2))
          (message "delete line"))))))

(require 'nero)

(require 'incr)


(load-file "e:/software/emacs-22.1/site-lisp/lispsql/emacs-mysql.el")
(load-file "e:/software/emacs-22.1/site-lisp/lispsql/emacs-functions.el")

;; The next 2 stmts go together
;; The completion (when you select a connection) is busted without the second one.
(mysql-create-and-register-auto-object "hanna.carma" "" "" "carma" "" "root" "")
(setq mysql-connection-alist
      (append '(("hanna.carma" . "hanna.carma"))
          mysql-connection-alist))

;; Bind useful commands
;;;;; My custom functions
(global-set-key "/C-ck" 'copy-line)
(global-set-key "/M-k" 'kill-other-buffer)


(add-to-list 'load-path "~/site-lisp/eim")
(autoload 'eim-use-package "eim" "another emacs input method")

;; (register-input-method
;;  "eim-wb" "euc-cn" 'eim-use-package
;;  " "~/site-lisp/eim/wb.txt")
;; (register-input-method
;;  "eim-py" "euc-cn" 'eim-use-package

(global-set-key [(f7)] (lambda () (interactive "")
             (w32-shell-execute nil "explorer" "c://")
             ))
(global-set-key [(M-f7)] (lambda () (interactive "")
               (w32-shell-execute nil "odbccp32.cpl" "")
               ))

(global-set-key [(S-f7)] (lambda () (interactive "")
               (w32-shell-execute nil "isqlw.exe" "")
               ))



(global-set-key [(C-f9)] (lambda () (interactive "")
               (w32-shell-execute nil "control.exe" "")
               ))

(global-set-key [(C-f9)] (lambda () (interactive "")
               (w32-shell-execute nil "firefox.exe" "")
               ))

(global-set-key [(M-f8)] (lambda () (interactive "")
               (w32-shell-execute nil "mysqlquerybrowser.exe" "")
               ))

(global-set-key (kbd "C-c d") (lambda () (interactive "")
                (w32-shell-execute nil "devmgmt.msc" "")
                ))


(global-set-key (kbd "C-c h") (lambda () (interactive "")
                (w32-shell-execute nil "compmgmt.msc" "")
                ))

(global-set-key (kbd "C-c C-n") (lambda () (interactive "")
                  (w32-shell-execute nil "ncpa.cpl" "")
                  ))



(global-set-key (kbd "C-c C-p") (lambda () (interactive "")
                  (w32-shell-execute nil "powercfg.cpl" "")
                  ))

(global-set-key (kbd "C-c C-j") (lambda () (interactive "")
                  (w32-shell-execute nil "sysdm.cpl" "")
                  ))


(load "fontset-win")


(global-set-key [/C-c ?,] 'moccur)



(defun eshell/clear ()
  "clears the shell buffer ala unix's clear or dos' cls"
  (interactive)
  ;; the shell prompts are read-only, so clear that for the duration
  (let ((inhibit-read-only t))
    ;; simply delete the region
    (delete-region (point-min) (point-max))))

                    ;(load "em-joc")


;;    (global-set-key [(control f2)]  (function
;;        (lambda () "change eshell's directory to current buffer's default-directory"
;;          (interactive)
;;          (let ((the-dir default-directory)
;;                (start 0))
;;            (while (string-match " " the-dir start)
;;              (setq the-dir (replace-match "// " nil t the-dir))
;;              (setq start (+ (match-end 0) 1)))
;;            (joc-remote-eshell-cmd (concat "cd " the-dir) 1)))))

;;    (global-set-key [(shift f2)] (function
;;       (lambda (reg-start reg-end)
;;          "send region to eshell as command input"
;;          (interactive "r")
;;          (let ((cmd (buffer-substring reg-start reg-end)))
;;            (joc-remote-eshell-cmd cmd 1)))))


(defadvice eldoc-fnsym-in-current-sexp (around eldoc-fnsym-in-current-sexp-or-command activate)
  ad-do-it
  (if (and (not ad-return-value)
       (eq major-mode 'eshell-mode))
      (save-excursion
    (goto-char eshell-last-output-end)
    (setq ad-return-value (eldoc-current-symbol)))))


(defun eshell-maybe-bol ()
  (interactive)
  (let ((p (point)))
    (eshell-bol)
    (if (= p (point))
    (beginning-of-line))))

(add-hook 'eshell-mode-hook
      '(lambda () (define-key eshell-mode-map "/c-a" 'eshell-maybe-bol)))
(load "which-func")
(which-func-mode)

(delete (assoc 'which-func-mode mode-line-format) mode-line-format)
(setq which-func-header-line-format
      '(which-func-mode
    ("" which-func-format
     )))
(defadvice which-func-ff-hook (after header-line activate)
  (when which-func-mode
    (delete (assoc 'which-func-mode mode-line-format) mode-line-format)
    (setq header-line-format which-func-header-line-format)))


(defun match-paren (arg)
  "go to the matching paren if on a paren; otherwise insert %."
  (interactive "p")
  (cond ((looking-at "//s/(") (forward-list 1) (backward-char 1))
    ((looking-at "//s/)") (forward-char 1) (backward-list 1))
    (t (self-insert-command (or arg 1)))))


(global-set-key "%" 'match-paren)

(defun tiw-comment ()
  "comment/uncomment a line;; "
  (interactive)
  (save-excursion
    (if (gnus-region-active-p)
        (tiw-comment-region)
      (tiw-comment-line))))


(defun tiw-comment-line ()
  "comment or uncomment a line according to
the first charachter"
  (save-excursion
    (beginning-of-line)
    (if (looking-at comment-start)
        (uncomment-region (line-beginning-position) (line-end-position) nil)
      (comment-region  (line-beginning-position) (line-end-position) nil))))

(defun tiw-comment-region ()
  "comment or uncomment a region according to
the first character"
  (interactive)
  (let ((b-p (region-beginning))
        (e-p (region-end)))
    (save-excursion
      (goto-char (region-beginning))
      (if (looking-at comment-start)
          (uncomment-region b-p e-p nil)
        (comment-region b-p e-p nil)))))
(put 'narrow-to-region 'disabled nil)
;;      mew
(autoload 'mew "mew" nil t)
(autoload 'mew-send "mew" nil t)
(setq mew-icon-directory "d:/ntemacs23_2006_02_26/site-lisp/mew/etc")
(setq mew-use-cached-passwd t)

(setq mew-pop-size 0)

(setq mew-pop-delete nil)
(setq mew-config-alist
      '(("default"
     ("name"         .  "yexiuy")
     ("user"         .  "yexiuy")
     ("mail-domain"  .  "xjsh.com")
     ("pop-server"   .  "pop3.xjsh.com")
     ("pop-port"     .  "110")
     ("pop-user"     .  "yexiuy")
     ("pop-auth"     .  pass)
     ("smtp-server"  .  "smtp.xjsh.com")
     ("smtp-port"    .  "25")
     ("smtp-user"    .  "yexiuy")
     ("smtp-auth-list"  .  ("plain" "login" "cram-md5")))))

(defun eldoc-get-arg-index ()
  (save-excursion
    (let ((fn (eldoc-fnsym-in-current-sexp))
          (i 0))
      (unless (memq (char-syntax (char-before)) '(32 39)) ; ? , ?'
        (condition-case err
            (backward-sexp)             ;for safety
          (error 1)))
      (condition-case err
          (while (not (equal fn (eldoc-current-symbol)))
            (setq i (1+ i))
            (backward-sexp))
        (error 1))
      (max 0 i))))

(defun eldoc-highlight-nth-arg (doc n)
  (cond ((null doc) "")
        ((<= n 0) doc)
        (t
         (let ((i 0))
           (mapconcat
            (lambda (arg)
              (if (member arg '("&optional" "&rest"))
                  arg
                (prog2
                    (if (= i n)
                        (put-text-property 0 (length arg) 'face 'underline arg))
                    arg
                  (setq i (1+ i)))))
            (split-string doc) " ")))))

(defadvice eldoc-get-fnsym-args-string (around highlight activate)
  ""
  (setq ad-return-value (eldoc-highlight-nth-arg ad-do-it (eldoc-get-arg-index)))
  )



(add-hook 'python-mode-hook
          '(lambda () (eldoc-mode 1)) t)



(defun my-python-documentation (w)
  "launch pydoc on the word at point"
  (interactive
   (list (let* ((word (thing-at-point 'word))
        (input (read-string
            (format "pydoc entry%s: "
                (if (not word) "" (format " (default %s)" word))))))
       (if (string= input "")
           (if (not word) (error "no pydoc args given")
         word)            ;sinon word
         input))))            ;sinon input
  (shell-command (concat py-python-command " -c /"from pydoc import help;help(/'" w "/'/")") "*pydocs*")
  (view-buffer-other-window "*pydocs*" t 'kill-buffer-and-window))



(add-hook 'python-mode-hook
      (lambda ()
        (define-key python-mode-map "/"" 'electric-pair)
        (define-key python-mode-map "/'" 'electric-pair)
        (define-key python-mode-map "(" 'electric-pair)
        (define-key python-mode-map "[" 'electric-pair)
        (define-key python-mode-map "{" 'electric-pair)))

(defun electric-pair ()
  "insert character pair without sournding spaces"
  (interactive)
  (let (parens-require-spaces)
    (insert-pair)))

(require 'ange-ftp)

(require 'inf-perl)

;;  in windows expand-file-name is require because perl don't where is ~/psh.pl
(setq perl-shell-program (expand-file-name "~/psh.pl"))


(defun make-cpp-function-definition (buffer class-name start end)
  "generate c++ function definition and insert it into `buffer'"
  (interactive "bappend to buffer: /nmclass name: /nr")
  (setq function-declaration (buffer-substring-no-properties start end))
  (setq function-definition nil)
  (defun iter (pos)
    (if (string-match
     "//(?://(?:virtual//|inline//|static//)[ /t/n]*//)?//(?://(//(?:const[ /t/n]*//)?[^ /t/n;* /t/n]*//([^;]+//)//);"
     function-declaration
     pos)
    (progn
      (setq return-type
        (match-string 1 function-declaration))
      (setq one-function-definition
        (match-string 2 function-declaration))
      (if (equal class-name "")
          (setq one-function-declaration
            (concat return-type "/n" one-function-definition))
        (setq one-function-declaration
          (concat return-type "/n"
              class-name "::" one-function-definition)))
      (setq function-definition
        (concat function-definition
            one-function-declaration "/n{/n}/n/n"))
      (iter (match-end 0)))
      '()))
  (save-excursion
    (iter 0)
    (set-buffer (get-buffer-create buffer))
    (setq pos (point))
    (insert function-definition)
    (indent-region pos (point)))
  (if (one-window-p)
      (split-window-vertically))
  (switch-to-buffer-other-window buffer))


(require 'vlf)

(defun vlf-extract-part-of-file (file from to)
  "returns bytes in file from from to to."
  (let ((size (vlf-file-size file)))
    (if (or (> from size)
            (> to size))
        (error "from or to is larger that the file size"))
    (with-temp-buffer
      (shell-command
       (format "head --bytes %d %s | tail --bytes %d"
           to file (+ (- to from) 1)) t)
      (buffer-substring (point-min) (point-max)))))


(setq vlf-batch-size 1000000)

(global-set-key (kbd "<C-f1>") 'inf-perl-start)

(setq auto-mode-alist (append (list (cons "//.pl//'" 'cperl-mode))
                  auto-mode-alist))

(defun perl-contructor ()
  (interactive)
  (insert "
sub new {
  my $proto = shift;
  my $class = ref($proto) || $proto;
  my $self = {};
  bless($self, $class);
  return $self;
}"))
(define-key cperl-mode-map (kbd "c-c p c") 'perl-contructor)


(require 'snippet)

(defun my-snippet-cperl ()
  (define-abbrev-table 'cperl-mode-abbrev-table '())
  (snippet-with-abbrev-table
   'cperl-mode-abbrev-table
   ("if"      .  ">if ($${test}) {/n>$./n>}")
   ("for"     .  ">for $$($${sequence}) {/n>$./n>}")
   ("foreach" .  ">foreach $$($${sequence}) {/n>$./n>}")
   ("wh"      .  ">while ($${test}) {/n>$./n>}")
   ("while"   .  ">while ($${test}) {/n>$./n>}")
   ("do"      .  ">do {/n>$./n>} while($$);")
   ("map"     .  ">map {/n>$./n>}")
   ("grep"    .  ">grep {/n>$./n>}")
   ))

(add-hook 'cperl-mode-hook 'my-snippet-cperl)

(require 'joccur)
(require  'perl-find-library)

;; inspired by erik naggum's `recursive-edit-with-single-window'
(defmacro recursive-edit-preserving-window-config (body)
  "*return a command that enters a recursive edit after executing body.
 upon exiting the recursive edit (with//[exit-recursive-edit] (exit)
 or //[abort-recursive-edit] (abort)), restore window configuration
 in current frame."
  `(lambda ()
     "see the documentation for `recursive-edit-preserving-window-config'."
     (interactive)
     (save-window-excursion
       ,body
       (recursive-edit))))



(global-set-key (kbd "C-c 0") (recursive-edit-preserving-window-config (delete-window)))

(global-set-key (kbd "C-c 1") (recursive-edit-preserving-window-config
                   (if (one-window-p 'ignore-minibuffer)
                   (error "current window is the only window in its frame")
                 (delete-other-windows))))

(require 'all)
(autoload 'chinese-chess "chinese-chess" "play chinese chess game." t)

(local-set-key [(meta up)] 'move-line-up)
(local-set-key [(meta down)] 'move-line-down)

(defun move-line (&optional n)
  "move current line n (1) lines up/down leaving point in place."
  (interactive "p")
  (when (null n)
    (setq n 1))
  (let ((col (current-column)))
    (beginning-of-line)
    (next-line 1)
    (transpose-lines n)
    (previous-line 1)
    (forward-char col)))
(defun move-line-up (n)
  "moves current line n (1) lines up leaving point in place."
  (interactive "p")
  (move-line (if (null n) -1 (- n))))

(defun move-line-down (n)
  "moves current line n (1) lines down leaving point in place."
  (interactive "p")
  (move-line (if (null n) 1 n)))

(require 'unicad)
(require 'fsdired)
(require 'grep-buffers)

(defun come-here ()
  "bring content from *shell command output* to current buffer"
  (interactive)
  (insert-buffer-substring (get-buffer "*shell command output*"))
  )

(defun copy-line (&optional arg)
  "save current line into kill-ring without mark the line "
  (interactive "p")
  (let ((beg (line-beginning-position))
        (end (line-end-position)))
    (copy-region-as-kill beg end))
  )

(defun insert-buffer-name ()
  "insert current buffer name at point"
  (interactive)
  (insert-string (buffer-name (current-buffer)))
  )

(defun copy-word (&optional arg)
  "copy words at point"
  (interactive "p")
  (let ((beg (progn (backward-word 1) (point)))
        (end (progn (forward-word arg) (point))))
    (copy-region-as-kill beg end))
  )

(defun copy-paragraph (&optional arg)
  "copy paragraphes at point"
  (interactive "p")
  (let ((beg (progn (backward-paragraph 1) (point)))
        (end (progn (forward-paragraph arg) (point))))
    (copy-region-as-kill beg end))
  )

(defun move-forward-paren (&optional arg)
  "move forward parenthesis"
  (interactive "p")
  (if (looking-at ")") (forward-char 1))
  (while (not (looking-at ")")) (forward-char 1))
  )

(defun move-backward-paren (&optional arg)
  "move backward parenthesis"
  (interactive "p")
  (if (looking-at "(") (forward-char -1))
  (while (not (looking-at "(")) (backward-char 1))
  )

(require 'get-rfc)

(defun string-search-and-replace (string search replace)
  "replace all instances in string of search with replace."
  (let ((quoted-search (regexp-quote search))
    (start 0))
    (while (string-match quoted-search string start)
      (setq string (replace-match replace nil t string))
      (setq start (+ (match-end 0) (- (length replace)
                      (length search)))))
    string))

(defun my-fontify-region (beg end mode)
  (interactive
   (list (region-beginning)
         (region-end)
         (intern
          (completing-read "which mode to use: "
                           obarray (lambda (s)
                                     (and (fboundp s)
                                          (string-match "-mode$" (symbol-name s))))
                           t))))
  (let ((buf (current-buffer))
        (font-lock-verbose nil)
        (start 1) face face-list)
    (set-text-properties beg end '(face nil))
    (with-temp-buffer
      (goto-char (point-min))
      (insert-buffer-substring buf beg end)
      (funcall mode)
      (font-lock-fontify-buffer)
      (or (get-text-property start 'face)
          (setq start (next-single-property-change start 'face)))
      (while (and start (< start (point-max)))
        (setq end (or (next-single-property-change start 'face)
                      (point-max))
              face (get-text-property start 'face))
        (and face end (setq face-list (cons (list (1- start) (1- end) face) face-list)))
        (setq start end)))
    (when face-list
      (dolist (f (nreverse face-list))
        (put-text-property (+ beg (car f)) (+ beg (cadr f))
                           'face (nth 2 f))))))

(require 'tooltip-help)
(global-set-key (kbd "<f1>") 'th-show-help)

(require 'perldb)

(defun my-term-bash ()
  "like m-x term ret bash ret"
  (interactive)
  (term (getenv "shell")))



(defun write-room ()
  "Make a frame without any bling."
  (interactive)
  ;; to restore:
  ;; (setq mode-line-format (default-value 'mode-line-format))
  (let ((frame (make-frame '((minibuffer . nil)
                 (vertical-scroll-bars . nil)
                 (border-width . 0)
                 (left-fringe . 200)
                 (right-fringe . 200)
                 (menu-bar-lines . 0)
                 (tool-bar-lines . 0)
                 (unsplittable . t)
                 (fullscreen . t)))))
    (select-frame frame)
    (find-file "~/NOTES")
    (setq mode-line-format nil)
    ;; maximize window
    (when (fboundp 'w32-send-sys-command)
      (w32-send-sys-command 61488 frame))))

(require 'tramp)
(setq tramp-default-method "plink"
      tramp-password-end-of-line "/r/n")
(setq scroll-conservatively most-positive-fixnum)


(defun fc-toggle-notes ()
  "switch to the notes file, or switch to the previous buffer."
  (interactive)
  (let ((notes-file "~/.note"))
    (when (file-exists-p notes-file)
      (if (and (buffer-file-name)
               (string= (expand-file-name notes-file)
                        (expand-file-name (buffer-file-name))))
          (bury-buffer)
        (find-file notes-file)))))

(global-set-key [(control c)(s)] 'fc-toggle-notes)
;(require 'sr-speedbar)
;(global-set-key [(super ?s)] 'sr-speedbar-toggle)


;; (if window-system
;;     (if (< (caddr (decode-time (current-time))) 18)
;;         (color-theme-arjen)             ;
;;       (color-theme-deep-blue))          ;
;;   (color-theme-tty-dark))

(defun teds-goto-minibuffer ()
  "Move cursor to minibuffer window"
  (interactive)
  (select-window (minibuffer-window)))
(global-unset-key "/C-cm")
(global-set-key (kbd "C-c m") 'teds-goto-minibuffer)
(global-set-key [(C-z)] 'previous-line)
;(global-set-key "/C-z" 'set-mark-command)
(global-set-key "/C-z" 'next-line)
(global-set-key "/M-z" 'previous-line)



(setq gnus-select-method '(nntp "news.cn99.com"))

(defun kill-other-buffers (&optional arg)
  (interactive "P")
  (loop for i in (buffer-list) when (not (string= (buffer-name i) (buffer-name))) do (kill-buffer i))
  )

(global-set-key (kbd "<f1>") 'kill-other-buffers)

(require 'bm-ext)

(add-to-list 'load-path "~/.emacs.d/site-lisp/eim")
(autoload 'eim-use-package "eim" "Another emacs input method")
(setq eim-use-tooltip nil)
(register-input-method
 "eim-wb" "euc-cn" 'eim-use-package
 "五筆" "漢字五筆輸入法" "wb.txt")
(register-input-method
 "eim-py" "euc-cn" 'eim-use-package
 "拼音" "漢字拼音輸入法" "py.txt")
;; 用 ; 暫時輸入英文
(require 'eim-extra)
(global-set-key ";" 'eim-insert-ascii)



(require 'spartan-wiki)
(add-to-list 'auto-mode-alist '("//.sw$" . spartan-mode))
(require 'goto-chg)

(require 'idle-highlight)

(require 'sticky-windows)
(global-set-key     [(control x) (?0)]        'sticky-window-delete-window)
(global-set-key     [(control x) (?1)]        'sticky-window-delete-other-windows)

;;In addition, `sticky-window-keep-window-visible' might be bound to the currently unused C-x 9 key binding:

(global-set-key     [(control x) (?9)]        'sticky-window-keep-window-visible)


;; (defun findFiles (regex &optional subdir keep-p full-paths-p)
;;   (interactive "sregex of file name (foo.*//.txt):")
;;   (let*
;;       (
;;        (buf (get-buffer-create "*findfiles*"))
;;        (dir default-directory) ;; changed by with-current-buf
;;        (n (if full-paths-p 0 (length dir)))
      
;;        (find-fun
;;         (lambda (regexp dir)
;;           (message "searching %s" dir)
;;           (loop for i in (directory-files dir) do
;;                 (if (and (file-directory-p (concat dir i)) (not (equal i ".")) (not (equal i "..")))
;;                     (funcall find-fun regexp (concat dir i "/")))
;;                 (if (string-match regexp i) (insert (substring dir n) i ":0:/n"))))
;;               )
;;        )
;;     (with-current-buffer buf
;;       (setq buffer-read-only nil)
;;       (if (not keep-p) (erase-buffer))
;;       (setq default-directory dir)
;;       (insert "-*- finding:; " regex "/n/n")
;;       (funcall find-fun regex (concat dir (or subdir "")))
;;       (insert "/n-*- done")
;;       )
;;     (switch-to-buffer-other-window buf)
;;     (grep-mode)   
;;   ))

;; (require 'wuxch-bookmark)
;; (require 'whole-line-or-region)
;; (require 'mine-sweeper)

(require 'shell-pop)

(require 'doc-view)

(require 'auto-complete)
(global-auto-complete-mode t)
(define-key ac-complete-mode-map (kbd "") 'ac-complete)
(define-key ac-complete-mode-map (kbd "M-j") 'ac-complete)
(define-key ac-complete-mode-map (kbd "M-n") 'ac-next)
(define-key ac-complete-mode-map (kbd "M-p") 'ac-previous)
(require 'desktop-menu)


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com