Skip to content

go-remove-unused-imports cannot operate on unsaved buffer #340

Closed
@admacro

Description

@admacro

Hi, I want to format and remove unnecessary imports when saving go buffers, so I wrote this little function to do it. However, I got an error saying "go-remove-unused-imports cannot operate on unsaved buffer".

(defun go-tidy-up ()
  (gofmt-before-save)
  (go-remove-unused-imports))
(add-hook 'before-save-hook 'go-tidy-up)

Error message

Calling gofmt: gofmt (-s -w /var/folders/z6/f1935z3x7wq9bwbfvfmnq5xw0000gn/T/gofmtwP3cch.go)
Applied gofmt
Error: (wrong-number-of-arguments #[(arg) "\212p\306\211���\307\303!\203����\303\310!\210\311\306\312\"\210\313 \203$�\314\315!\210\202Y�\316 \211�\306�\211�\203R�
@�\317!\210\320 \210��\203H�\321\322 \323 \"\210\202K�\324 \210
A\211�\204/�*\314\325�G\"\210	\205`�\303\326!,\207" [lines flymake-state cur-buffer flymake-mode import --dolist-tail-- nil boundp -1 save-some-buffers #[nil "�p\232\207" [cur-buffer] 2] buffer-modified-p message "Cannot operate on unsaved buffer" go-unused-imports-lines go--goto-line beginning-of-line comment-region line-beginning-position line-end-position go--delete-whole-line "Removed %d imports" 1 arg] 4 ("/Users/james/.emacs.d/elpa/go-mode-20200112.2140/go-mode.elc" . 61594) "P"] 0)

How can I make it work on unsaved buffers?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions