emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/go-mode 02d44df 067/495: add function for downloading play


From: ELPA Syncer
Subject: [nongnu] elpa/go-mode 02d44df 067/495: add function for downloading playgrounds into emacs
Date: Sat, 7 Aug 2021 09:04:45 -0400 (EDT)

branch: elpa/go-mode
commit 02d44dfccaa9fc0e2c963ce858f0efff17b7635b
Author: Dominik Honnef <dominikh@fork-bomb.org>
Commit: Dominik Honnef <dominikh@fork-bomb.org>

    add function for downloading playgrounds into emacs
---
 README.md  |  1 +
 go-mode.el | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/README.md b/README.md
index 1e98677..85906a6 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,7 @@ Features
 - Support for `C-M-e` (`end-of-defun`)
 - Support for `C-M-h` (`mark-defun`)
 - Two functions for sending code to the Playground (`go-play-buffer` and 
`go-play-region`)
+- A function for downloading code from the Playground into a Go buffer 
(`go-download-play`)
 - A function for adding imports, including tab completion (`go-import-add`, 
bound to `C-c C-a`)
 - A function for removing or commenting unused imports 
(`go-remove-unused-imports`)
 - A function for jumping to the file's imports (`go-goto-imports`)
diff --git a/go-mode.el b/go-mode.el
index a7874cc..8b3b2ce 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -14,6 +14,8 @@
   (require 'diff-mode)
   (require 'cl))
 
+(require 'ffap)
+
 (defconst go-dangling-operators-regexp "[^-]-\\|[^+]\\+\\|[/*&><.=|^]")
 (defconst gofmt-stdin-tag "<standard input>")
 (defconst go-identifier-regexp "[[:word:][:multibyte:]_]+")
@@ -524,6 +526,20 @@ link in the kill ring."
                            (kill-new (format "http://play.golang.org/p/%s"; 
(buffer-substring (point) (point-max))))
                            (message "http://play.golang.org/p/%s"; 
(buffer-substring (point) (point-max)))))))))))
 
+;;;###autoload
+(defun go-download-play (url)
+  "Downloads a paste from the playground and inserts it in a Go
+buffer. Tries to look for a URL at point."
+  (interactive (list (read-from-minibuffer "Playground URL: " (ffap-url-p 
(ffap-string-at-point 'url)))))
+  (with-current-buffer (url-retrieve-synchronously (concat url ".go"))
+    (let ((buffer (generate-new-buffer (concat (car (reverse (split-string url 
"/"))) ".go"))))
+      (goto-char (point-min))
+      (re-search-forward "\n\n")
+      (copy-to-buffer buffer (point) (point-max))
+      (kill-buffer)
+      (with-current-buffer buffer
+        (go-mode)
+        (switch-to-buffer buffer)))))
 
 ;; "However, it should not call syntax-ppss-flush-cache; so, it is not allowed 
to call syntax-ppss on some position and later modify the buffer at an earlier 
position."
 ;; ↑ let's hope this doesn't screw me over



reply via email to

[Prev in Thread] Current Thread [Next in Thread]