@@ -154,90 +154,90 @@ Emacs传说中的神器,她不仅仅是一个编辑器,它是一个整合环
154
154
155
155
5 . 配置.emacs
156
156
157
- ;; golang mode
158
- (require 'go-mode-load)
159
- (require 'go-autocomplete)
160
- ;; speedbar
161
- ;; (speedbar 1)
162
- (speedbar-add-supported-extension ".go")
163
- (add-hook
164
- 'go-mode-hook
165
- '(lambda ()
166
- ;; gocode
167
- (auto-complete-mode 1)
168
- (setq ac-sources '(ac-source-go))
169
- ;; Imenu & Speedbar
170
- (setq imenu-generic-expression
171
- '(("type" "^type *\\([^ \t\n\r\f]*\\)" 1)
172
- ("func" "^func *\\(.*\\) {" 1)))
173
- (imenu-add-to-menubar "Index")
174
- ;; Outline mode
175
- (make-local-variable 'outline-regexp)
176
- (setq outline-regexp "//\\.\\|//[^\r\n\f][^\r\n\f]\\|pack\\|func\\|impo\\|cons\\|var.\\|type\\|\t\t*....")
177
- (outline-minor-mode 1)
178
- (local-set-key "\M-a" 'outline-previous-visible-heading)
179
- (local-set-key "\M-e" 'outline-next-visible-heading)
180
- ;; Menu bar
181
- (require 'easymenu)
182
- (defconst go-hooked-menu
183
- '("Go tools"
184
- ["Go run buffer" go t]
185
- ["Go reformat buffer" go-fmt-buffer t]
186
- ["Go check buffer" go-fix-buffer t]))
187
- (easy-menu-define
188
- go-added-menu
189
- (current-local-map)
190
- "Go tools"
191
- go-hooked-menu)
192
-
193
- ;; Other
194
- (setq show-trailing-whitespace t)
195
- ))
196
- ;; helper function
197
- (defun go ()
198
- "run current buffer"
199
- (interactive)
200
- (compile (concat "go run " (buffer-file-name))))
201
-
202
- ;; helper function
203
- (defun go-fmt-buffer ()
204
- "run gofmt on current buffer"
205
- (interactive)
206
- (if buffer-read-only
207
- (progn
208
- (ding)
209
- (message "Buffer is read only"))
210
- (let ((p (line-number-at-pos))
211
- (filename (buffer-file-name))
212
- (old-max-mini-window-height max-mini-window-height))
157
+ ;; golang mode
158
+ (require 'go-mode-load)
159
+ (require 'go-autocomplete)
160
+ ;; speedbar
161
+ ;; (speedbar 1)
162
+ (speedbar-add-supported-extension ".go")
163
+ (add-hook
164
+ 'go-mode-hook
165
+ '(lambda ()
166
+ ;; gocode
167
+ (auto-complete-mode 1)
168
+ (setq ac-sources '(ac-source-go))
169
+ ;; Imenu & Speedbar
170
+ (setq imenu-generic-expression
171
+ '(("type" "^type *\\([^ \t\n\r\f]*\\)" 1)
172
+ ("func" "^func *\\(.*\\) {" 1)))
173
+ (imenu-add-to-menubar "Index")
174
+ ;; Outline mode
175
+ (make-local-variable 'outline-regexp)
176
+ (setq outline-regexp "//\\.\\|//[^\r\n\f][^\r\n\f]\\|pack\\|func\\|impo\\|cons\\|var.\\|type\\|\t\t*....")
177
+ (outline-minor-mode 1)
178
+ (local-set-key "\M-a" 'outline-previous-visible-heading)
179
+ (local-set-key "\M-e" 'outline-next-visible-heading)
180
+ ;; Menu bar
181
+ (require 'easymenu)
182
+ (defconst go-hooked-menu
183
+ '("Go tools"
184
+ ["Go run buffer" go t]
185
+ ["Go reformat buffer" go-fmt-buffer t]
186
+ ["Go check buffer" go-fix-buffer t]))
187
+ (easy-menu-define
188
+ go-added-menu
189
+ (current-local-map)
190
+ "Go tools"
191
+ go-hooked-menu)
192
+
193
+ ;; Other
194
+ (setq show-trailing-whitespace t)
195
+ ))
196
+ ;; helper function
197
+ (defun go ()
198
+ "run current buffer"
199
+ (interactive)
200
+ (compile (concat "go run " (buffer-file-name))))
201
+
202
+ ;; helper function
203
+ (defun go-fmt-buffer ()
204
+ "run gofmt on current buffer"
205
+ (interactive)
206
+ (if buffer-read-only
207
+ (progn
208
+ (ding)
209
+ (message "Buffer is read only"))
210
+ (let ((p (line-number-at-pos))
211
+ (filename (buffer-file-name))
212
+ (old-max-mini-window-height max-mini-window-height))
213
+ (show-all)
214
+ (if (get-buffer "*Go Reformat Errors*")
215
+ (progn
216
+ (delete-windows-on "*Go Reformat Errors*")
217
+ (kill-buffer "*Go Reformat Errors*")))
218
+ (setq max-mini-window-height 1)
219
+ (if (= 0 (shell-command-on-region (point-min) (point-max) "gofmt" "*Go Reformat Output*" nil "*Go Reformat Errors*" t))
220
+ (progn
221
+ (erase-buffer)
222
+ (insert-buffer-substring "*Go Reformat Output*")
223
+ (goto-char (point-min))
224
+ (forward-line (1- p)))
225
+ (with-current-buffer "*Go Reformat Errors*"
226
+ (progn
227
+ (goto-char (point-min))
228
+ (while (re-search-forward "<standard input>" nil t)
229
+ (replace-match filename))
230
+ (goto-char (point-min))
231
+ (compilation-mode))))
232
+ (setq max-mini-window-height old-max-mini-window-height)
233
+ (delete-windows-on "*Go Reformat Output*")
234
+ (kill-buffer "*Go Reformat Output*"))))
235
+ ;; helper function
236
+ (defun go-fix-buffer ()
237
+ "run gofix on current buffer"
238
+ (interactive)
213
239
(show-all)
214
- (if (get-buffer "*Go Reformat Errors*")
215
- (progn
216
- (delete-windows-on "*Go Reformat Errors*")
217
- (kill-buffer "*Go Reformat Errors*")))
218
- (setq max-mini-window-height 1)
219
- (if (= 0 (shell-command-on-region (point-min) (point-max) "gofmt" "*Go Reformat Output*" nil "*Go Reformat Errors*" t))
220
- (progn
221
- (erase-buffer)
222
- (insert-buffer-substring "*Go Reformat Output*")
223
- (goto-char (point-min))
224
- (forward-line (1- p)))
225
- (with-current-buffer "*Go Reformat Errors*"
226
- (progn
227
- (goto-char (point-min))
228
- (while (re-search-forward "<standard input>" nil t)
229
- (replace-match filename))
230
- (goto-char (point-min))
231
- (compilation-mode))))
232
- (setq max-mini-window-height old-max-mini-window-height)
233
- (delete-windows-on "*Go Reformat Output*")
234
- (kill-buffer "*Go Reformat Output*"))))
235
- ;; helper function
236
- (defun go-fix-buffer ()
237
- "run gofix on current buffer"
238
- (interactive)
239
- (show-all)
240
- (shell-command-on-region (point-min) (point-max) "go tool fix -diff"))
240
+ (shell-command-on-region (point-min) (point-max) "go tool fix -diff"))
241
241
242
242
6 . 恭喜你,你现在可以体验在神器中开发Go的乐趣。默认speedbar是关闭的,如果打开需要把 ;; (speedbar 1) 前面的注释去掉,或者也可以通过 * M-x speedbar* 手动开启。
243
243
0 commit comments