cygwin.root.emacs 5.9 KB
Newer Older
Russ Fish's avatar
Russ Fish committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
; Prototype .emacs file.

(setq inhibit-startup-message t)        ; I've seen it...

;; Set the debug option when there is trouble...
;; (setq debug-on-error t)

; Add my own emacs directory to the load path.
(setq load-path (cons (condition-case () 
                          (expand-file-name "~/emacs") 
                        (error nil)) 
                      load-path))

; Fix the minibuffer completion routines so that SPACE expands as
; much as possible, instead of tab.
(define-key minibuffer-local-completion-map " " 'minibuffer-complete)
(define-key minibuffer-local-completion-map "\t" 'minibuffer-complete-word)
(define-key minibuffer-local-must-match-map " " 'minibuffer-complete)
(define-key minibuffer-local-must-match-map "\t" 'minibuffer-complete-word)

; ================================================================
; Appearance.

(setq default-fill-column 86)

(if (fboundp 'resize-minibuffer-mode)
    (resize-minibuffer-mode))

(if (fboundp 'line-number-mode)
    (line-number-mode t))

(if (fboundp 'column-number-mode)
    (column-number-mode t))

; Use CUA-style cut-and-paste editing (^C,^V,^X,^Z) with transient-mark mode.
;  See http://www.emacswiki.org/cgi-bin/wiki.pl?CopyAndPaste for comparison, 
;  http://www.emacswiki.org/cgi-bin/wiki.pl/CuaMode for Cua installation,
;  http://www.cua.dk/ to download cua.el, put in your own emacs dir or under site-lisp.
(require 'cua)
(CUA-mode t)

; Use the mouse wheel if we have support for it.
(if (fboundp 'mouse-wheel-mode)
     (mouse-wheel-mode 1))

(if (string= window-system "w32")       ; Windows!
    (progn

      ; Make the Left-ctl and Right-Alt combination function as Ctl-Alt.
      ; This is particularly nice if caps-lock is turned into a Left-Ctl key.
      (setq w32-recognize-altgr nil)

      ; To make Caps Lock into a Control key, leaving the original control keys alone:
      ; . See "How do I swap CapsLock and Control?" here:
      ;      http://www.gnu.org/software/emacs/windows/faq3.html
      ; . Get the following file and double-click on it to enter the registry
      ;   settings in regedit, then reboot Windows.
      ;     http://www.gnu.org/software/emacs/windows/ntemacs/contrib/caps-as-ctrl.reg
      
    )
)

;================================================================

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
;; Compilation key bindings.
(global-set-key "\^CE" 'compile)                        ; ^C shift-e
(global-set-key "\^CN" 'next-error)                     ; ^C shift-n
(global-set-key "\^CP" 'previous-error)                 ; ^C shift-p
;(global-set-key "\^CK" 'kill-compilation)              ; ^C shift-k
(global-set-key "\^C}"   'compilation-next-file)        ; ^C shift-[
(global-set-key "\^C{"   'compilation-previous-file)    ; ^C shift-]

(defun make-this-file-writable ()
  "Use this when you want to edit a read-only file.  Changes the file permissions,
   and marks the read-only buffer writable."
  (interactive)
  (if (not (file-writable-p buffer-file-name))
      (set-file-modes buffer-file-name (logior 146   ; 0222, writable file mode.
                                               (file-modes buffer-file-name))))
  (setq buffer-read-only nil))
(global-set-key "\^Cw" 'make-this-file-writable)  ; Bind to ^C-w.

(defun set-c-basic-offset (arg)
  "Set the amount of C indentation to the prefix arg."
  (interactive "NC indentation step: ")
  (setq c-basic-offset arg))

(setq c-mode-common-hook
      (function (lambda ()
                  ; ^C-^B for rename-buffer, don't need c-submit-bug-report.
		  (local-set-key "\^C\^B" 'rename-buffer)
		  (local-set-key "\^CO" 'set-c-basic-offset) ; Bind to ^C shift-O.
		  (modify-syntax-entry ?_ "w")  ; Treat underscore as a word char in C.
                  )))
(setq auto-mode-alist (append '(("\\.h\\'" . c++-mode)) ; .h files are C++ by default.
                              auto-mode-alist))

;================================================================

Russ Fish's avatar
Russ Fish committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
;; Electric help, avoids mucking up the window layout with the *Help* buffer.
(require 'ehelp)
(global-set-key "\C-h" 'ehelp-command)
(global-set-key [help] 'ehelp-command)
(global-set-key [f1] 'ehelp-command)

;; Electric-command-history pops up a command history window for redo.
(autoload 'electric-command-history "echistory" nil t)
(global-set-key "\^C\e" 'electric-command-history)      ; ^C-Escape.

;; Electric-buffer-list pops up window to select/manipulate buffers.
(global-set-key "\^X\^B" 'electric-buffer-list)         ; ^X-^B.
(setq electric-buffer-menu-mode-hook  ; Add key bindings like searches.
      '(lambda ()
         (local-set-key "e" 'Buffer-menu-execute)
         (local-set-key "\^s" 'isearch-forward)
         (local-set-key "\^r" 'isearch-backward)
         (local-set-key "\^a" 'beginning-of-line)
         (local-set-key "\^e" 'end-of-line)
         (local-set-key "\M-f" 'forward-word)
         (local-set-key "\M-b" 'backward-word)
         (local-set-key "\M-w" 'kill-ring-save)))

;================================================================

(defun revert-buffer-no-confirm ()
  "Like revert-buffer, but doesn't ask for confirmation every time."
  (interactive)
  (revert-buffer nil t)
)
(global-set-key "\^XR" 'revert-buffer-no-confirm)

(global-set-key "\^Ca" 'apropos)                ;The system-level apropos fn.

(defun toggle-truncate-lines ()
  "Toggle the truncate-lines variable."
  (interactive)
  (setq truncate-lines (not truncate-lines))
  (recenter)                            ; Redisplay.
  (message "truncate-lines is now %s in this buffer." 
           (if truncate-lines "on" "off"))
)
(global-set-key "\^C\^L" 'toggle-truncate-lines)
; Individually control the truncation in vertically-split windows.
(setq truncate-partial-width-windows nil)

(defun toggle-stack-trace-on-error ()
  "Toggle the stack-trace-on-error variable."
  (interactive)
  (setq stack-trace-on-error (not stack-trace-on-error))
  (message "stack-trace-on-error is now %s." 
           (if stack-trace-on-error "on" "off"))
)
(global-set-key "\^C\^S" 'toggle-stack-trace-on-error)