2016-01-04 19:20:54 +00:00
|
|
|
;;; helm-spacemacs-help.el --- Spacemacs layer exploration with `helm'.
|
2014-12-20 04:48:31 +00:00
|
|
|
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; Keywords: helm, spacemacs
|
|
|
|
;; Version: 0.1
|
|
|
|
;; Package-Requires: ((helm "1.5"))
|
|
|
|
|
|
|
|
;; This file is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
;; any later version.
|
|
|
|
|
|
|
|
;; This file is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to
|
|
|
|
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
;; Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;; This package adds a convenient way to discover Spacemacs configuration
|
|
|
|
;; layers thanks to helm.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2015-08-27 06:58:05 +00:00
|
|
|
(require 'cl)
|
2014-12-21 07:53:14 +00:00
|
|
|
(require 'ht)
|
2015-01-27 05:16:44 +00:00
|
|
|
(require 'helm)
|
2015-11-11 21:49:07 +00:00
|
|
|
(require 'helm-command)
|
2015-10-05 15:34:57 +00:00
|
|
|
(require 'helm-org)
|
2015-01-27 05:16:44 +00:00
|
|
|
(require 'core-configuration-layer)
|
2014-12-21 07:53:14 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defvar helm-spacemacs-help-all-layers nil
|
2014-12-21 07:53:14 +00:00
|
|
|
"Alist of all configuration layers.")
|
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defvar helm-spacemacs-help-all-packages nil
|
2014-12-21 07:53:14 +00:00
|
|
|
"Hash table of all packages in all layers.")
|
|
|
|
|
|
|
|
;;;###autoload
|
2016-01-04 19:20:54 +00:00
|
|
|
(define-minor-mode helm-spacemacs-help-mode
|
2014-12-21 07:53:14 +00:00
|
|
|
"Layers discovery with helm interface."
|
|
|
|
:group 'spacemacs
|
2015-08-12 12:59:25 +00:00
|
|
|
:global t)
|
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//init (&optional arg)
|
|
|
|
(when (or arg (null helm-spacemacs-help-all-packages))
|
2015-08-12 12:59:25 +00:00
|
|
|
(mapc (lambda (layer) (push (configuration-layer/make-layer layer)
|
2016-01-04 19:20:54 +00:00
|
|
|
helm-spacemacs-help-all-layers))
|
2015-08-12 12:59:25 +00:00
|
|
|
(configuration-layer/get-layers-list))
|
2016-05-30 01:12:54 +00:00
|
|
|
(let (configuration-layer--packages)
|
|
|
|
(configuration-layer/get-packages helm-spacemacs-help-all-layers)
|
|
|
|
(setq helm-spacemacs-help-all-packages configuration-layer--packages))))
|
2014-12-20 04:48:31 +00:00
|
|
|
|
|
|
|
;;;###autoload
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help (arg)
|
2014-12-20 04:48:31 +00:00
|
|
|
"Layers discovery with helm interface."
|
2015-08-12 12:59:25 +00:00
|
|
|
(interactive "P")
|
2016-01-04 19:20:54 +00:00
|
|
|
(helm-spacemacs-help-mode)
|
|
|
|
(helm-spacemacs-help//init arg)
|
2014-12-20 04:48:31 +00:00
|
|
|
(helm :buffer "*helm: spacemacs*"
|
2016-01-04 19:20:54 +00:00
|
|
|
:sources `(,(helm-spacemacs-help//documentation-source)
|
|
|
|
,(helm-spacemacs-help//layer-source)
|
|
|
|
,(helm-spacemacs-help//package-source)
|
|
|
|
,(helm-spacemacs-help//dotspacemacs-source)
|
|
|
|
,(helm-spacemacs-help//toggle-source)
|
|
|
|
,(helm-spacemacs-help//faq-source))))
|
2015-10-05 15:34:57 +00:00
|
|
|
|
|
|
|
;;;###autoload
|
2016-01-13 05:37:26 +00:00
|
|
|
(defun helm-spacemacs-help-dotspacemacs ()
|
|
|
|
"Helm session to search for dotfile variables."
|
|
|
|
(interactive)
|
|
|
|
(helm-spacemacs-help-mode)
|
|
|
|
(helm :buffer "*helm: spacemacs*"
|
|
|
|
:sources `(,(helm-spacemacs-help//dotspacemacs-source))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun helm-spacemacs-help-layers ()
|
|
|
|
"Helm session to search for layers."
|
|
|
|
(interactive)
|
|
|
|
(helm-spacemacs-help-mode)
|
|
|
|
(helm :buffer "*helm: spacemacs*"
|
|
|
|
:sources `(,(helm-spacemacs-help//layer-source))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun helm-spacemacs-help-packages (arg)
|
|
|
|
"Helm session to search for packages."
|
2015-10-05 15:34:57 +00:00
|
|
|
(interactive "P")
|
2016-01-04 19:20:54 +00:00
|
|
|
(helm-spacemacs-help-mode)
|
2016-01-13 05:37:26 +00:00
|
|
|
(helm-spacemacs-help//init arg)
|
|
|
|
(helm :buffer "*helm: spacemacs*"
|
|
|
|
:sources `(,(helm-spacemacs-help//package-source))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun helm-spacemacs-help-docs ()
|
|
|
|
"Helm session to search for documentation."
|
|
|
|
(interactive)
|
|
|
|
(helm-spacemacs-help-mode)
|
|
|
|
(helm :buffer "*helm: spacemacs*"
|
|
|
|
:sources `(,(helm-spacemacs-help//documentation-source))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun helm-spacemacs-help-toggles ()
|
|
|
|
"Helm session to search for toggles."
|
|
|
|
(interactive)
|
|
|
|
(helm-spacemacs-help-mode)
|
|
|
|
(helm :buffer "*helm: spacemacs*"
|
|
|
|
:sources `(,(helm-spacemacs-help//toggle-source))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun helm-spacemacs-help-faq ()
|
|
|
|
"Helm session to search for the FAQ."
|
|
|
|
(interactive)
|
|
|
|
(helm-spacemacs-help-mode)
|
2015-10-05 15:34:57 +00:00
|
|
|
(helm :buffer "*helm: spacemacs*"
|
2016-01-04 19:20:54 +00:00
|
|
|
:sources `(,(helm-spacemacs-help//faq-source))))
|
2014-12-20 04:48:31 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//documentation-source ()
|
2015-06-06 17:24:48 +00:00
|
|
|
"Construct the helm source for the documentation section."
|
2015-06-10 05:32:44 +00:00
|
|
|
(helm-build-sync-source "Spacemacs Documentation"
|
2016-01-04 19:20:54 +00:00
|
|
|
:candidates #'helm-spacemacs-help//documentation-candidates
|
|
|
|
:persistent-action #'helm-spacemacs-help//documentation-action-open-file
|
2015-06-10 02:56:08 +00:00
|
|
|
:keymap helm-map
|
|
|
|
:action (helm-make-actions
|
2016-01-04 19:20:54 +00:00
|
|
|
"Open Documentation" #'helm-spacemacs-help//documentation-action-open-file)))
|
2015-06-06 17:24:48 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//documentation-candidates ()
|
2015-06-10 15:06:30 +00:00
|
|
|
(let (result file-extension)
|
2015-06-18 06:54:48 +00:00
|
|
|
(dolist (filename (directory-files spacemacs-docs-directory))
|
|
|
|
(setq file-extension (file-name-extension filename))
|
2015-06-10 15:06:30 +00:00
|
|
|
(when (or (equal file-extension "md")
|
|
|
|
(equal file-extension "org"))
|
2015-06-18 06:54:48 +00:00
|
|
|
(push filename result)))
|
Refactor CONTRIBUTING documentations
This commit merge the `CONTRIBUTING.md` and `doc/CONTRIBUTE.org` file
into a new `CONTRIBUTING.org` file. It also refactors the content to be
more organized and make its navigation more goal-oriented.
Github displays a link to the `CONTRIBUTING.*` file when people are
opening new issues or proposing new PRs. This file is important because
it is the entry-point to contributions guidelines for most of the users.
The current setup is non-optimal, even broken, as it adds a level of
indirection, and points to a contributing file that has broken
links (due to the new documentation format). The possible drawback of
the proposed solution is that I'm not sure if it is possible to include
it into the new online documentation as it is not in `doc/` folder.
The other possibility is to keep a small `CONTRIBUTING.md` file, as it
is now, pointing to the new documentation system (once online), but I'm
preferring the proposed solution for the following reasons:
- People that are willing to contribute will probably open Github
first (for forking, creating PR, etc), not the online documentation.
- It has one level of indirection less when people click on the
guidelines guide from a new issue/PR.
- `CONTRIBUTING.*` is by convention a special kind of file on github, so
it's valid reason to break the rule and not having it in the `doc/`
folder.
2015-11-22 13:11:08 +00:00
|
|
|
|
|
|
|
;; CONTRIBUTING.org is a special case as it should be at the root of the
|
|
|
|
;; repository to be linked as the contributing guide on Github.
|
|
|
|
(push "CONTRIBUTING.org" result)
|
|
|
|
|
2015-06-11 05:00:54 +00:00
|
|
|
;; delete DOCUMENTATION.org to make it the first guide
|
|
|
|
(delete "DOCUMENTATION.org" result)
|
|
|
|
(push "DOCUMENTATION.org" result)
|
2015-06-10 02:56:08 +00:00
|
|
|
|
|
|
|
;; give each document an appropriate title
|
|
|
|
(mapcar (lambda (r)
|
|
|
|
(cond
|
Refactor CONTRIBUTING documentations
This commit merge the `CONTRIBUTING.md` and `doc/CONTRIBUTE.org` file
into a new `CONTRIBUTING.org` file. It also refactors the content to be
more organized and make its navigation more goal-oriented.
Github displays a link to the `CONTRIBUTING.*` file when people are
opening new issues or proposing new PRs. This file is important because
it is the entry-point to contributions guidelines for most of the users.
The current setup is non-optimal, even broken, as it adds a level of
indirection, and points to a contributing file that has broken
links (due to the new documentation format). The possible drawback of
the proposed solution is that I'm not sure if it is possible to include
it into the new online documentation as it is not in `doc/` folder.
The other possibility is to keep a small `CONTRIBUTING.md` file, as it
is now, pointing to the new documentation system (once online), but I'm
preferring the proposed solution for the following reasons:
- People that are willing to contribute will probably open Github
first (for forking, creating PR, etc), not the online documentation.
- It has one level of indirection less when people click on the
guidelines guide from a new issue/PR.
- `CONTRIBUTING.*` is by convention a special kind of file on github, so
it's valid reason to break the rule and not having it in the `doc/`
folder.
2015-11-22 13:11:08 +00:00
|
|
|
((string-equal r "CONTRIBUTING.org")
|
2015-06-10 02:56:08 +00:00
|
|
|
`("How to contribute to Spacemacs" . ,r))
|
2015-06-11 05:00:54 +00:00
|
|
|
((string-equal r "CONVENTIONS.org")
|
2015-06-10 02:56:08 +00:00
|
|
|
`("Spacemacs conventions" . ,r))
|
2015-06-11 05:00:54 +00:00
|
|
|
((string-equal r "DOCUMENTATION.org")
|
2015-09-24 04:17:37 +00:00
|
|
|
`("Spacemacs documentation" . ,r))
|
|
|
|
((string-equal r "FAQ.org")
|
|
|
|
`("Spacemacs FAQ" . ,r))
|
2015-08-05 20:09:58 +00:00
|
|
|
((string-equal r "LAYERS.org")
|
|
|
|
`("Tips on writing layers for Spacemacs" . ,r))
|
2015-09-24 04:17:37 +00:00
|
|
|
((string-equal r "QUICK_START.org")
|
|
|
|
`("Quick start guide for Spacemacs" . ,r))
|
2015-06-10 02:56:08 +00:00
|
|
|
((string-equal r "VIMUSERS.org")
|
|
|
|
`("Vim users migration guide" . ,r))
|
|
|
|
(t
|
2016-04-08 20:04:54 +00:00
|
|
|
`(,r . ,r))))
|
2015-06-10 02:56:08 +00:00
|
|
|
result)))
|
2015-06-06 17:24:48 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//documentation-action-open-file (candidate)
|
2015-06-06 17:24:48 +00:00
|
|
|
"Open documentation FILE."
|
Refactor CONTRIBUTING documentations
This commit merge the `CONTRIBUTING.md` and `doc/CONTRIBUTE.org` file
into a new `CONTRIBUTING.org` file. It also refactors the content to be
more organized and make its navigation more goal-oriented.
Github displays a link to the `CONTRIBUTING.*` file when people are
opening new issues or proposing new PRs. This file is important because
it is the entry-point to contributions guidelines for most of the users.
The current setup is non-optimal, even broken, as it adds a level of
indirection, and points to a contributing file that has broken
links (due to the new documentation format). The possible drawback of
the proposed solution is that I'm not sure if it is possible to include
it into the new online documentation as it is not in `doc/` folder.
The other possibility is to keep a small `CONTRIBUTING.md` file, as it
is now, pointing to the new documentation system (once online), but I'm
preferring the proposed solution for the following reasons:
- People that are willing to contribute will probably open Github
first (for forking, creating PR, etc), not the online documentation.
- It has one level of indirection less when people click on the
guidelines guide from a new issue/PR.
- `CONTRIBUTING.*` is by convention a special kind of file on github, so
it's valid reason to break the rule and not having it in the `doc/`
folder.
2015-11-22 13:11:08 +00:00
|
|
|
(let ((file (if (string= candidate "CONTRIBUTING.org")
|
|
|
|
;; CONTRIBUTING.org is a special case as it should be at the
|
|
|
|
;; root of the repository to be linked as the contributing
|
|
|
|
;; guide on Github.
|
|
|
|
(concat user-emacs-directory candidate)
|
|
|
|
(concat spacemacs-docs-directory candidate))))
|
2015-06-09 03:32:55 +00:00
|
|
|
(cond ((and (equal (file-name-extension file) "md")
|
|
|
|
(not helm-current-prefix-arg))
|
2016-02-24 15:32:45 +00:00
|
|
|
(condition-case-unless-debug nil
|
2015-06-09 03:32:55 +00:00
|
|
|
(with-current-buffer (find-file-noselect file)
|
|
|
|
(gh-md-render-buffer)
|
|
|
|
(kill-this-buffer))
|
|
|
|
;; if anything fails, fall back to simply open file
|
|
|
|
(find-file file)))
|
|
|
|
((equal (file-name-extension file) "org")
|
2015-06-10 15:06:30 +00:00
|
|
|
(spacemacs/view-org-file file "^" 'all))
|
2015-06-09 03:32:55 +00:00
|
|
|
(t
|
|
|
|
(find-file file)))))
|
2015-06-06 17:24:48 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//layer-source ()
|
2014-12-20 04:48:31 +00:00
|
|
|
"Construct the helm source for the layer section."
|
|
|
|
`((name . "Layers")
|
2014-12-25 19:45:27 +00:00
|
|
|
(candidates . ,(sort (configuration-layer/get-layers-list) 'string<))
|
2015-03-05 05:00:54 +00:00
|
|
|
(candidate-number-limit)
|
2016-01-04 19:20:54 +00:00
|
|
|
(keymap . ,helm-spacemacs-help--layer-map)
|
2015-08-09 03:31:02 +00:00
|
|
|
(action . (("Open README.org"
|
2016-01-04 19:20:54 +00:00
|
|
|
. helm-spacemacs-help//layer-action-open-readme)
|
2015-08-09 03:31:02 +00:00
|
|
|
("Open packages.el"
|
2016-01-04 19:20:54 +00:00
|
|
|
. helm-spacemacs-help//layer-action-open-packages)
|
2016-01-12 00:02:22 +00:00
|
|
|
("Install Layer"
|
|
|
|
. helm-spacemacs-help//layer-action-install-layer)
|
2015-10-02 18:51:10 +00:00
|
|
|
("Open README.org (for editing)"
|
2016-01-04 19:20:54 +00:00
|
|
|
. helm-spacemacs-help//layer-action-open-readme-edit)))))
|
2014-12-20 04:48:31 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defvar helm-spacemacs-help--layer-map
|
2015-11-20 04:43:01 +00:00
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(set-keymap-parent map helm-map)
|
|
|
|
(define-key map (kbd "<S-return>") '(lambda () (interactive)
|
|
|
|
;; Add Layer
|
|
|
|
(helm-select-nth-action 3)))
|
|
|
|
map)
|
|
|
|
"Keymap for Spacemacs Layers sources")
|
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//package-source ()
|
2014-12-21 07:53:14 +00:00
|
|
|
"Construct the helm source for the packages."
|
|
|
|
`((name . "Packages")
|
2016-01-04 19:20:54 +00:00
|
|
|
(candidates . ,(helm-spacemacs-help//package-candidates))
|
2015-03-05 05:00:54 +00:00
|
|
|
(candidate-number-limit)
|
2015-08-09 03:31:02 +00:00
|
|
|
(action . (("Go to init function"
|
2016-02-22 07:29:43 +00:00
|
|
|
. helm-spacemacs-help//package-action-goto-init-func)
|
|
|
|
("Describe"
|
|
|
|
. helm-spacemacs-help//package-action-decribe)))))
|
2014-12-21 07:53:14 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//package-candidates ()
|
2014-12-21 07:53:14 +00:00
|
|
|
"Return the sorted candidates for package source."
|
|
|
|
(let (result)
|
2016-01-04 19:20:54 +00:00
|
|
|
(dolist (pkg helm-spacemacs-help-all-packages)
|
2015-11-11 21:49:07 +00:00
|
|
|
(push (format "%s (%S layer)"
|
|
|
|
(propertize (symbol-name (oref pkg :name))
|
|
|
|
'face 'font-lock-type-face)
|
|
|
|
(oref pkg :owner))
|
2015-08-09 03:31:02 +00:00
|
|
|
result))
|
2014-12-21 07:53:14 +00:00
|
|
|
(sort result 'string<)))
|
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//toggle-source ()
|
2015-01-29 05:08:48 +00:00
|
|
|
"Construct the helm source for the toggles."
|
2015-08-27 06:58:05 +00:00
|
|
|
(helm-build-sync-source "Toggles"
|
2016-01-04 19:20:54 +00:00
|
|
|
:candidates #'helm-spacemacs-help//toggle-candidates
|
|
|
|
:persistent-action #'helm-spacemacs-help//toggle
|
2015-08-27 06:58:05 +00:00
|
|
|
:keymap helm-map
|
2016-01-04 19:20:54 +00:00
|
|
|
:action (helm-make-actions "Toggle" #'helm-spacemacs-help//toggle)))
|
2015-01-29 05:08:48 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//toggle-candidates ()
|
2015-01-29 05:08:48 +00:00
|
|
|
"Return the sorted candidates for toggle source."
|
|
|
|
(let (result)
|
|
|
|
(dolist (toggle spacemacs-toggles)
|
2015-08-27 06:58:05 +00:00
|
|
|
(let* ((toggle-symbol (symbol-name (car toggle)))
|
2016-05-31 13:33:44 +00:00
|
|
|
(toggle-status (funcall (plist-get (cdr toggle) :predicate)))
|
2015-08-27 06:58:05 +00:00
|
|
|
(toggle-name (capitalize (replace-regexp-in-string "-" " " toggle-symbol)))
|
2016-05-31 13:33:44 +00:00
|
|
|
(toggle-doc (format "(%s) %s: %s"
|
|
|
|
(if toggle-status "+" "-")
|
2015-11-11 21:49:07 +00:00
|
|
|
toggle-name
|
|
|
|
(propertize
|
|
|
|
(or (plist-get (cdr toggle) :documentation) "")
|
|
|
|
'face 'font-lock-doc-face))))
|
|
|
|
(when (plist-member (cdr toggle) :evil-leader)
|
|
|
|
(let ((key (key-description
|
|
|
|
(kbd (concat dotspacemacs-leader-key " "
|
|
|
|
(plist-get (cdr toggle) :evil-leader))))))
|
|
|
|
(setq toggle-doc
|
|
|
|
(format "%s (%s)"
|
|
|
|
toggle-doc
|
|
|
|
(propertize key 'face 'helm-M-x-key)))))
|
2015-08-27 06:58:05 +00:00
|
|
|
(if (plist-member (cdr toggle) :documentation)
|
|
|
|
(push `(,toggle-doc . ,toggle-symbol) result)
|
|
|
|
(push `(,toggle-name . ,toggle-symbol) result))))
|
|
|
|
(setq result (cl-sort result 'string< :key 'car))
|
|
|
|
result))
|
2015-01-29 05:08:48 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//dotspacemacs-source ()
|
2015-05-16 04:49:38 +00:00
|
|
|
`((name . "Dotfile")
|
2016-01-04 19:20:54 +00:00
|
|
|
(candidates . ,(helm-spacemacs-help//dotspacemacs-candidates))
|
2015-05-16 04:49:38 +00:00
|
|
|
(candidate-number-limit)
|
2016-01-04 19:20:54 +00:00
|
|
|
(action . (("Go to variable" . helm-spacemacs-help//go-to-dotfile-variable)))))
|
2015-05-16 04:49:38 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//dotspacemacs-candidates ()
|
2015-05-16 04:49:38 +00:00
|
|
|
"Return the sorted candidates for all the dospacemacs variables."
|
2015-09-01 03:16:14 +00:00
|
|
|
(sort (dotspacemacs/get-variable-string-list) 'string<))
|
2015-05-16 04:49:38 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//layer-action-open-file (file candidate &optional edit)
|
2015-10-02 18:51:10 +00:00
|
|
|
"Open FILE of the passed CANDIDATE. If EDIT is false, open in view mode."
|
2015-06-12 01:23:50 +00:00
|
|
|
(let ((path (if (and (equalp file "README.org") (equalp candidate "spacemacs"))
|
2015-02-27 16:23:50 +00:00
|
|
|
;; Readme for spacemacs is in the project root
|
|
|
|
(ht-get configuration-layer-paths (intern candidate))
|
|
|
|
(file-name-as-directory
|
|
|
|
(concat (ht-get configuration-layer-paths
|
|
|
|
(intern candidate))
|
|
|
|
candidate)))))
|
2015-06-12 01:23:50 +00:00
|
|
|
(if (and (equal (file-name-extension file) "org")
|
2015-04-29 18:07:05 +00:00
|
|
|
(not helm-current-prefix-arg))
|
2015-10-02 18:51:10 +00:00
|
|
|
(if edit
|
|
|
|
(find-file (concat path file))
|
|
|
|
(spacemacs/view-org-file (concat path file) "^" 'all))
|
2015-04-23 05:20:23 +00:00
|
|
|
(find-file (concat path file)))))
|
2014-12-20 04:48:31 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//layer-action-open-readme (candidate)
|
2015-10-02 18:51:10 +00:00
|
|
|
"Open the `README.org' file of the passed CANDIDATE for reading."
|
2016-01-04 19:20:54 +00:00
|
|
|
(helm-spacemacs-help//layer-action-open-file "README.org" candidate))
|
2014-12-20 04:48:31 +00:00
|
|
|
|
2016-01-12 00:02:22 +00:00
|
|
|
(defun helm-spacemacs-help//layer-action-install-layer (candidate-layer)
|
|
|
|
"Add CANDIDATE-LAYER to dotspacemacs file and reloads configuration"
|
2016-03-25 04:24:52 +00:00
|
|
|
(when (dotspacemacs/add-layer (intern candidate-layer))
|
|
|
|
(dotspacemacs/sync-configuration-layers)))
|
2015-11-20 04:43:01 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//layer-action-open-readme-edit (candidate)
|
2015-10-02 18:51:10 +00:00
|
|
|
"Open the `README.org' file of the passed CANDIDATE for editing."
|
2016-01-04 19:20:54 +00:00
|
|
|
(helm-spacemacs-help//layer-action-open-file "README.org" candidate t))
|
2015-10-02 18:51:10 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//layer-action-open-packages (candidate)
|
2014-12-20 04:48:31 +00:00
|
|
|
"Open the `packages.el' file of the passed CANDIDATE."
|
2016-01-04 19:20:54 +00:00
|
|
|
(helm-spacemacs-help//layer-action-open-file "packages.el" candidate))
|
2014-12-20 04:48:31 +00:00
|
|
|
|
2016-02-22 07:29:43 +00:00
|
|
|
(defun helm-spacemacs-help//package-action-decribe (candidate)
|
|
|
|
"Describe the passed package using Spacemacs describe function."
|
|
|
|
(save-match-data
|
|
|
|
(string-match "^\\(.+\\)\s(\\(.+\\) layer)$" candidate)
|
|
|
|
(let* ((package (match-string 1 candidate)))
|
|
|
|
(configuration-layer/describe-package (intern package)))))
|
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//package-action-goto-init-func (candidate)
|
2014-12-21 07:53:14 +00:00
|
|
|
"Open the file `packages.el' and go to the init function."
|
|
|
|
(save-match-data
|
2015-11-12 09:49:31 +00:00
|
|
|
(string-match "^\\(.+\\)\s(\\(.+\\) layer)$" candidate)
|
|
|
|
;; (string-match "^(\\(.+\\))\s\\(.+\\):\s\\(.+\\)$" candidate)
|
|
|
|
(let* ((package (match-string 1 candidate))
|
|
|
|
(layer (match-string 2 candidate))
|
2014-12-21 07:53:14 +00:00
|
|
|
(path (file-name-as-directory
|
2014-12-25 19:45:27 +00:00
|
|
|
(concat (ht-get configuration-layer-paths (intern layer))
|
2014-12-21 07:53:14 +00:00
|
|
|
layer)))
|
2015-11-12 09:49:31 +00:00
|
|
|
(filename (concat path "packages.el")))
|
2014-12-21 07:53:14 +00:00
|
|
|
(find-file filename)
|
2014-12-24 05:21:47 +00:00
|
|
|
(goto-char (point-min))
|
2014-12-21 07:53:14 +00:00
|
|
|
(re-search-forward (format "init-%s" package))
|
|
|
|
(beginning-of-line))))
|
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//toggle (candidate)
|
2015-01-29 05:08:48 +00:00
|
|
|
"Toggle candidate."
|
|
|
|
(let ((toggle (assq (intern candidate) spacemacs-toggles)))
|
|
|
|
(when toggle
|
2015-01-30 05:18:48 +00:00
|
|
|
(funcall (plist-get (cdr toggle) :function)))))
|
2015-01-29 05:08:48 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//go-to-dotfile-variable (candidate)
|
2015-05-16 04:49:38 +00:00
|
|
|
"Go to candidate in the dotfile."
|
|
|
|
(find-file dotspacemacs-filepath)
|
|
|
|
(goto-char (point-min))
|
|
|
|
;; try to exclude comments
|
|
|
|
(re-search-forward (format "^[a-z\s\\(\\-]*%s" candidate))
|
|
|
|
(beginning-of-line))
|
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defvar helm-spacemacs-help--faq-filename
|
2015-10-08 16:09:22 +00:00
|
|
|
(concat spacemacs-docs-directory "FAQ.org")
|
|
|
|
"Location of the FAQ file.")
|
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//faq-source ()
|
2015-10-05 15:34:57 +00:00
|
|
|
"Construct the helm source for the FAQ."
|
|
|
|
`((name . "FAQ")
|
2016-01-04 19:20:54 +00:00
|
|
|
(candidates . ,(helm-spacemacs-help//faq-candidates))
|
2015-10-05 15:34:57 +00:00
|
|
|
(candidate-number-limit)
|
2016-01-04 19:20:54 +00:00
|
|
|
(action . (("Go to question" . helm-spacemacs-help//faq-goto-marker)))))
|
2015-10-05 15:34:57 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//faq-candidate (cand)
|
2015-11-11 21:49:07 +00:00
|
|
|
(let ((str (substring-no-properties (car cand))))
|
2015-12-18 10:27:37 +00:00
|
|
|
(when (string-match "\\`.*/\\([^/]*\\)/\\(.*\\)\\'" str)
|
2015-11-11 21:49:07 +00:00
|
|
|
(cons (concat (propertize
|
|
|
|
(match-string 1 str)
|
|
|
|
'face 'font-lock-type-face)
|
|
|
|
": " (match-string 2 str))
|
|
|
|
(cdr cand)))))
|
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//faq-candidates ()
|
2016-01-03 17:30:41 +00:00
|
|
|
(let* ((helm-org-format-outline-path nil)
|
2016-01-04 19:20:54 +00:00
|
|
|
(cands (helm-org-get-candidates (list helm-spacemacs-help--faq-filename)))
|
2016-01-03 17:30:41 +00:00
|
|
|
section result)
|
2015-12-27 12:03:20 +00:00
|
|
|
(dolist (c cands)
|
|
|
|
(let ((str (substring-no-properties (car c))))
|
|
|
|
(when (string-match "\\`\\* \\(.*\\)\\'" str)
|
|
|
|
(setq section (match-string 1 str)))
|
|
|
|
(when (string-match "\\`\\*\\* \\(.*\\)\\'" str)
|
|
|
|
(push (cons (concat (propertize section 'face 'font-lock-type-face)
|
|
|
|
": " (match-string 1 str))
|
|
|
|
(cdr c))
|
|
|
|
result))))
|
|
|
|
result))
|
2015-10-08 16:09:22 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(defun helm-spacemacs-help//faq-goto-marker (marker)
|
|
|
|
(find-file helm-spacemacs-help--faq-filename)
|
2015-10-08 16:09:22 +00:00
|
|
|
(goto-char marker)
|
|
|
|
(org-show-context)
|
|
|
|
(org-show-entry))
|
2015-05-16 04:49:38 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
(provide 'helm-spacemacs-help)
|
2014-12-20 04:48:31 +00:00
|
|
|
|
2016-01-04 19:20:54 +00:00
|
|
|
;;; helm-spacemacs-help.el ends here
|