Skip to content

Commit

Permalink
Calculate longest candidate instead of harcoding to
Browse files Browse the repository at this point in the history
an unknown value.
  • Loading branch information
thierryvolpiatto committed Oct 4, 2023
1 parent ebe71ec commit 19075bb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions helm-apt.el
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
(defvar helm-apt-installed-packages nil)
(defvar helm-apt-term-buffer nil)
(defvar helm-apt-default-archs nil)
(defvar helm-apt--max-len-candidate 0)


(defgroup helm-apt nil
Expand Down Expand Up @@ -236,7 +237,7 @@ Support install, remove and purge actions."
(propertize name 'face 'helm-apt-installed))
(t name))
for desc = (cadr split)
for sep = (helm-make-separator name 40)
for sep = (helm-make-separator name helm-apt--max-len-candidate)
collect (cons (concat
disp1
sep
Expand All @@ -248,9 +249,10 @@ Support install, remove and purge actions."
(sort candidates #'helm-generic-sort-fn))

;;;###autoload
(defun helm-apt-search ()
(defun helm-apt-search (&optional arg)
"Search in pkg names and their whole description asynchronously."
(interactive)
(interactive "P")
(when arg (setq helm-apt-installed-packages nil))
(unless helm-apt-default-archs
(setq helm-apt-default-archs
(append (split-string
Expand All @@ -268,7 +270,11 @@ Support install, remove and purge actions."
nil (current-buffer))
(cl-loop for i in (split-string (buffer-string) "\n" t)
for p = (split-string i)
collect (cons (car p) (cadr p))))))
for key = (car p)
for val = (cadr p)
do (setq helm-apt--max-len-candidate
(max (length key) helm-apt--max-len-candidate))
collect (cons key val)))))
(helm :sources (helm-build-async-source "Apt async"
:candidates-process #'helm-apt-search-init
:filtered-candidate-transformer '(helm-apt-search-transformer
Expand Down

0 comments on commit 19075bb

Please sign in to comment.