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