Skip to content

Commit fa6c0a6

Browse files
authored
Merge pull request #131 from davidshepherd7/master
Add helm-dash-async-install-docset function
2 parents 238d60e + 573036c commit fa6c0a6

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

helm-dash.el

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,47 @@ Report an error unless a valid docset is selected."
331331

332332
(helm-dash-install-docset-from-file docset-tmp-path))))
333333

334+
;;;###autoload
335+
(defun helm-dash-async-install-docset (docset-name)
336+
"Asynchronously download docset with specified DOCSET-NAME and move its stuff to docsets-path."
337+
(interactive (list (helm-dash-read-docset "Install docset" (helm-dash-available-docsets))))
338+
(when (helm-dash--ensure-created-docsets-path (helm-dash-docsets-path))
339+
(let ((feed-url (format "%s/%s.xml" helm-dash-docsets-url docset-name)))
340+
341+
(message (concat "The docset \"" docset-name "\" will now be installed asynchronously."))
342+
343+
(async-start ; First async call gets the docset meta data
344+
(lambda ()
345+
;; Beware! This lambda is run in it's own instance of emacs.
346+
(url-file-local-copy feed-url))
347+
(lambda (filename)
348+
(let ((docset-url (helm-dash-get-docset-url filename)))
349+
(async-start ; Second async call gets the docset itself
350+
(lambda ()
351+
;; Beware! This lambda is run in it's own instance of emacs.
352+
(url-file-local-copy docset-url))
353+
(lambda (docset-tmp-path)
354+
(helm-dash-async-install-docset-from-file docset-tmp-path)))))))))
355+
356+
;;;###autoload
357+
(defun helm-dash-async-install-docset-from-file (docset-tmp-path)
358+
(interactive (list (car (find-file-read-args "Docset Tarball: " t))))
359+
(let ((docset-tar-path (expand-file-name docset-tmp-path))
360+
(docset-out-path (helm-dash-docsets-path)))
361+
(async-start
362+
(lambda ()
363+
;; Beware! This lambda is run in it's own instance of emacs.
364+
(shell-command-to-string
365+
(format "tar xvf %s -C %s"
366+
(shell-quote-argument docset-tar-path)
367+
(shell-quote-argument docset-out-path))))
368+
(lambda (shell-output)
369+
(let ((docset-folder (helm-dash-docset-folder-name shell-output)))
370+
(helm-dash-activate-docset docset-folder)
371+
(message (format
372+
"Docset installed. Add \"%s\" to helm-dash-common-docsets or helm-dash-docsets."
373+
docset-folder)))))))
374+
334375
(defalias 'helm-dash-update-docset 'helm-dash-install-docset)
335376

336377
(defun helm-dash-docset-folder-name (tar-output)

0 commit comments

Comments
 (0)