[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode 8144ae8 392/495: Merge commit '12ef34c'
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode 8144ae8 392/495: Merge commit '12ef34c' |
Date: |
Sat, 7 Aug 2021 09:05:54 -0400 (EDT) |
branch: elpa/go-mode
commit 8144ae8bcadf2af59d8073e44ee46142beefcace
Merge: 04a2946 12ef34c
Author: Dominik Honnef <dominik@honnef.co>
Commit: Dominik Honnef <dominik@honnef.co>
Merge commit '12ef34c'
---
AUTHORS | 1 +
go-rename.el | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 109 insertions(+)
diff --git a/AUTHORS b/AUTHORS
index c8e74d2..516a29e 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -19,6 +19,7 @@ Iwasaki Yudai <yudai.iwasaki@ntti3.com>
James Aguilar <jaguilar@google.com>
Jan Newmarch <jan.newmarch@gmail.com>
Jean-Marc Eurin <jmeurin@google.com>
+Jeff Hodges <jeff@somethingsimilar.com>
Juergen Hoetzel <juergen@archlinux.org>
Kevin Ballard <kevin@sb.org>
Konstantin Shaposhnikov <k.shaposhnikov@gmail.com>
diff --git a/go-rename.el b/go-rename.el
new file mode 100644
index 0000000..f12d363
--- /dev/null
+++ b/go-rename.el
@@ -0,0 +1,108 @@
+;;; go-rename.el --- Integration of the 'gorename' tool into Emacs.
+
+;; Copyright 2014 The Go Authors. All rights reserved.
+;; Use of this source code is governed by a BSD-style
+;; license that can be found in the LICENSE file.
+
+;; Version: 0.1
+;; Package-Requires: ((go-mode "1.3.1"))
+;; Keywords: tools
+
+;;; Commentary:
+
+;; To install:
+
+;; % go get golang.org/x/tools/cmd/gorename
+;; % go build golang.org/x/tools/cmd/gorename
+;; % mv gorename $HOME/bin/ # or elsewhere on $PATH
+
+;; The go-rename-command variable can be customized to specify an
+;; alternative location for the installed command.
+
+;;; Code:
+
+(require 'cl-lib)
+(require 'compile)
+(require 'go-mode)
+(require 'thingatpt)
+
+(defgroup go-rename nil
+ "Options specific to the Go rename."
+ :group 'go)
+
+(defcustom go-rename-command "gorename"
+ "The `gorename' command; by the default, $PATH is searched."
+ :type 'string
+ :group 'go-rename)
+
+;;;###autoload
+(defun go-rename (new-name &optional force)
+ "Rename the entity denoted by the identifier at point, using
+the `gorename' tool. With FORCE, call `gorename' with the
+`-force' flag."
+ (interactive (list (read-string "New name: " (thing-at-point 'symbol))
+ current-prefix-arg))
+ (if (not buffer-file-name)
+ (error "Cannot use go-rename on a buffer without a file name"))
+ ;; It's not sufficient to save the current buffer if modified,
+ ;; since if gofmt-before-save is on the before-save-hook,
+ ;; saving will disturb the selected region.
+ (if (buffer-modified-p)
+ (error "Please save the current buffer before invoking go-rename"))
+ ;; Prompt-save all other modified Go buffers, since they might get written.
+ (save-some-buffers nil #'(lambda ()
+ (and (buffer-file-name)
+ (string= (file-name-extension (buffer-file-name)) ".go"))))
+ (let* ((posflag (format "-offset=%s:#%d"
+ buffer-file-name
+ (1- (go--position-bytes (point)))))
+ (env-vars (go-root-and-paths))
+ (goroot-env (concat "GOROOT=" (car env-vars)))
+ (gopath-env (concat "GOPATH=" (mapconcat #'identity (cdr env-vars)
":")))
+ success)
+ (with-current-buffer (get-buffer-create "*go-rename*")
+ (setq buffer-read-only nil)
+ (erase-buffer)
+ (let ((args (append (list go-rename-command nil t nil posflag "-to"
new-name) (if force '("-force")))))
+ ;; Log the command to *Messages*, for debugging.
+ (message "Command: %s:" args)
+ (message "Running gorename...")
+ ;; Use dynamic binding to modify/restore the environment
+ (setq success (zerop (let ((process-environment (cl-list* goroot-env
gopath-env process-environment)))
+ (apply #'call-process args))))
+ (insert "\n")
+ (compilation-mode)
+ (setq compilation-error-screen-columns nil)
+
+ ;; On success, print the one-line result in the message bar,
+ ;; and hide the *go-rename* buffer.
+ (if success
+ (progn
+ (message "%s" (go--buffer-string-no-trailing-space))
+ (gofmt--kill-error-buffer (current-buffer)))
+ ;; failure
+ (let ((w (display-buffer (current-buffer))))
+ (message "gorename exited")
+ (set-window-point w (point-min)))))))
+
+ ;; Reload the modified files, saving line/col.
+ ;; (Don't restore the point since the text has changed.)
+ ;;
+ ;; TODO(adonovan): should we also do this for all other files
+ ;; that were updated (the tool can print them)?
+ (let ((line (line-number-at-pos))
+ (col (current-column)))
+ (revert-buffer t t t) ; safe, because we just saved it
+ (goto-char (point-min))
+ (forward-line (1- line))
+ (forward-char col)))
+
+
+(defun go--buffer-string-no-trailing-space ()
+ (replace-regexp-in-string "[\t\n ]*\\'"
+ ""
+ (buffer-substring (point-min) (point-max))))
+
+(provide 'go-rename)
+
+;;; go-rename.el ends here
- [nongnu] elpa/go-mode 1dc6fb5 357/495: cmd/guru: fix mode map, again, (continued)
- [nongnu] elpa/go-mode 1dc6fb5 357/495: cmd/guru: fix mode map, again, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode fac4a24 336/495: go.tools/importer: negate "cgo" build tag to avoid native code in "net"., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 5b5ac61 364/495: cmd/guru: emacs: highlight all instances of an identifier, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 4146860 373/495: cmd/guru: Emacs: run guru asynchronously using compilation-mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7077c4f 375/495: cmd/guru: fix quoting bug in Emacs binding, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 142eae4 374/495: cmd/guru: add menu to Emacs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode eb8cf16 386/495: refactor/rename: emacs: package.el compatibility changes, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode bfc4f9b 385/495: tools/refactor/rename: add provide to rename.el, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 0604054 388/495: cmd/gorename: emacs: do not auto shrink error window, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 1b85887 389/495: refactor/rename: require cl-lib, use cl- namespace, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 8144ae8 392/495: Merge commit '12ef34c',
ELPA Syncer <=
- [nongnu] elpa/go-mode 269eb01 398/495: Remove support for Emacs 23, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 5056b85 403/495: Use xref functions if available, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 3f02a16 406/495: Add go-guru-definition-other-window, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7eb5b3d 409/495: Delete go-mode-autoloads.el, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 2d1d33a 407/495: Fix off-by-one in point calculations, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7f87c32 416/495: Permit empty guru scope, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode be9186c 417/495: Support remote files in `gofmt', ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 287595a 420/495: Don't traverse symlinks when recursing directories, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode b990645 425/495: Fix call expr indenting after dangling operator., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode ac6dd8c 430/495: Fix go-remove-unused-imports, ELPA Syncer, 2021/08/07