branch: elpa/helm
commit b4916d6720f0e16a1a06ee49ca3228a10111ddd3
Author: Thierry Volpiatto <[email protected]>
Commit: Thierry Volpiatto <[email protected]>
Add tldr action to helm-man
---
helm-man.el | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/helm-man.el b/helm-man.el
index b6358bdad54..5dd448e08ab 100644
--- a/helm-man.el
+++ b/helm-man.el
@@ -61,6 +61,8 @@ source.")
(defvar helm-source-man-pages nil)
+(defvar helm-man--tldr-cache nil)
+
(defun helm-man-default-action (candidate)
"Default action for jumping to a woman or man page from Helm."
(let ((wfiles (mapcar #'car (woman-file-name-all-completions candidate))))
@@ -87,6 +89,8 @@ source.")
(let ((warning-suppress-log-types '((defvaralias))))
(require 'woman))
(require 'helm-utils)
+ (unless helm-man--tldr-cache
+ (setq helm-man--tldr-cache (helm-man--tldr-cache)))
(unless helm-man--pages
(setq woman-expanded-directory-path
(woman-expand-directory-path woman-manpath woman-path))
@@ -103,6 +107,24 @@ source.")
output)
(match-string 2 output))))
+(defun helm-man-tldr-render (command)
+ (with-current-buffer-window "*tldr*" nil nil
+ (call-process "tldr" nil t nil "--color" "always" command)
+ (ansi-color-apply-on-region (point-min) (point-max))
+ (local-set-key "q" 'quit-window)))
+
+(defun helm-man--tldr-cache ()
+ (when (executable-find "tldr")
+ (with-temp-buffer
+ (call-process "tldr" nil t nil "-l")
+ (split-string (buffer-string) "\n"))))
+
+(defun helm-man-action-transformer (actions _candidate)
+ (let ((disp (helm-get-selection nil t)))
+ (if (member disp helm-man--tldr-cache)
+ (append actions '(("tldr" . helm-man-tldr-render)))
+ actions)))
+
(defclass helm-man-pages-class (helm-source-in-buffer)
((popup-info :initform #'helm-man-popup-info)))
@@ -113,7 +135,8 @@ With a prefix ARG reinitialize the cache. To have a popup
showing a basic description of selected candidate, turn on
`helm-popup-tip-mode'."
(interactive "P")
- (when arg (setq helm-man--pages nil))
+ (when arg (setq helm-man--pages nil
+ helm-man--tldr-cache nil))
(unless helm-source-man-pages
(setq helm-source-man-pages
(helm-make-source "Manual Pages" 'helm-man-pages-class
@@ -122,6 +145,7 @@ showing a basic description of selected candidate, turn on
:filtered-candidate-transformer
(lambda (candidates _source)
(sort candidates #'helm-generic-sort-fn))
+ :action-transformer 'helm-man-action-transformer
:action '(("Display Man page" . helm-man-default-action))
:group 'helm-man)))
(helm :sources 'helm-source-man-pages