Helm: Add browse-urls action to helm-occur.

master
Pierre Neidhardt 2020-05-20 10:13:34 +02:00
parent d167008924
commit cc83668eab
1 changed files with 21 additions and 0 deletions

View File

@ -339,4 +339,25 @@ Useful for Guix."
(advice-add 'helm-external-commands-list-1
:around #'ambrevar/helm-external-command-cleanup-dotted)
;; From https://github.com/emacs-helm/helm/issues/2149:
(defun helm-occur-extract-urls-from-line (line)
(with-temp-buffer
(save-excursion (insert "\n" line))
(cl-loop while (re-search-forward "\\(https?\\|ftp\\)://[^ >]*" nil t)
collect (match-string 0))))
(defun helm-occur-browse-urls (_candidate)
(let ((urls (helm-occur-extract-urls-from-line (helm-get-selection nil t))))
(browse-url (helm-comp-read "Url: " urls :exec-when-only-one t))))
(defun helm-occur-action-transformer (actions _candidate)
(cond ((string-match "\\(https?\\|ftp\\)://[^ >]*" (helm-get-selection nil t))
(helm-append-at-nth actions
'(("Browse urls in line" . helm-occur-browse-urls))
1))
(t actions)))
(defmethod helm-setup-user-source ((source helm-moccur-class))
(setf (slot-value source 'action-transformer) 'helm-occur-action-transformer))
(provide 'init-helm)