-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-misc.el
executable file
·208 lines (174 loc) · 6.11 KB
/
init-misc.el
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
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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
;;C-x C-u所选区域大写, C-x C-l所选区域小写
;;f8 calendar, f12 bookmarks
;;C-c z最大化或还原窗口(只适用于windows)
;;----------------------------------------------------------------------------
;; Misc config - yet to be placed in separate files
;;----------------------------------------------------------------------------
(add-auto-mode 'tcl-mode "Portfile$")
(fset 'yes-or-no-p 'y-or-n-p)
(add-hook 'find-file-hooks 'goto-address-prog-mode)
(add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
(setq goto-address-mail-face 'link)
(column-number-mode 1)
; NO automatic new line when scrolling down at buffer bottom
(setq next-line-add-newlines nil)
;Ctrl-X, u/l to upper/lowercase regions without confirm
(put 'downcase-region 'disabled nil);;C-x C-l
(put 'upcase-region 'disabled nil);;C-x C-u
;; no annoying beep on errors
(setq visible-bell t)
(setq backup-directory-alist '(("." . "~/.backups")))
(put 'narrow-to-region 'disabled nil)
; from RobinH
;Time management
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
(display-time)
(global-set-key [f8] 'calendar)
(global-set-key [f12] 'list-bookmarks)
;; (when *win32*
;; resize frame
(defun w32-maximize-frame ()
"Maximize the current frame."
(interactive)
(w32-send-sys-command 61488)
(global-set-key (kbd "C-c z") 'w32-restore-frame))
(global-set-key (kbd "C-c z") 'w32-maximize-frame)
(defun w32-restore-frame ()
"Restore a minimized frame."
(interactive)
(w32-send-sys-command 61728)
(global-set-key (kbd "C-c z") 'w32-maximize-frame))
;; )
;; M-x ct ENTER
(defun ct (dir-name)
"Create tags file."
(interactive "DDirectory: ")
(shell-command
(format "ctags -f %s/TAGS -e -R %s" dir-name (directory-file-name dir-name)))
)
; @see ht
tp://xahlee.blogspot.com/2012/01/emacs-tip-hotkey-for-repeat-complex.html
(global-set-key [f2] 'repeat-complex-command)
;effective emacs item 3
(global-set-key "\C-w" 'backward-kill-word)
(global-set-key "\C-x\C-k" 'kill-region)
(global-set-key "\C-c\C-k" 'kill-region)
(global-set-key "\C-s" 'isearch-forward-regexp)
(global-set-key "\M-s" 'isearch-backward-regexp)
(global-set-key "\C-\M-s" 'tags-search)
(global-set-key "\C-x\C-n" 'find-file-other-frame) ;open new frame with a file
;;a no-op function to bind to if you want to set a keystroke to null
(defun void () "this is a no-op" (interactive))
;convert a buffer from dos ^M end of lines to unix end of lines
(defun dos2unix ()
(interactive)
(goto-char (point-min))
(while (search-forward "\r" nil t) (replace-match "")))
;vice versa
(defun unix2dos ()
(interactive)
(goto-char (point-min))
(while (search-forward "\n" nil t) (replace-match "\r\n")))
;show ascii table
(defun ascii-table ()
"Print the ascii table. Based on a defun by Alex Schroeder <[email protected]>"
(interactive)
(switch-to-buffer "*ASCII*")
(erase-buffer)
(insert (format "ASCII characters up to number %d.\n" 254))
(let ((i 0))
(while (< i 254)
(setq i (+ i 1))
(insert (format "%4d %c\n" i i))))
(beginning-of-buffer))
;insert date into buffer
(defun insert-date ()
"Insert date at point."
(interactive)
(insert (format-time-string "%a %b %e, %Y %l:%M %p")))
;;compute the length of the marked region
(defun region-length ()
"length of a region"
(interactive)
(message (format "%d" (- (region-end) (region-beginning)))))
;; gdb
(global-set-key "\C-x\C-a\C-g" 'gud-run)
(defalias 'list-buffers 'ibuffer)
;KEYBOARD SECTION
;global keyb maps
(global-set-key "\C-xc" 'clipboard-kill-ring-save)
(global-set-key "\C-cc" 'copy-region-as-kill)
(global-set-key [home] 'beginning-of-line)
(global-set-key [end] 'end-of-line)
(global-set-key [\C-home] 'beginning-of-buffer)
(global-set-key [\C-end] 'end-of-buffer)
;;(global-set-key [?\C-/] 'void) ;forward reference
;; @see http://www.emacswiki.org/emacs/BetterRegisters
;; This is used in the function below to make marked points visible
(defface register-marker-face '((t (:background "grey")))
"Used to mark register positions in a buffer."
:group 'faces)
;effective emacs item 7; no scrollbar, no menubar, no toolbar
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
;(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
;effiective emacs item9
(defalias 'qrr 'query-replace-regexp)
;@see http://stackoverflow.com/questions/3509919/ \
;emacs-c-opening-corresponding-header-file
(global-set-key (kbd "C-x C-o") 'ff-find-other-file)
(setq-default regex-tool-backend 'perl)
;shortcut 'ytx', if smex installed
(defun yank-to-x-clipboard ()
(interactive)
(if (region-active-p)
(progn
; my clipboard manager only intercept CLIPBOARD
(shell-command-on-region (region-beginning) (region-end)
(cond
(*cygwin* "putclip")
(*is-a-mac* "pbcopy")
(t "xclip -selection clipboard")
)
)
(message "Yanked region to clipboard!")
(deactivate-mark))
(message "No region active; can't yank to clipboard!")))
(defun paste-from-x-clipboard()
(interactive)
(shell-command
(cond
(*cygwin* "getclip")
(*is-a-mac* "pbpaste")
(t "xclip -o")
)
1)
)
(eval-after-load "speedbar" '(if (load "mwheel" t)
;; Enable wheelmouse support by default
(cond (window-system
(mwheel-install)))))
(track-closed-files-mode)
; @see http://www.emacswiki.org/emacs/SavePlace
(require 'saveplace)
(setq-default save-place t)
; if emacs-nox, use C-@, else, use C-2;
(if window-system
(progn
(define-key global-map (kbd "C-2") 'er/expand-region)
(define-key global-map (kbd "C-M-2") 'er/contract-region)
)
(progn
(define-key global-map (kbd "C-@") 'er/expand-region)
(define-key global-map (kbd "C-M-@") 'er/contract-region)
)
)
(define-key global-map (kbd "C-c SPC") 'ace-jump-mode)
;;move-text stuff, move line up/down by pressing hotkey
(global-set-key (kbd "M-p") 'move-text-up)
(global-set-key (kbd "M-n") 'move-text-down)
;; move window
(require 'window-numbering)
(window-numbering-mode 1)
(provide 'init-misc)