core: move some functions to their correct source file

This commit is contained in:
syl20bnr 2016-12-18 12:05:10 -05:00
parent 28f2a6079d
commit 467a5cc0ff
3 changed files with 164 additions and 158 deletions

View File

@ -9,6 +9,15 @@
;;
;;; License: GPLv3
(defun spacemacs/display-and-copy-version ()
"Echo the current spacemacs version and copy it."
(interactive)
(let ((msg (format "Spacemacs v.%s" spacemacs-version)))
(message msg) (kill-new msg)))
;; startup debug
(require 'profiler)
(defvar spacemacs-debug-timer-threshold 0.15
@ -140,4 +149,150 @@ seconds to load")
;; Keep debug-on-error on for stuff that is lazily loaded
(add-hook 'after-init-hook (lambda () (setq debug-on-error t))))
;; Report issue
(defun spacemacs//describe-system-info-string ()
"Gathers info about your Spacemacs setup and returns it as a string."
(format
(concat "#### System Info :computer:\n"
"- OS: %s\n"
"- Emacs: %s\n"
"- Spacemacs: %s\n"
"- Spacemacs branch: %s (rev. %s)\n"
"- Graphic display: %s\n"
"- Distribution: %s\n"
"- Editing style: %s\n"
"- Completion: %s\n"
"- Layers:\n```elisp\n%s```\n"
(when (version<= "25.1" emacs-version)
"- System configuration features: %s\n"))
system-type
emacs-version
spacemacs-version
(spacemacs//git-get-current-branch)
(spacemacs/git-get-current-branch-rev)
(display-graphic-p)
dotspacemacs-distribution
dotspacemacs-editing-style
(cond ((configuration-layer/layer-usedp 'helm)
'helm)
((configuration-layer/layer-usedp 'ivy)
'ivy)
(t 'helm))
(pp-to-string dotspacemacs--configuration-layers-saved)
(bound-and-true-p system-configuration-features)))
(defun spacemacs/describe-system-info ()
"Gathers info about your Spacemacs setup and copies to clipboard."
(interactive)
(let ((sysinfo (spacemacs//describe-system-info-string)))
(kill-new sysinfo)
(message sysinfo)
(message (concat "Information has been copied to clipboard.\n"
"You can paste it in the gitter chat.\n"
"Check the *Messages* buffer if you need to review it"))))
(defun spacemacs//describe-last-keys-string ()
"Gathers info about your Emacs last keys and returns it as a string."
(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 :musical_keyboard: \n```text\n%s\n```\n" (buffer-string))))))
(defun spacemacs/describe-last-keys ()
"Gathers info about your Emacs last keys and copies to clipboard."
(interactive)
(let ((lossage (spacemacs//describe-last-keys-string)))
(kill-new lossage)
(message lossage)
(message (concat "Information has been copied to clipboard.\n"
(propertize
"PLEASE REVIEW THE DATA BEFORE GOING FURTHER AS IT CAN CONTAIN SENSITIVE DATA (PASSWORD, ...)\n"
'face 'font-lock-warning-face)
"You can paste it in the gitter chat.\n"
"Check the *Messages* buffer if you need to review it"))))
(defun spacemacs/report-issue (arg)
"Open a spacemacs/report-issue-mode buffer prepopulated with
issue report template and system information.
With prefix arg,include the last keys pressed."
(interactive "P")
(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}
"
(font-lock-add-keywords 'spacemacs/report-issue-mode
'(("\\(<<.*?>>\\)" . 'font-lock-comment-face))))
(define-key spacemacs/report-issue-mode-map
(kbd "C-c C-c") 'spacemacs//report-issue-done)
(define-key spacemacs/report-issue-mode-map
(kbd "C-c C-k") 'kill-buffer)
(with-eval-after-load 'bind-map
(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: 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)))
(provide 'core-debug)

View File

@ -501,6 +501,14 @@ a display strng and the value is the actual value to return."
(cadr (assoc (ido-completing-read prompt (mapcar 'car candidates))
candidates))))
(defun dotspacemacs/maybe-install-dotfile ()
"Install the dotfile if it does not exist."
(unless (file-exists-p dotspacemacs-filepath)
(spacemacs-buffer/set-mode-line "Dotfile wizard installer")
(spacemacs//redisplay)
(when (dotspacemacs/install 'with-wizard)
(configuration-layer/sync))))
(defun dotspacemacs/install (arg)
"Install the dotfile, return non nil if the doftile has been installed.

View File

@ -154,7 +154,7 @@ the final step of executing code in `emacs-startup-hook'.")
(if dotspacemacs-mode-line-unicode-symbols
(setq-default spacemacs-version-check-lighter "[⇪]"))
;; install the dotfile if required
(spacemacs/maybe-install-dotfile))
(dotspacemacs/maybe-install-dotfile))
(defun spacemacs//removes-gui-elements ()
"Remove the menu bar, tool bar and scroll bars."
@ -170,20 +170,6 @@ the final step of executing code in `emacs-startup-hook'.")
(when (and (fboundp 'tooltip-mode) (not (eq tooltip-mode -1)))
(tooltip-mode -1)))
(defun spacemacs/maybe-install-dotfile ()
"Install the dotfile if it does not exist."
(unless (file-exists-p dotspacemacs-filepath)
(spacemacs-buffer/set-mode-line "Dotfile wizard installer")
(spacemacs//redisplay)
(when (dotspacemacs/install 'with-wizard)
(configuration-layer/sync))))
(defun spacemacs/display-and-copy-version ()
"Echo the current spacemacs version and copy it."
(interactive)
(let ((msg (format "Spacemacs v.%s" spacemacs-version)))
(message msg) (kill-new msg)))
(defun display-startup-echo-area-message ()
"Change the default welcome message of minibuffer to another one."
(message "Spacemacs is ready."))
@ -220,147 +206,4 @@ defer call using `spacemacs-post-user-config-hook'."
(spacemacs/check-for-new-version nil spacemacs-version-check-interval)
(setq spacemacs-initialized t))))
(defun spacemacs//describe-system-info-string ()
"Gathers info about your Spacemacs setup and returns it as a string."
(format
(concat "#### System Info :computer:\n"
"- OS: %s\n"
"- Emacs: %s\n"
"- Spacemacs: %s\n"
"- Spacemacs branch: %s (rev. %s)\n"
"- Graphic display: %s\n"
"- Distribution: %s\n"
"- Editing style: %s\n"
"- Completion: %s\n"
"- Layers:\n```elisp\n%s```\n"
(when (version<= "25.1" emacs-version)
"- System configuration features: %s\n"))
system-type
emacs-version
spacemacs-version
(spacemacs//git-get-current-branch)
(spacemacs/git-get-current-branch-rev)
(display-graphic-p)
dotspacemacs-distribution
dotspacemacs-editing-style
(cond ((configuration-layer/layer-usedp 'helm)
'helm)
((configuration-layer/layer-usedp 'ivy)
'ivy)
(t 'helm))
(pp-to-string dotspacemacs--configuration-layers-saved)
(bound-and-true-p system-configuration-features)))
(defun spacemacs/describe-system-info ()
"Gathers info about your Spacemacs setup and copies to clipboard."
(interactive)
(let ((sysinfo (spacemacs//describe-system-info-string)))
(kill-new sysinfo)
(message sysinfo)
(message (concat "Information has been copied to clipboard.\n"
"You can paste it in the gitter chat.\n"
"Check the *Messages* buffer if you need to review it"))))
(defun spacemacs//describe-last-keys-string ()
"Gathers info about your Emacs last keys and returns it as a string."
(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 :musical_keyboard: \n```text\n%s\n```\n" (buffer-string))))))
(defun spacemacs/describe-last-keys ()
"Gathers info about your Emacs last keys and copies to clipboard."
(interactive)
(let ((lossage (spacemacs//describe-last-keys-string)))
(kill-new lossage)
(message lossage)
(message (concat "Information has been copied to clipboard.\n"
(propertize
"PLEASE REVIEW THE DATA BEFORE GOING FURTHER AS IT CAN CONTAIN SENSITIVE DATA (PASSWORD, ...)\n"
'face 'font-lock-warning-face)
"You can paste it in the gitter chat.\n"
"Check the *Messages* buffer if you need to review it"))))
(defun spacemacs/report-issue (arg)
"Open a spacemacs/report-issue-mode buffer prepopulated with
issue report template and system information.
With prefix arg,include the last keys pressed."
(interactive "P")
(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}
"
(font-lock-add-keywords 'spacemacs/report-issue-mode
'(("\\(<<.*?>>\\)" . 'font-lock-comment-face))))
(define-key spacemacs/report-issue-mode-map
(kbd "C-c C-c") 'spacemacs//report-issue-done)
(define-key spacemacs/report-issue-mode-map
(kbd "C-c C-k") 'kill-buffer)
(with-eval-after-load 'bind-map
(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: 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)))
(provide 'core-spacemacs)