From f80be3682b31270b1bad858292f6af2f1d693fbf Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 20 May 2018 12:13:59 +0200 Subject: [PATCH] New open-bug-report & open-vanilla-sandbox commands --- core/autoload/debug.el | 126 +++++++++++++++++++++++++++++++++ core/templates/BUG_REPORT | 29 ++++++++ core/templates/VANILLA_SANDBOX | 7 ++ debug.el | 16 ----- 4 files changed, 162 insertions(+), 16 deletions(-) create mode 100644 core/templates/BUG_REPORT create mode 100644 core/templates/VANILLA_SANDBOX delete mode 100644 debug.el diff --git a/core/autoload/debug.el b/core/autoload/debug.el index db5764ee4..03c944765 100644 --- a/core/autoload/debug.el +++ b/core/autoload/debug.el @@ -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
\nBacktrace\n\n```\n%s\n```\n
\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 ;; diff --git a/core/templates/BUG_REPORT b/core/templates/BUG_REPORT new file mode 100644 index 000000000..a46909cce --- /dev/null +++ b/core/templates/BUG_REPORT @@ -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 + + + +### Expected behavior + + + +### Steps to reproduce + + + +### Extra details + + + +------------------------------------------------------------------- diff --git a/core/templates/VANILLA_SANDBOX b/core/templates/VANILLA_SANDBOX new file mode 100644 index 000000000..201ad51d1 --- /dev/null +++ b/core/templates/VANILLA_SANDBOX @@ -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). + diff --git a/debug.el b/debug.el deleted file mode 100644 index 0aa3970a3..000000000 --- a/debug.el +++ /dev/null @@ -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...