[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode 21cba0e 220/495: add gofmt-show-errors option
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode 21cba0e 220/495: add gofmt-show-errors option |
Date: |
Sat, 7 Aug 2021 09:05:18 -0400 (EDT) |
branch: elpa/go-mode
commit 21cba0ef083a05a8650a5f1ceef7b70fa8bfbeba
Author: Dominik Honnef <dominikh@fork-bomb.org>
Commit: Dominik Honnef <dominikh@fork-bomb.org>
add gofmt-show-errors option
gofmt-show-errors determines where to output gofmt error output: in a
buffer, in the echo area, or not at all.
---
go-mode.el | 58 ++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 38 insertions(+), 20 deletions(-)
diff --git a/go-mode.el b/go-mode.el
index 23dd9ca..2572b20 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -191,6 +191,20 @@ from https://github.com/bradfitz/goimports."
:type 'string
:group 'go)
+
+(defcustom gofmt-show-errors 'buffer
+ "Where to display gofmt error output. It can either be
+displayed in its own buffer, in the echo area, or not at all.
+
+Please note that Emacs outputs to the echo area when writing
+files and will overwrite gofmt's echo output if used from inside
+a before-save-hook."
+ :type '(choice
+ (const :tag "Own buffer" buffer)
+ (const :tag "Echo area" echo)
+ (const :tag "None" nil))
+ :group 'go)
+
(defcustom go-other-file-alist
'(("_test\\.go\\'" (".go"))
("\\.go\\'" ("_test.go")))
@@ -907,15 +921,16 @@ buffer."
(interactive)
(let ((tmpfile (make-temp-file "gofmt" nil ".go"))
(patchbuf (get-buffer-create "*Gofmt patch*"))
- (errbuf (get-buffer-create "*Gofmt Errors*"))
+ (errbuf (if gofmt-show-errors (get-buffer-create "*Gofmt Errors*")))
(coding-system-for-read 'utf-8)
(coding-system-for-write 'utf-8))
(save-restriction
(widen)
- (with-current-buffer errbuf
- (setq buffer-read-only nil)
- (erase-buffer))
+ (if errbuf
+ (with-current-buffer errbuf
+ (setq buffer-read-only nil)
+ (erase-buffer)))
(with-current-buffer patchbuf
(erase-buffer))
@@ -925,29 +940,32 @@ buffer."
;; is not an issue because gofmt -w does not produce any stdout
;; output in case of success.
(if (zerop (call-process gofmt-command nil errbuf nil "-w" tmpfile))
- (if (zerop (call-process-region (point-min) (point-max) "diff" nil
patchbuf nil "-n" "-" tmpfile))
- (progn
- (kill-buffer errbuf)
- (message "Buffer is already gofmted"))
- (go--apply-rcs-patch patchbuf)
- (kill-buffer errbuf)
- (message "Applied gofmt"))
- (message "Could not apply gofmt. Check errors for details")
- (gofmt--process-errors (buffer-file-name) tmpfile errbuf))
+ (progn
+ (if (zerop (call-process-region (point-min) (point-max) "diff" nil
patchbuf nil "-n" "-" tmpfile))
+ (message "Buffer is already gofmted")
+ (go--apply-rcs-patch patchbuf)
+ (message "Applied gofmt"))
+ (if errbuf (kill-buffer errbuf)))
+ (message "Could not apply gofmt")
+ (if errbuf (gofmt--process-errors (buffer-file-name) tmpfile errbuf)))
(kill-buffer patchbuf)
(delete-file tmpfile))))
(defun gofmt--process-errors (filename tmpfile errbuf)
- ;; Convert the gofmt stderr to something understood by the compilation mode.
(with-current-buffer errbuf
- (goto-char (point-min))
- (insert "gofmt errors:\n")
- (while (search-forward-regexp (concat "^\\(" (regexp-quote tmpfile)
"\\):") nil t)
- (replace-match (file-name-nondirectory filename) t t nil 1))
- (compilation-mode)
- (display-buffer errbuf)))
+ (if (eq gofmt-show-errors 'echo)
+ (progn
+ (message "%s" (buffer-string))
+ (kill-buffer errbuf))
+ ;; Convert the gofmt stderr to something understood by the compilation
mode.
+ (goto-char (point-min))
+ (insert "gofmt errors:\n")
+ (while (search-forward-regexp (concat "^\\(" (regexp-quote tmpfile)
"\\):") nil t)
+ (replace-match (file-name-nondirectory filename) t t nil 1))
+ (compilation-mode)
+ (display-buffer errbuf))))
;;;###autoload
(defun gofmt-before-save ()
- [nongnu] elpa/go-mode f664cff 197/495: correctly fontify methods when go-fontify-function-calls is nil, (continued)
- [nongnu] elpa/go-mode f664cff 197/495: correctly fontify methods when go-fontify-function-calls is nil, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 10281b7 202/495: add godoc-at-point, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 6ed8eec 206/495: style adjustments as per CL 106010043, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 0e030ef 207/495: style adjustment, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode b626ee9 213/495: readd link to gocode in README, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 541e559 212/495: when parsing GOPATH, split on the platform-specific path separator, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 40b55e3 211/495: improve README, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode e639832 208/495: add documentation for godoc-at-point, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7e22639 215/495: remove LEGAL, treat this repository as a mirror of misc/emacs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 903fb9e 216/495: Cancel narrowing before gofmt, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 21cba0e 220/495: add gofmt-show-errors option,
ELPA Syncer <=
- [nongnu] elpa/go-mode 731b93c 152/495: godef: instead of printing just the first line of a definition, print all, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 6e1d5ea 162/495: bump version, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 5a58bda 149/495: bump version, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode a55aa42 168/495: add pledgie to the readme, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 115b2eb 171/495: add go-coverage to readme, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode b0d4379 175/495: fix for eea3ccf, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 2089798 200/495: ignore backquote in comment or string, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 6b5fe38 204/495: write our own implementation of go--delete-whole-line, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 1319be5 210/495: simplify godoc-at-point, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 61aafe9 218/495: Allow spaces after "chan<-", ELPA Syncer, 2021/08/07