helm-spacemacs: add dotfile variable source go to action

This commit is contained in:
syl20bnr 2015-05-16 00:49:38 -04:00
parent f7dfad9253
commit d81e373275

View file

@ -63,6 +63,7 @@
(helm :buffer "*helm: spacemacs*"
:sources `(,(helm-spacemacs//layer-source)
,(helm-spacemacs//package-source)
,(helm-spacemacs//dotspacemacs-source)
,(helm-spacemacs//toggle-source))))
(defun helm-spacemacs//layer-source ()
@ -103,6 +104,22 @@
(push (symbol-name (car toggle)) result))
(sort result 'string<)))
(defun helm-spacemacs//dotspacemacs-source ()
`((name . "Dotfile")
(candidates . ,(helm-spacemacs//dotspacemacs-candidates))
(candidate-number-limit)
(action . (("Go to variable" . helm-spacemacs//go-to-dotfile-variable)))))
(defun helm-spacemacs//dotspacemacs-candidates ()
"Return the sorted candidates for all the dospacemacs variables."
(sort (all-completions "" obarray
(lambda (x)
(and (boundp x)
(not (keywordp x))
(string-prefix-p "dotspacemacs"
(symbol-name x)))))
'string<))
(defun helm-spacemacs//layer-action-open-file (file candidate)
"Open FILE of the passed CANDIDATE."
(let ((path (if (and (equalp file "README.md") (equalp candidate "spacemacs"))
@ -155,6 +172,15 @@
(when toggle
(funcall (plist-get (cdr toggle) :function)))))
(defun helm-spacemacs//go-to-dotfile-variable (candidate)
"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))
(provide 'helm-spacemacs)
;;; helm-spacemacs.el ends here