New open-bug-report & open-vanilla-sandbox commands

This commit is contained in:
Henrik Lissner 2018-05-20 12:13:59 +02:00
parent 7b8917ed42
commit f80be3682b
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
4 changed files with 162 additions and 16 deletions

View file

@ -1,5 +1,14 @@
;;; core/autoload/debug.el -*- lexical-binding: t; -*-
(defun doom-template-exists-p (template)
"TODO"
(file-exists-p (expand-file-name "templates/" doom-core-dir)))
(defun doom-template-insert (template)
"TODO"
(let ((dir (expand-file-name "templates/" doom-core-dir)))
(insert-file-contents (expand-file-name template dir))))
;;;###autoload
(defun doom-info ()
"Returns diagnostic information about the current Emacs session in markdown,
@ -134,6 +143,123 @@ branch and commit."
"n/a")))
;;
;; Vanilla sandbox
;;
(defun doom--run-vanilla-sandbox ()
"TODO"
(interactive)
(when (equal (buffer-name) "*doom:vanilla-sandbox*")
(let ((file (make-temp-file "doom-eval-")))
(write-file file)
(require 'pp)
(require 'restart-emacs)
(restart-emacs--launch-other-emacs
(list "-Q"
"--eval"
(prin1-to-string
`(setq user-emacs-directory ,doom-emacs-dir
package--init-file-ensured t
package-user-dir ,package-user-dir
package-archives ',package-archives
debug-on-error t))
"-f" "package-initialize"
"-l" file
"--eval" (prin1-to-string `(delete-file ,file)))))))
;;;###autoload
(defun doom//open-vanilla-sandbox ()
"Open an Emacs Lisp buffer destinated to run in a blank Emacs session.
This vanilla sandbox is started with emacs -Q, and provides a testbed for
debugging code without Doom standing in the way, and without sacrificing
access to the installed packages."
(interactive)
(let ((buf (get-buffer-create "*doom:vanilla-sandbox*")))
(with-current-buffer buf
(emacs-lisp-mode)
(local-set-key (kbd "C-c C-c") #'doom--run-vanilla-sandbox)
(local-set-key (kbd "C-c C-k") #'kill-this-buffer)
(setq header-line-format "C-c C-c to run the session / C-c C-k to abort it")
(setq-local default-directory doom-emacs-dir)
(doom-template-insert "VANILLA_SANDBOX")
(goto-char (point-max)))
(pop-to-buffer buf)))
;;
;; Reporting bugs
;;
(defun doom--open-bug-report ()
"TODO"
(interactive)
(let ((url "https://github.com/hlissner/doom-emacs/issues/new?body="))
;; TODO Refactor me
(save-restriction
(widen)
(goto-char (point-min))
(re-search-forward "^-------------------------------------------------------------------\n" nil t)
(skip-chars-forward " \n\t")
(condition-case e
(progn
(save-excursion
(when (and (re-search-backward "\\+ [ ] " nil t)
(not (y-or-n-p "You haven't checked all the boxes. Continue anyway?")))
(error "Aborted submit")))
(narrow-to-region (point) (point-max))
(let ((text (buffer-string)))
;; `url-encode-url' doesn't encode ampersands
(setq text (replace-regexp-in-string "&" "%26" text))
(setq url (url-encode-url (concat url text)))
;; HACK: encode some characters according to HTML URL Encoding Reference
;; http://www.w3schools.com/tags/ref_urlencode.asp
(setq url (replace-regexp-in-string "#" "%23" url))
(setq url (replace-regexp-in-string ";" "%3B" url))
(browse-url url)))
(error (signal (car e) (car e)))))))
;;;###autoload
(defun doom//open-bug-report ()
"Open a markdown buffer destinated to populate the New Issue page on Doom
Emacs' issue tracker.
If called when a backtrace buffer is present, it and the output of `doom-info'
will be automatically appended to the result."
(interactive)
;; TODO Refactor me
(let ((backtrace
(when (get-buffer "*Backtrace*")
(with-current-buffer "*Backtrace*"
(string-trim
(buffer-substring-no-properties
(point-min)
(min (point-max) 1000))))))
(buf (get-buffer-create "*doom:vanilla-sandbox*")))
(with-current-buffer buf
(erase-buffer)
(condition-case _ (gfm-mode)
(error (text-mode)))
(doom-template-insert "SUBMIT_BUG_REPORT")
(goto-char (point-max))
(let ((pos (point)))
(save-excursion
(insert
"\n" (doom-info) "\n"
(if (and backtrace (not (string-empty-p backtrace)))
(format "\n<details>\n<summary>Backtrace</summary>\n\n```\n%s\n```\n</details>\n"
backtrace)
"")))
(local-set-key (kbd "C-c C-c") #'doom--open-bug-report)
(local-set-key (kbd "C-c C-k") #'kill-this-buffer)
(setq header-line-format "C-c C-c to submit / C-c C-k to close")
;;
(narrow-to-region (point-min) pos)
(goto-char (point-min)))
(pop-to-buffer buf))))
;;
;; Profiling
;;

29
core/templates/BUG_REPORT Normal file
View file

@ -0,0 +1,29 @@
Please read through the following before you submit your issue.
+ [ ] Running `make` (then restarting Emacs) did not fix my issue
+ [ ] If I have byte-compiled, I've tried recompiling with `make compile`
+ [ ] If I changed the version of Emacs installed, I've recompiled by plugins
with `make compile-elpa`
+ [ ] I ran `make doctor` and it produced no leads
+ [ ] My issue cannot be found [on the wiki](/docs/troubleshoot.org)
+ [ ] I filled out the four fields in the template below
-------------------------------------------------------------------
### Observed behavior
<!-- What happened -->
### Expected behavior
<!-- What *should* have happened -->
### Steps to reproduce
<!-- Tell us how to reproduce the issue in steps -->
### Extra details
<!-- Include backtraces & screenshots if possible -->
-------------------------------------------------------------------

View file

@ -0,0 +1,7 @@
;; Welcome to the vanilla sanbox!
;;
;; This is a test bed for Emacs Lisp to be run in a blank instance of Emacs
;; (free of Doom's clutches). This is equivalent to using emacs -Q with
;; package.el initialized and nothing else (so you have access to installed
;; plugins).

View file

@ -1,16 +0,0 @@
;;; debug.el -*- lexical-binding: t; -*-
;; To test something in a blank, vanilla Emacs session (Emacs -Q) load me:
;;
;; emacs -Q -l debug.el
(setq user-emacs-directory (file-name-directory load-file-name)
package--init-file-ensured t
package-user-dir (expand-file-name ".local/packages/elpa" user-emacs-directory)
package-archives
'(("gnu" . "https://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")
("org" . "https://orgmode.org/elpa/")))
(package-initialize)
;; Then you can test packages in isolation here...