6
1.1.md
6
1.1.md
@@ -126,9 +126,9 @@ homebrew是Mac系统下面目前使用最多的管理软件的工具,目前已
|
|||||||
|
|
||||||
|
|
||||||
## links
|
## links
|
||||||
* [目录](<preface.md>)
|
* [目录](<preface.md>)
|
||||||
* 上一节: [Go环境配置](<1.md>)
|
* 上一节: [Go环境配置](<1.md>)
|
||||||
* 下一节: [GOPATH 与工作空间](<1.2.md>)
|
* 下一节: [GOPATH 与工作空间](<1.2.md>)
|
||||||
|
|
||||||
[downlink]: http://code.google.com/p/go/downloads/list "Go安装包下载"
|
[downlink]: http://code.google.com/p/go/downloads/list "Go安装包下载"
|
||||||
[hg]: http://mercurial.selenic.com/downloads/ "Mercurial下载"
|
[hg]: http://mercurial.selenic.com/downloads/ "Mercurial下载"
|
||||||
|
|||||||
162
1.4.md
162
1.4.md
@@ -154,90 +154,90 @@ Emacs传说中的神器,她不仅仅是一个编辑器,它是一个整合环
|
|||||||
|
|
||||||
5. 配置.emacs
|
5. 配置.emacs
|
||||||
|
|
||||||
;; golang mode
|
;; golang mode
|
||||||
(require 'go-mode-load)
|
(require 'go-mode-load)
|
||||||
(require 'go-autocomplete)
|
(require 'go-autocomplete)
|
||||||
;; speedbar
|
;; speedbar
|
||||||
;; (speedbar 1)
|
;; (speedbar 1)
|
||||||
(speedbar-add-supported-extension ".go")
|
(speedbar-add-supported-extension ".go")
|
||||||
(add-hook
|
(add-hook
|
||||||
'go-mode-hook
|
'go-mode-hook
|
||||||
'(lambda ()
|
'(lambda ()
|
||||||
;; gocode
|
;; gocode
|
||||||
(auto-complete-mode 1)
|
(auto-complete-mode 1)
|
||||||
(setq ac-sources '(ac-source-go))
|
(setq ac-sources '(ac-source-go))
|
||||||
;; Imenu & Speedbar
|
;; Imenu & Speedbar
|
||||||
(setq imenu-generic-expression
|
(setq imenu-generic-expression
|
||||||
'(("type" "^type *\\([^ \t\n\r\f]*\\)" 1)
|
'(("type" "^type *\\([^ \t\n\r\f]*\\)" 1)
|
||||||
("func" "^func *\\(.*\\) {" 1)))
|
("func" "^func *\\(.*\\) {" 1)))
|
||||||
(imenu-add-to-menubar "Index")
|
(imenu-add-to-menubar "Index")
|
||||||
;; Outline mode
|
;; Outline mode
|
||||||
(make-local-variable 'outline-regexp)
|
(make-local-variable 'outline-regexp)
|
||||||
(setq outline-regexp "//\\.\\|//[^\r\n\f][^\r\n\f]\\|pack\\|func\\|impo\\|cons\\|var.\\|type\\|\t\t*....")
|
(setq outline-regexp "//\\.\\|//[^\r\n\f][^\r\n\f]\\|pack\\|func\\|impo\\|cons\\|var.\\|type\\|\t\t*....")
|
||||||
(outline-minor-mode 1)
|
(outline-minor-mode 1)
|
||||||
(local-set-key "\M-a" 'outline-previous-visible-heading)
|
(local-set-key "\M-a" 'outline-previous-visible-heading)
|
||||||
(local-set-key "\M-e" 'outline-next-visible-heading)
|
(local-set-key "\M-e" 'outline-next-visible-heading)
|
||||||
;; Menu bar
|
;; Menu bar
|
||||||
(require 'easymenu)
|
(require 'easymenu)
|
||||||
(defconst go-hooked-menu
|
(defconst go-hooked-menu
|
||||||
'("Go tools"
|
'("Go tools"
|
||||||
["Go run buffer" go t]
|
["Go run buffer" go t]
|
||||||
["Go reformat buffer" go-fmt-buffer t]
|
["Go reformat buffer" go-fmt-buffer t]
|
||||||
["Go check buffer" go-fix-buffer t]))
|
["Go check buffer" go-fix-buffer t]))
|
||||||
(easy-menu-define
|
(easy-menu-define
|
||||||
go-added-menu
|
go-added-menu
|
||||||
(current-local-map)
|
(current-local-map)
|
||||||
"Go tools"
|
"Go tools"
|
||||||
go-hooked-menu)
|
go-hooked-menu)
|
||||||
|
|
||||||
;; Other
|
;; Other
|
||||||
(setq show-trailing-whitespace t)
|
(setq show-trailing-whitespace t)
|
||||||
))
|
))
|
||||||
;; helper function
|
;; helper function
|
||||||
(defun go ()
|
(defun go ()
|
||||||
"run current buffer"
|
"run current buffer"
|
||||||
(interactive)
|
(interactive)
|
||||||
(compile (concat "go run " (buffer-file-name))))
|
(compile (concat "go run " (buffer-file-name))))
|
||||||
|
|
||||||
;; helper function
|
;; helper function
|
||||||
(defun go-fmt-buffer ()
|
(defun go-fmt-buffer ()
|
||||||
"run gofmt on current buffer"
|
"run gofmt on current buffer"
|
||||||
(interactive)
|
(interactive)
|
||||||
(if buffer-read-only
|
(if buffer-read-only
|
||||||
(progn
|
(progn
|
||||||
(ding)
|
(ding)
|
||||||
(message "Buffer is read only"))
|
(message "Buffer is read only"))
|
||||||
(let ((p (line-number-at-pos))
|
(let ((p (line-number-at-pos))
|
||||||
(filename (buffer-file-name))
|
(filename (buffer-file-name))
|
||||||
(old-max-mini-window-height max-mini-window-height))
|
(old-max-mini-window-height max-mini-window-height))
|
||||||
|
(show-all)
|
||||||
|
(if (get-buffer "*Go Reformat Errors*")
|
||||||
|
(progn
|
||||||
|
(delete-windows-on "*Go Reformat Errors*")
|
||||||
|
(kill-buffer "*Go Reformat Errors*")))
|
||||||
|
(setq max-mini-window-height 1)
|
||||||
|
(if (= 0 (shell-command-on-region (point-min) (point-max) "gofmt" "*Go Reformat Output*" nil "*Go Reformat Errors*" t))
|
||||||
|
(progn
|
||||||
|
(erase-buffer)
|
||||||
|
(insert-buffer-substring "*Go Reformat Output*")
|
||||||
|
(goto-char (point-min))
|
||||||
|
(forward-line (1- p)))
|
||||||
|
(with-current-buffer "*Go Reformat Errors*"
|
||||||
|
(progn
|
||||||
|
(goto-char (point-min))
|
||||||
|
(while (re-search-forward "<standard input>" nil t)
|
||||||
|
(replace-match filename))
|
||||||
|
(goto-char (point-min))
|
||||||
|
(compilation-mode))))
|
||||||
|
(setq max-mini-window-height old-max-mini-window-height)
|
||||||
|
(delete-windows-on "*Go Reformat Output*")
|
||||||
|
(kill-buffer "*Go Reformat Output*"))))
|
||||||
|
;; helper function
|
||||||
|
(defun go-fix-buffer ()
|
||||||
|
"run gofix on current buffer"
|
||||||
|
(interactive)
|
||||||
(show-all)
|
(show-all)
|
||||||
(if (get-buffer "*Go Reformat Errors*")
|
(shell-command-on-region (point-min) (point-max) "go tool fix -diff"))
|
||||||
(progn
|
|
||||||
(delete-windows-on "*Go Reformat Errors*")
|
|
||||||
(kill-buffer "*Go Reformat Errors*")))
|
|
||||||
(setq max-mini-window-height 1)
|
|
||||||
(if (= 0 (shell-command-on-region (point-min) (point-max) "gofmt" "*Go Reformat Output*" nil "*Go Reformat Errors*" t))
|
|
||||||
(progn
|
|
||||||
(erase-buffer)
|
|
||||||
(insert-buffer-substring "*Go Reformat Output*")
|
|
||||||
(goto-char (point-min))
|
|
||||||
(forward-line (1- p)))
|
|
||||||
(with-current-buffer "*Go Reformat Errors*"
|
|
||||||
(progn
|
|
||||||
(goto-char (point-min))
|
|
||||||
(while (re-search-forward "<standard input>" nil t)
|
|
||||||
(replace-match filename))
|
|
||||||
(goto-char (point-min))
|
|
||||||
(compilation-mode))))
|
|
||||||
(setq max-mini-window-height old-max-mini-window-height)
|
|
||||||
(delete-windows-on "*Go Reformat Output*")
|
|
||||||
(kill-buffer "*Go Reformat Output*"))))
|
|
||||||
;; helper function
|
|
||||||
(defun go-fix-buffer ()
|
|
||||||
"run gofix on current buffer"
|
|
||||||
(interactive)
|
|
||||||
(show-all)
|
|
||||||
(shell-command-on-region (point-min) (point-max) "go tool fix -diff"))
|
|
||||||
|
|
||||||
6. 恭喜你,你现在可以体验在神器中开发Go的乐趣。默认speedbar是关闭的,如果打开需要把 ;; (speedbar 1) 前面的注释去掉,或者也可以通过 *M-x speedbar* 手动开启。
|
6. 恭喜你,你现在可以体验在神器中开发Go的乐趣。默认speedbar是关闭的,如果打开需要把 ;; (speedbar 1) 前面的注释去掉,或者也可以通过 *M-x speedbar* 手动开启。
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user