Skip to content

Commit

Permalink
Adds in-emacs editing to spacemacs/report-issue
Browse files Browse the repository at this point in the history
spacemacs/report-issue opens a buffer prepopulated with a template and some
system information. The buffer is markdown-mode augmented with a keybinding to
send the contents to github.

Or if that doesn't work, the text remains in the buffer to be manually copied
and pasted. This makes the error reporting more robust: right after the user has
experienced one bug is the worst time to manifest another one.

This commit also rewrites spacemacs//describe-last-keys-string because I
couldn't figure out how else to prevent view-lossage from burying the new
REPORT_SPACEMACS_ISSUE buffer.  Suggestions welcome.
  • Loading branch information
dwang20151005 committed Apr 27, 2016
1 parent b21c717 commit b3c3302
Showing 1 changed file with 74 additions and 41 deletions.
115 changes: 74 additions & 41 deletions core/core-spacemacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,19 @@ defer call using `spacemacs-post-user-config-hook'."

(defun spacemacs//describe-last-keys-string ()
"Gathers info about your Emacs last keys and returns it as a string."
(view-lossage)
(let* ((lossage-buffer "*Help*")
(last-keys (format "#### Emacs last keys\n```text\n%s```\n"
(with-current-buffer lossage-buffer
(buffer-string)))))
(kill-buffer lossage-buffer)
last-keys))
(loop
for key
across (recent-keys)
collect (if (or (integerp key) (symbolp key) (listp key))
(single-key-description key)
(prin1-to-string key))
into keys
finally (return
(with-temp-buffer
(set-fill-column 60)
(insert (mapconcat 'identity keys " "))
(fill-region (point-min) (point-max))
(format "#### Emacs last keys\n```text\n%s\n```\n" (buffer-string))))))

(defun spacemacs/describe-last-keys ()
"Gathers info about your Emacs last keys and copies to clipboard."
Expand All @@ -249,42 +255,69 @@ defer call using `spacemacs-post-user-config-hook'."
"Check the *Messages* buffer if you need to review it"))))

(defun spacemacs/report-issue (arg)
"Browse the page for creating a new Spacemacs issue on GitHub,
with the message pre-filled with template and information.
"Open a spacemacs/report-issue-mode buffer prepopulated with
issue report template and system information.
With prefix arg also inlcude last pressed keys."
With prefix arg,include the last keys pressed."
(interactive "P")
(let* ((url "http://github.com/syl20bnr/spacemacs/issues/new?body=")
(template (with-temp-buffer
(insert-file-contents-literally
(concat configuration-layer-template-directory "REPORTING.template"))
(buffer-string))))
;; Include the system info description directly into the template
(setq template (replace-regexp-in-string
"%SYSTEM_INFO%"
(spacemacs//describe-system-info-string)
template [keep-case]))
;; Include the backtrace directly in the template, if it exists
(setq template (replace-regexp-in-string
"%BACKTRACE%"
(if (get-buffer "*Backtrace*")
(with-current-buffer "*Backtrace*"
(buffer-substring-no-properties
(point-min) (min (point-max) 1000)))
"BACKTRACE IF RELEVANT")
template [keep-case]))
;; Include the last keys description directly into the template, if
;; prefix argument has been passed
(setq template (replace-regexp-in-string
"(%LAST_KEYS%)\n"
(if (and arg (y-or-n-p (concat "Do you really want to "
"include your last pressed keys? It "
"may include some sensitive data.")))
(concat (spacemacs//describe-last-keys-string) "\n")
"")
template [keep-case]))
;; Create the encoded url
(setq url (url-encode-url (concat url template)))
(let ((buf
(generate-new-buffer "REPORT_SPACEMACS_ISSUE"))
(system-info
(spacemacs//describe-system-info-string))
(backtrace
(if (get-buffer "*Backtrace*")
(with-current-buffer "*Backtrace*"
(buffer-substring-no-properties
(point-min)
(min (point-max) 1000)))
"BACKTRACE IF RELEVANT"))
(last-keys
(if (and arg (y-or-n-p (concat "Do you really want to "
"include your last pressed keys? It "
"may include some sensitive data.")))
(concat (spacemacs//describe-last-keys-string) "\n")
"")))
(switch-to-buffer buf)
(insert-file-contents-literally
(concat configuration-layer-template-directory "REPORTING.template"))
(loop
for (placeholder replacement)
in '(("%SYSTEM_INFO%" system-info)
("%BACKTRACE%" backtrace)
("(%LAST_KEYS%)\n" last-keys))
do (save-excursion
(goto-char (point-min))
(search-forward placeholder)
(replace-match (symbol-value replacement) [keep-case] [literal])))
(spacemacs/report-issue-mode)))

(define-derived-mode spacemacs/report-issue-mode markdown-mode "Report-Issue"
"Major mode for reporting issues with Spacemacs.
When done editing, you can type \\[spacemacs//report-issue-done] to create the
issue on Github. You must be logged in already for this to work. After you see
that the issue has been created successfully, you can close this buffer.
Markdown syntax is supported in this buffer.
\\{spacemacs/report-issue-mode-map}
")

(define-key
spacemacs/report-issue-mode-map
(kbd "C-c C-c")
'spacemacs//report-issue-done)

(spacemacs/set-leader-keys-for-major-mode 'spacemacs/report-issue-mode
"," 'spacemacs//report-issue-done
"c" 'spacemacs//report-issue-done
"a" 'kill-buffer
"k" 'kill-buffer)

(defun spacemacs//report-issue-done ()
(interactive)
(let ((url "http://github.com/syl20bnr/spacemacs/issues/new?body="))
(setq url (url-encode-url (concat url (buffer-string))))
;; HACK: Needed because the first `#' is not encoded
(setq url (replace-regexp-in-string "#" "%23" url))
(browse-url url)))
Expand Down

0 comments on commit b3c3302

Please sign in to comment.