Skip to content

Commit

Permalink
* helm-config.el: Move gentoo to helm-gentoo.el
Browse files Browse the repository at this point in the history
* helm-gentoo.el: New file.
  • Loading branch information
thierryvolpiatto committed Mar 22, 2012
1 parent 18fc764 commit 888b319
Show file tree
Hide file tree
Showing 2 changed files with 231 additions and 211 deletions.
211 changes: 0 additions & 211 deletions helm-config.el
Expand Up @@ -3042,217 +3042,6 @@ Support install, remove and purge actions."

;; (helm-c-apt-install "jed")


;;; Helm UI for gentoo portage.
;;
;;
(defvar helm-c-gentoo-use-flags nil)
(defvar helm-c-gentoo-buffer "*helm-gentoo-output*")
(defvar helm-c-cache-gentoo nil)
(defvar helm-c-cache-world nil)
(defvar helm-c-source-gentoo
'((name . "Portage sources")
(init . (lambda ()
(get-buffer-create helm-c-gentoo-buffer)
(unless helm-c-cache-gentoo
(helm-c-gentoo-setup-cache))
(unless helm-c-cache-world
(setq helm-c-cache-world (helm-c-gentoo-get-world)))
(helm-c-gentoo-init-list)))
(candidates-in-buffer)
(match . identity)
(candidate-transformer helm-c-highlight-world)
(action . (("Show package" . (lambda (elm)
(helm-c-gentoo-eshell-action elm "eix")))
("Show history" . (lambda (elm)
(if (member elm helm-c-cache-world)
(helm-c-gentoo-eshell-action elm "genlop -qe")
(message "No infos on packages not yet installed"))))
("Copy in kill-ring" . kill-new)
("insert at point" . insert)
("Browse HomePage" . (lambda (elm)
(let ((urls (helm-c-gentoo-get-url elm)))
(browse-url (helm-comp-read "Url: " urls :must-match t)))))
("Show extra infos" . (lambda (elm)
(if (member elm helm-c-cache-world)
(helm-c-gentoo-eshell-action elm "genlop -qi")
(message "No infos on packages not yet installed"))))
("Show use flags" . (lambda (elm)
(helm-c-gentoo-default-action elm "equery" "-C" "u")
(font-lock-add-keywords nil '(("^\+.*" . font-lock-variable-name-face)))
(font-lock-mode 1)))
("Run emerge pretend" . (lambda (elm)
(helm-c-gentoo-eshell-action elm "emerge -p")))
("Emerge" . (lambda (elm)
(helm-gentoo-install elm :action 'install)))
("Unmerge" . (lambda (elm)
(helm-gentoo-install elm :action 'uninstall)))
("Show dependencies" . (lambda (elm)
(helm-c-gentoo-default-action elm "equery" "-C" "d")))
("Show related files" . (lambda (elm)
(helm-c-gentoo-default-action elm "equery" "files")))
("Refresh" . (lambda (elm)
(helm-c-gentoo-setup-cache)
(setq helm-c-cache-world (helm-c-gentoo-get-world))))))))


(defun* helm-gentoo-install (candidate &key action)
(setq helm-c-external-commands-list nil)
(ansi-term (getenv "SHELL") "Gentoo emerge")
(term-line-mode)
(let ((command (case action
('install "sudo emerge -av ")
('uninstall "sudo emerge -avC ")
(t (error "Unknow action"))))
(elms (mapconcat 'identity (helm-marked-candidates) " "))
(beg (point)) end)
(goto-char (point-max))
(insert (concat command elms))
(setq end (point))
(term-char-mode) (term-send-input)))

(defun helm-c-gentoo-default-action (elm command &rest args)
"Gentoo default action that use `helm-c-gentoo-buffer'."
(if (member elm helm-c-cache-world)
(progn
(helm-c-switch-to-buffer helm-c-gentoo-buffer)
(erase-buffer)
(let ((com-list (append args (list elm))))
(apply #'call-process command nil t nil
com-list)))
(message "No infos on packages not yet installed")))

(defvar helm-c-source-use-flags
'((name . "Use Flags")
(init . (lambda ()
(unless helm-c-gentoo-use-flags
(helm-c-gentoo-setup-use-flags-cache))
(helm-c-gentoo-get-use)))
(candidates-in-buffer)
(match . identity)
(candidate-transformer helm-c-highlight-local-use)
(action . (("Description"
. (lambda (elm)
(helm-c-switch-to-buffer helm-c-gentoo-buffer)
(erase-buffer)
(apply #'call-process "euse" nil t nil
`("-i"
,elm))
(font-lock-add-keywords nil `((,elm . font-lock-variable-name-face)))
(font-lock-mode 1)))
("Enable"
. (lambda (elm)
(helm-c-gentoo-eshell-action elm "*sudo -p Password: euse -E")))
("Disable"
. (lambda (elm)
(helm-c-gentoo-eshell-action elm "*sudo -p Password: euse -D")))
("Remove"
. (lambda (elm)
(helm-c-gentoo-eshell-action elm "*sudo -p Password: euse -P")))
("Show which dep use this flag"
. (lambda (elm)
(helm-c-switch-to-buffer helm-c-gentoo-buffer)
(erase-buffer)
(apply #'call-process "equery" nil t nil
`("-C"
"h"
,elm))))))))



(defun helm-c-gentoo-init-list ()
"Initialize buffer with all packages in Portage."
(let* ((portage-buf (get-buffer-create "*helm-gentoo*"))
(buf (helm-candidate-buffer 'portage-buf)))
(with-current-buffer buf
(dolist (i helm-c-cache-gentoo)
(insert (concat i "\n"))))))

(defun helm-c-gentoo-setup-cache ()
"Set up `helm-c-cache-gentoo'"
(setq helm-c-cache-gentoo
(split-string (with-temp-buffer
(call-process "eix" nil t nil
"--only-names")
(buffer-string)))))

(defun helm-c-gentoo-eshell-action (elm command)
(when (get-buffer "*EShell Command Output*")
(kill-buffer "*EShell Command Output*"))
(message "Wait searching...")
(let ((buf-fname (buffer-file-name helm-current-buffer)))
(if (and buf-fname (string-match tramp-file-name-regexp buf-fname))
(progn
(save-window-excursion
(pop-to-buffer "*scratch*")
(eshell-command (format "%s %s" command elm)))
(pop-to-buffer "*EShell Command Output*"))
(eshell-command (format "%s %s" command elm)))))

(defun helm-c-gentoo-get-use ()
"Initialize buffer with all use flags."
(let* ((use-buf (get-buffer-create "*helm-gentoo-use*"))
(buf (helm-candidate-buffer 'use-buf)))
(with-current-buffer buf
(dolist (i helm-c-gentoo-use-flags)
(insert (concat i "\n"))))))


(defun helm-c-gentoo-setup-use-flags-cache ()
"Setup `helm-c-gentoo-use-flags'"
(setq helm-c-gentoo-use-flags
(split-string (with-temp-buffer
(call-process "eix" nil t nil
"--print-all-useflags")
(buffer-string)))))

(defun helm-c-gentoo-get-url (elm)
"Return a list of urls from eix output."
(loop
with url-list = (split-string
(with-temp-buffer
(call-process "eix" nil t nil
elm "--format" "<homepage>\n")
(buffer-string)))
with all
for i in url-list
when (and (string-match "^http://.*" i)
(not (member i all)))
collect i into all
finally return all))

(defun helm-c-gentoo-get-world ()
"Return list of all installed package on your system."
(split-string (with-temp-buffer
(call-process "qlist" nil t nil
"-I")
(buffer-string))))

(defun helm-c-gentoo-get-local-use ()
(split-string (with-temp-buffer
(call-process "portageq" nil t nil
"envvar"
"USE")
(buffer-string))))


(defun helm-c-highlight-world (eix)
"Highlight all installed package."
(loop for i in eix
if (member i helm-c-cache-world)
collect (propertize i 'face 'helm-gentoo-match-face)
else
collect i))

(defun helm-c-highlight-local-use (use-flags)
(let ((local-uses (helm-c-gentoo-get-local-use)))
(loop for i in use-flags
if (member i local-uses)
collect (propertize i 'face 'helm-gentoo-match-face)
else
collect i)))



;;; Helm ratpoison UI
;;
Expand Down

0 comments on commit 888b319

Please sign in to comment.