Emacs with Golang with Flymake with Goscript .emacs settings

來源:互聯網
上載者:User

It's kinda late. So I make it quick: How to setup an emacs with syntax check when you write golang script.

 

In linux of course.

 

(require 'go-mode-load)<br />(require 'flymake)<br />(autoload 'flymake-find-file-hook "flymake" "" t)<br />(add-hook 'find-file-hook 'flymake-find-file-hook)<br />(setq flymake-gui-warnings-enabled nil)<br />(setq flymake-log-level 0)<br />(defun flymake-golang-init ()<br /> (defadvice flymake-save-buffer-in-file ;;;;fix for my goscript usage<br /> (around flymake-save-buffer-in-file-golang-fix<br /> (file-name)<br /> activate)<br /> (make-directory (file-name-directory file-name) 1)<br /> (save-excursion<br /> (goto-char 0)<br /> (when (looking-at "^#!/.*goscript.*")<br /> (progn (forward-line 1) (forward-char -1)))<br /> (write-region (point) (point-max) file-name nil 566))<br /> (flymake-log 3 "saved buffer %s in file %s" (buffer-name) file-name))<br /> (let* ((temp-file (flymake-init-create-temp-buffer-copy<br /> 'flymake-create-temp-inplace))<br /> (local-file (file-relative-name<br /> temp-file<br /> (file-name-directory buffer-file-name))))<br /> ;; edit this if you use `8g'/`6g' other than my `cg'<br /> ;; #!/bin/bash<br /> ;; 6g $*<br /> ;; exit 0<br /> (list "cg" (list "-o /dev/null" local-file))))<br />(setq flymake-allowed-file-name-masks<br /> (cons '(".+//.go$"<br /> flymake-golang-init<br /> flymake-simple-cleanup<br /> flymake-get-real-file-name)<br /> flymake-allowed-file-name-masks))<br />(defun flymake-display-current-error ()<br /> "Display errors/warnings under cursor."<br /> (interactive)<br /> (let ((ovs (overlays-in (point) (1+ (point)))))<br /> (catch 'found<br /> (dolist (ov ovs)<br /> (when (flymake-overlay-p ov)<br /> (message (overlay-get ov 'help-echo))<br /> (throw 'found t))))))<br />(global-set-key (kbd "C-c f") 'flymake-display-current-error)<br />(global-set-key (kbd "C-c m") 'flymake-mode)<br />

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.