簡體   English   中英

emacs自動完成go語言

[英]emacs auto complete for go language

我一直試圖結合公司模式gocode來在emacs中設置自動完成。 我已經關注了這個鏈接 但是結果不是gocode的github頁面中提到的結果。 菜單不會單獨出現,並且函數聲明不會顯示在迷你緩沖區中。

這是我的.emacs文件(最后是gocode和公司模式設置):

                                                     ;(invert-face 'default)   ;;weird with nw mode
                                                     ;(blink-cursor-mode 0)
(load-file "/home/sudeep/.emacs.d/shortcuts.el")
;; (defadvice ido-find-file (after find-file-sudo activate)
;;   "Find file as root if necessary."
;;   (unless (and buffer-file-name
;;                (file-writable-p buffer-file-name))
;;     (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
                                                     ;(setq debug-on-error t)

(setq custom-file "/home/sudeep/.emacs.d/custom.el")
(load custom-file 'noerror)

(iswitchb-mode 1)
                                                     ;disables scroll bar
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(menu-bar-mode -1)
(tool-bar-mode -1)


(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))    ;.h files are treated as c files instaed of c++ in emacs. Remove it!

;; -- laoding images in org mode
;; enable image mode first
(setq-default iimage-mode t)


;Splitted window switching with C-ESC

(global-set-key (kbd "<C-escape>") 'other-window)
;     

;hiding code(hiding the contents of a function)C-c @ C-h and C-c @ C-s


(add-hook 'c++-mode-common-hook #'hs-minor-mode)
(add-hook 'c-mode-common-hook #'hs-minor-mode)
(add-hook 'python-mode-common-hook #'hs-minor-mode)
(add-hook 'elisp-mode-common-hook #'hs-minor-mode)
(add-hook 'java-mode-common-hook #'hs-minor-mode)


(blink-cursor-mode -1)

;miscellaneous
(setq max-mini-window-height .70)
(which-function-mode)




(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8-unix)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)




;; (load-file "~/.emacs.d/tabbar.el")
;; (require 'cl)
;; (when (require 'tabbar nil t)
;;   (setq tabbar-buffer-groups-function
;;        (lambda (b) (list "All Buffers")))
;;   (setq tabbar-buffer-list-function
;;        (lambda ()
;;           (remove-if
;;            (lambda(buffer)
;;               (find (aref (buffer-name buffer) 0) " *"))
;;            (buffer-list))))
;;   (tabbar-mode))

;; (setq tabbar-buffer-groups-function
;;      (lambda ()
;;        (list "All")))
;; (require 'tabbar)
;; (tabbar-mode 1)
;; (global-set-key [(C-S-iso-lefttab)] 'tabbar-backward)
;; (global-set-key (kbd "C-<tab>") 'tabbar-forward)



                                                     ;bookmarks
(global-set-key (kbd "C-c C-z") 'bookmark-set)
(global-set-key (kbd "C-c C-j") 'bookmark-jump)
(global-set-key (kbd "C-c C-q") 'bookmark-delete)
;(global-set-key (kbd "C-!") 'gtags-pop-stack)

(defadvice bookmark-jump (after bookmark-jump activate)
  (let ((latest (bookmark-get-bookmark bookmark)))
    (setq bookmark-alist (delq latest bookmark-alist))
    (add-to-list 'bookmark-alist latest)))

(display-time-mode 1)

;highlighting  todo,fixme, bug

(add-hook 'prog-mode-common-hook
             (lambda ()
                (font-lock-add-keywords nil
                                                '(("\\<\\(FIXME\\|TODO\\|BUG\\):" 1 font-lock-warning-face t)))))


;; (load-file "/home/sudeep/.emacs.d/sr-speedbar.el")
;; (require 'sr-speedbar)
;; (make-face 'speedbar-face)
;; ;(set-face-font 'speedbar-face "8")
;; (setq speedbar-mode-hook '(lambda () (buffer-face-set 'speedbar-face)))


;; (speedbar-add-supported-extension ".c")
;; (speedbar-add-supported-extension ".c++")
;; (speedbar-add-supported-extension ".s")
;; (speedbar-add-supported-extension ".asm")
;; (speedbar-add-supported-extension ".java")
;; (speedbar-add-supported-extension ".py")

(setq c-default-style "linux"
        c-basic-offset 3)

                                                     ;indentation customization(replacing tabs by 4 spaces)
(setq-default c-basic-offset 3
                  tab-width 3
                  indent-tabs-mode t)


(defun dos2unix ()
  "Replace DOS eolns CR LF with Unix eolns CR"
  (interactive)
    (goto-char (point-min))
      (while (search-forward "\r" nil t) (replace-match "")))


;(set-face-attribute 'default nil :height 105)

(setq url-proxy-services
   '(("no_proxy" . "^\\(localhost\\|10.*\\)")
     ("http" . "10.3.100.207:8080")
     ("https" . "10.3.100.207:8080")
      ("ftp" . "10.3.100.207:8080")
      ("socks" . "10.3.100.207:8080")))



(require 'package)
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
                         ("marmalade" . "http://marmalade-repo.org/packages/")
                         ("melpa" . "http://melpa.milkbox.net/packages/")
                                 ("elpa" . "http://tromey.com/elpa/")))
(package-initialize)
(when (not package-archive-contents)
  (package-refresh-contents))
(add-to-list 'load-path "/home/sudeep/.emacs.d/")



(defun djcb-opacity-modify (&optional dec)
  "modify the transparency of the emacs frame; if DEC is t,
    decrease the transparency, otherwise increase it in 10%-steps"
  (let* ((alpha-or-nil (frame-parameter nil 'alpha)) ; nil before setting
          (oldalpha (if alpha-or-nil alpha-or-nil 100))
          (newalpha (if dec (- oldalpha 10) (+ oldalpha 10))))
    (when (and (>= newalpha frame-alpha-lower-limit) (<= newalpha 100))
      (modify-frame-parameters nil (list (cons 'alpha newalpha))))))

 ;; C-8 will increase opacity (== decrease transparency)
 ;; C-9 will decrease opacity (== increase transparency
 ;; C-0 will returns the state to normal
(global-set-key (kbd "C-8") '(lambda()(interactive)(djcb-opacity-modify)))
(global-set-key (kbd "C-9") '(lambda()(interactive)(djcb-opacity-modify t)))
(global-set-key (kbd "C-0") '(lambda()(interactive)
                               (modify-frame-parameters nil `((alpha . 10)))))



(setq large-file-warning-threshold 100000000)


;(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")
;(load-theme 'junio t)
;(load-theme 'zenburn t)

;(load-file "~/.emacs.d/arjen-theme.el")

                                                     ;(load-file "~/.emacs.d/sanityinc-tomorrow-night-theme.el")
                                                     ;(set-background-color "black")
                                                     ;(require 'color-theme-sanityinc-tomorrow)
                                                     ;(load-theme 'color-theme-sanityinc-tomorrow-black t)
                                                     ;(load-theme 'sanityinc-solarized-dark)


(defun electric-pair ()
  "If at end of line, insert character pair without surrounding spaces.
   Otherwise, just insert the typed character."
  (interactive)
  (if (eolp) (let (parens-require-spaces) (insert-pair)) 
    (self-insert-command 1)))

(add-hook 'js-mode-hook
             (lambda ()
                (define-key js-mode-map "(" 'electric-pair)
                (define-key js-mode-map "[" 'electric-pair)
                (define-key js-mode-map "{" 'electric-pair)))



;;js2-mode setup
                                                     ;(semantic-mode)
                                                     ;(require 'icicles)
                                                     ;(icy-mode t)


;; (add-to-list 'load-path "/home/sudeep/.emacs.d/elpa/auto-complete-20160107.8/")  ; Load the default configuration
;; (require 'auto-complete-config)   ; Make sure we can find the dictionaries
;; (add-to-list 'ac-dictionary-directories "/home/sudeep/.emacs.d/elpa/auto-complete-20160107.8/dict")          ; Usedictionaries by default
;; (setq-default ac-sources (add-to-list 'ac-sources 'ac-source-dictionary))
;; (global-auto-complete-mode t)
;;                                                   ; Start auto-completion after 2 characters of a word
;; (setq ac-auto-start 2)
;;                                                   ; case sensitivity is important when finding matches
;; (setq ac-ignore-case nil)

;;                                                   ;(autoload 'js2-mode "js2" nil t) 

;; (ac-config-default)

;; (set-default 'ac-sources
;;               '(ac-source-abbrev
;;                  ac-source-dictionary
;;                  ac-source-yasnippet
;;                  ac-source-words-in-buffer
;;                  ac-source-words-in-same-mode-buffers
;;                  ac-source-semantic))

;; (dolist (m '(c-mode c++-mode java-mode go-mode))
;;   (add-to-list 'ac-modes m))

;; (global-auto-complete-mode t)
;; ;;yasnippet
;; (add-to-list 'load-path
;;               "~/.emacs.d/plugins/yasnippet")
;; (require 'yasnippet)
;;                                                   ;(yas-global-mode 1)

(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))

(js2-imenu-extras-mode)


;; yes or no becomes y or n
(defalias 'yes-or-no-p 'y-or-n-p)

;; ;;yasnippet
;; (yas-global-mode 1)

;; ;; auto-complete
;; (require 'auto-complete-config)
;; (add-to-list 'ac-dictionary-directories "~/.emacs.d/elpa/auto-complete/dict")

;; (set-default 'ac-sources
;;              '(ac-source-abbrev
;;                ac-source-dictionary
;;                ac-source-yasnippet
;;                ac-source-words-in-buffer
;;                ac-source-words-in-same-mode-buffers
;;                ac-source-semantic))

;; (ac-config-default)

;; (dolist (m '(c-mode c++-mode java-mode emacs-lisp-mode))
;;   (add-to-list 'ac-modes m))

;; (global-auto-complete-mode t)





(global-aggressive-indent-mode 1)
(add-to-list 'aggressive-indent-excluded-modes 'html-mode)
(ido-mode 1)


;;go-mode
                                                     ;(require 'go-autocomplete)


(require 'company)                                   ; load company mode
                                                     ;(require 'company-go)                                                  ; load company mode go backend
(add-hook 'go-mode-hook (lambda ()
                                  (set (make-local-variable 'company-backends) '(company-go))
                                  (company-mode)))
(setq company-tooltip-limit 20)                      ; bigger popup window
(setq company-idle-delay .1)                         ; decrease delay before autocompletion popup shows
(setq company-echo-delay 0)                          ; remove annoying blinking
(setq company-begin-commands '(self-insert-command)) ; start autocompletion only after typing

(global-company-mode)

;; (eval-after-load "go-mode"
;;   '(progn
;;      (flycheck-declare-checker go-gofmt
;;                                       "A Go syntax and style checker using the gofmt utility."
;;                                       :command '("gofmt" source-inplace)
;;                                       :error-patterns '(("^\\(?1:.*\\):\\(?2:[0-9]+\\):\\(?3:[0-9]+\\): \\(?4:.*\\)$" error))
;;                                       :modes 'go-mode)
;;      (add-to-list 'flycheck-checkers 'go-gofmt)))
                                                     ;(ac-go-expand-arguments-into-snippets)
                                                     ;(add-hook 'go-mode-hook 'flycheck-mode)

請幫助我了解並修復丟失的內容。

這是我輸入一些字母后執行company-complete的調試消息:

Debugger entered--Lisp error: (error "GOCODE PANIC: Please check your code by \"go build\"")
  signal(error ("GOCODE PANIC: Please check your code by \"go build\""))
  error("GOCODE PANIC: Please check your code by \"go build\"")
  company-go--candidates()
  company-go(candidates #("Clien" 0 5 (fontified t)))
  apply(company-go (candidates #("Clien" 0 5 (fontified t))))
  #[0 "\302 !\203\303   \300\"\207\303\304  \300#\207" [(candidates #("Clien" 0 5 (fontified t))) company-backend functionp apply company--multi-backend-adapter] 4 "\n\n(fn)"]()
  company-call-backend-raw(candidates #("Clien" 0 5 (fontified t)))
  apply(company-call-backend-raw (candidates #("Clien" 0 5 (fontified t))))
  company--force-sync(company-call-backend-raw (candidates #("Clien" 0 5 (fontified t))) company-go)
  company-call-backend(candidates #("Clien" 0 5 (fontified t)))
  company--fetch-candidates(#("Clien" 0 5 (fontified t)))
  company-calculate-candidates(#("Clien" 0 5 (fontified t)))
  #[0 "\n\203   \nC\202\n\211\205\233\211@\3009\204\306!\203<9\2036\307N\310=\2046\307N?\205@\311!\205@\312!\202@\313\312\"\240\210\300@\203\224\314\300@!\203\216\315\300@!\211\301\316\f!\240\210\301@:\204w
\203i\317\320!\210\301@\310=\203\216\321\322!\210\202\216
\203\300@\323\301@!\210\324\325\326 \"\210\327\330!\210\331\332\301@\"\210A\266\202\202\n\207" [((#("Clien" 0 5 (fontified t)) . t)) (nil) company-backend company-backends company-prefix company--manual-action functionp company-init t company-init-backend prefix company--multi-backend-adapter company--good-prefix-p company--prefix-str company-calculate-candidates message "No completion found" company-cancel unique company-update-candidates run-hook-with-args company-completion-started-hook company-explicit-action-p company-call-frontends show throw --cl-block-nil-- company--manual-prefix] 6 "\n\n(fn)"]()
  funcall(#[0 "\n\203   \nC\202\n\211\205\233\211@\3009\204\306!\203<9\2036\307N\310=\2046\307N?\205@\311!\205@\312!\202@\313\312\"\240\210\300@\203\224\314\300@!\203\216\315\300@!\211\301\316\f!\240\210\301@:\204w
\203i\317\320!\210\301@\310=\203\216\321\322!\210\202\216
\203\300@\323\301@!\210\324\325\326 \"\210\327\330!\210\331\332\301@\"\210A\266\202\202\n\207" [((#("Clien" 0 5 (fontified t)) . t)) (nil) company-backend company-backends company-prefix company--manual-action functionp company-init t company-init-backend prefix company--multi-backend-adapter company--good-prefix-p company--prefix-str company-calculate-candidates message "No completion found" company-cancel unique company-update-candidates run-hook-with-args company-completion-started-hook company-explicit-action-p company-call-frontends show throw --cl-block-nil-- company--manual-prefix] 6 "\n\n(fn)"])
  company--begin-new()
  company--perform()
  #[0 "\301 \210\207" [company-candidates company--perform] 1 "\n\n(fn)"]()
  company-auto-begin()
  company-manual-begin()
  company-complete()
  call-interactively(company-complete record nil)
  command-execute(company-complete record)
  execute-extended-command(nil "company-complete")
  call-interactively(execute-extended-command nil nil)

編輯在開始時添加(require 'cl)解決了該問題。

您只需要company包裝。 不需要company-go 以下配置適用於我:

  ;; enable company mode for autocompletion
  (add-hook 'go-mode-hook (lambda ()
                            (set (make-local-variable 'company-backends) '(company-go))
                            (company-mode)))

強烈推薦Flycheck(開箱即用,即可使用支持):

  ;; enable flycheck
  (add-hook 'go-mode-hook 'flycheck-mode)

開始添加(require 'cl)解決了該問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM