Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Portage backend #24

Merged
merged 4 commits into from
Jun 28, 2018
Merged

Fix Portage backend #24

merged 4 commits into from
Jun 28, 2018

Conversation

chameco
Copy link
Contributor

@chameco chameco commented Jun 28, 2018

As discussed in #23 .

The changes I've made here are pretty minimal, mostly just switching to the new caching system.

Copy link
Member

@Ambrevar Ambrevar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! It's a definite step forward to bring portage up to speed, thanks!

(defun helm-system-packages-portage ()
"Preconfigured `helm' for Portage."
(unless (helm-system-packages-missing-dependencies-p "eix" "qlist" "euse" "portageq" "genlop")
(helm :sources (list (helm-system-packages-portage-build-source)
'helm-system-packages-portage-use-source)
(helm :sources (list (helm-system-packages-portage-build-source) helm-system-packages-portage-use-source)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave the linebreak here, it's a bit too long otherwise.

@@ -373,7 +373,7 @@ Return the result as a string."

With prefix argument, insert the output at point.
Otherwise display in `helm-system-packages-buffer'."
(let ((res (helm-system-packages-call command args)))
(let ((res (apply 'helm-system-packages-run (cons command args))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-print is deprecated. We should eventually move to -show-information. But that can wait for the next pull request :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is just lack of (immediate) effort on my part.

@@ -256,26 +232,13 @@ The caller can pass the list of EXPLICIT packages to avoid re-computing it."
(defvar helm-system-packages-portage-use-source
(helm-build-in-buffer-source "USE flags"
:init 'helm-system-packages-portage-use-init
:candidate-transformer 'helm-system-packages-portage-use-transformer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you moved the transformer to the -use-init function. Why?
As I understand it, the USE flags won't be updated on change.
Let me know if I'm wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure of how to approach this one - ideally, we want the USE-flag properties to be re-cached in helm-system-packages-portage-refresh, since then they'll be updated after running commands etc. However, that will inextricably link the package list source and the USE-flag source, preventing then from potentially being used independently by a third party. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so if I understand correctly, by moving the transformer to the init function you are updating the USE source everytime?
If this is fast enough, then I think this is the right approach.

(define-key map (kbd "M-N") 'helm-system-packages-portage-toggle-uninstalled)
(define-key map (kbd "M-D") 'helm-system-packages-portage-toggle-dependencies)
(define-key map (kbd "C-]") 'helm-system-packages-toggle-descriptions)
map))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you only move this block? Unless really necessary, let's keep the diff short! :)

(set-keymap-parent map helm-map)
(define-key map (kbd "M-I") 'helm-system-packages-portage-toggle-explicit)
(define-key map (kbd "M-N") 'helm-system-packages-portage-toggle-uninstalled)
(define-key map (kbd "M-D") 'helm-system-packages-portage-toggle-dependencies)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those 3 -toggles can be replaced with the package-level -toggles, e.g. helm-system-packages-toggle-explicit.

(defun helm-system-packages-portage-cache (display-list)
"Cache all package names with descriptions."
(let* ((raw (with-temp-buffer
(process-file "env" nil '(t nil) nil "EIX_LIMIT=0" "OVERLAYS_LIST=none" "PRINT_COUNT_ALWAYS=never" "eix" "--format" "<category>/<name>\t<description>\n")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think now we should break this absurdly long line ;)

;; tell `eix' to use the same formatting as `apt-cache' so that we can
;; re-use its code.
;; TODO: Can eix pad in the format string just like `expac' does?
;; TODO: Or output straight to Elisp?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of outputting straight to Elisp? Could be dangerous, but could also be simpler and faster (if speed is a problem).
If you think this is still relevant, please keep the "TODO" note.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the eix documentation that exists is fairly sparse, I couldn't find any reference to padding in the format string anywhere. It would certainly help significantly if this was possible. As far as outputting directly to Elisp, I assume you mean writing a series of S-expressions and then using read? I agree that this is fairly dangerous, and we'd have to perform a post-processing step anyway, since eix doesn't have any ability to escape strings AFAIK.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Feel free to comment on the TODO in the code.

(buffer-string)))
(paired (mapcar (lambda (x) (let ((l (split-string x "\t"))) (cons (car l) (cadr l)))) (split-string raw "\n")))
(names (mapcar 'car paired))
(descriptions (mapcar (lambda (x) (concat (car x) (make-string (max (- helm-system-packages-column-width (length (car x))) 0) ? ) (cdr x))) paired)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please break all the long lines, thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

names and descriptions are supposed to be string buffers for helm-system-packages--cache-set. Is this really working?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helm-init-candidates-in-buffer accepts either a string or a list of candidates according to its documentation.

@Ambrevar
Copy link
Member

Looks good to me! Let me know when this is ready for a merge.

@chameco
Copy link
Contributor Author

chameco commented Jun 28, 2018

Should be ready now.

@Ambrevar Ambrevar merged commit d510562 into emacs-helm:master Jun 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants