[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode 37f595f 365/495: cmd/guru: emacs: support running
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode 37f595f 365/495: cmd/guru: emacs: support running on nameless buffers |
Date: |
Sat, 7 Aug 2021 09:05:49 -0400 (EDT) |
branch: elpa/go-mode
commit 37f595f4d52744398ee3786cdf4e4173ac1f6150
Author: Dominik Honnef <dominik@honnef.co>
Commit: Dominik Honnef <dominik@honnef.co>
cmd/guru: emacs: support running on nameless buffers
By using guru's -modified flag and making up a file name, we can run
guru on a buffer that has no file attached to it. This feature will only
be useful for queries that operate on single files, as otherwise our made
up name could cause conflicts.
This will be useful for the "what" query and features using it.
Change-Id: I3d199bc0548245d59ba7b492f57beb9422d7f43d
Reviewed-on: https://go-review.googlesource.com/20431
Reviewed-by: Alan Donovan <adonovan@google.com>
---
guru_import/cmd/guru/go-guru.el | 45 +++++++++++++++++++++++++----------------
1 file changed, 28 insertions(+), 17 deletions(-)
diff --git a/guru_import/cmd/guru/go-guru.el b/guru_import/cmd/guru/go-guru.el
index a7f814b..ec4fa8e 100644
--- a/guru_import/cmd/guru/go-guru.el
+++ b/guru_import/cmd/guru/go-guru.el
@@ -121,16 +121,25 @@ result."
(with-current-buffer (go-guru--exec mode need-scope)
(go-guru--compilation-markup)))
-(defun go-guru--exec (mode &optional need-scope flags)
+(defun go-guru--exec (mode &optional need-scope flags allow-unnamed)
"Execute the Go guru in the specified MODE, passing it the
-selected region of the current buffer. If NEED-SCOPE, prompt for
-a scope if not already set. Return the output buffer."
- (if (not buffer-file-name)
- (error "Cannot use guru on a buffer without a file name"))
+selected region of the current buffer. If NEED-SCOPE, prompt for
+a scope if not already set. If ALLOW-UNNAMED is non-nil, a
+synthetic file for the unnamed buffer will be created. This
+should only be used with queries that work on single files
+only (e.g. 'what'). If ALLOW-UNNAMED is nil and the buffer has no
+associated name, an error will be signaled.
+
+Return the output buffer."
+ (or
+ buffer-file-name
+ allow-unnamed
+ (error "Cannot use guru on a buffer without a file name"))
(and need-scope
(string-equal "" go-guru-scope)
(go-guru-set-scope))
- (let* ((filename (file-truename buffer-file-name))
+ (let* ((is-unnamed (not buffer-file-name))
+ (filename (file-truename (or buffer-file-name "synthetic.go")))
(posn (if (use-region-p)
(format "%s:#%d,#%d"
filename
@@ -142,14 +151,17 @@ a scope if not already set. Return the output buffer."
(env-vars (go-root-and-paths))
(goroot-env (concat "GOROOT=" (car env-vars)))
(gopath-env (concat "GOPATH=" (mapconcat #'identity (cdr env-vars)
":")))
- (output-buffer (get-buffer-create "*go-guru*")))
+ (output-buffer (get-buffer-create "*go-guru*"))
+ (buf (current-buffer)))
(with-current-buffer output-buffer
(setq buffer-read-only nil)
(erase-buffer))
(with-current-buffer (get-buffer-create "*go-guru-input*")
(setq buffer-read-only nil)
(erase-buffer)
- (go-guru--insert-modified-files)
+ (if is-unnamed
+ (go-guru--insert-modified-file filename buf)
+ (go-guru--insert-modified-files))
(let* ((args (append (list "-modified"
"-scope" go-guru-scope
"-tags" go-guru-build-tags)
@@ -220,15 +232,14 @@ a scope if not already set. Return the output buffer."
"Insert the contents of each modified Go buffer into the
current buffer in the format specified by guru's -modified flag."
(mapc #'(lambda (b)
- (and (buffer-modified-p b)
- (buffer-file-name b)
- (string= (file-name-extension (buffer-file-name b)) "go")
- (progn
- (insert (format "%s\n%d\n"
- (buffer-file-name b)
- (go-guru--buffer-size-bytes b)))
- (insert-buffer-substring b))))
- (buffer-list)))
+ (and (buffer-modified-p b)
+ (string= (file-name-extension (buffer-file-name b)) "go")
+ (go-guru--insert-modified-file (buffer-file-name b) b)))
+ (buffer-list)))
+
+(defun go-guru--insert-modified-file (name buffer)
+ (insert (format "%s\n%d\n" name (go-guru--buffer-size-bytes buffer)))
+ (insert-buffer-substring buffer))
(defun go-guru--buffer-size-bytes (&optional buffer)
"Return the number of bytes in the current buffer.
- [nongnu] elpa/go-mode 218d8c5 346/495: cmd/oracle: emacs: look for oracle on $PATH and nowhere else, (continued)
- [nongnu] elpa/go-mode 218d8c5 346/495: cmd/oracle: emacs: look for oracle on $PATH and nowhere else, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode aa733d8 339/495: go.tools/oracle: turn emacs integration into minor-mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode cbf7274 343/495: x/tools/oracle: add whicherrs query mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 01dff21 358/495: cmd/guru: emacs: package.el compatibility changes, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode dc424ef 361/495: cmd/guru: emacs: add default key binding for whicherrs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 6bfbd41 371/495: cmd/guru: emacs: report most specific element in expand-region, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 9753f6a 342/495: go.tools: use golang.org/x/... import paths, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode aa9a40c 351/495: cmd/guru: in Emacs, change 'definition' to jump directly, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 95e7a6f 377/495: cmd/guru: emacs: Use cl-lib.el instead of cl.el, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 2e9ec69 376/495: cmd/guru: update Emacs installation documentation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 37f595f 365/495: cmd/guru: emacs: support running on nameless buffers,
ELPA Syncer <=
- [nongnu] elpa/go-mode 9d5f10a 366/495: cmd/guru: emacs: store output in separate buffer, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 6a92c3b 349/495: cmd/guru: clean ups to command-line interface, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode b2837e7 345/495: cmd/oracle: expect oracle binary beneath $GOBIN, $GOPATH/bin, or $GOROOT/bin, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode f1b8ed0 337/495: go.tools/cmd/oracle: use -pos=file:#start, #end syntax to indicate half-open [start, end) extent of byte offsets., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7580ac3 359/495: cmd/guru: emacs: allow passing tags to guru, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 90aac96 381/495: cmd/gorename: a precise, type-aware renaming tool for Go identifiers., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 34e7efe 356/495: cmd/guru: emacs: do not shrink results window, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 3da5817 383/495: refactor/rename: allow passing -force flag from Emacs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 3448304 340/495: go.tools/oracle: change -mode argument into subcommand., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 9d94107 328/495: Release version 1.4.0, ELPA Syncer, 2021/08/07