[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/helm b6c85e81fe 5/5: Make helm-popup-tip-mode working with
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/helm b6c85e81fe 5/5: Make helm-popup-tip-mode working with any sources |
Date: |
Sat, 17 Aug 2024 07:00:32 -0400 (EDT) |
branch: elpa/helm
commit b6c85e81fe4e5ff4429954b0e4d39ce98e9f79d2
Author: Thierry Volpiatto <thievol@posteo.net>
Commit: Thierry Volpiatto <thievol@posteo.net>
Make helm-popup-tip-mode working with any sources
Now in addition of popping up in helm-grep sources, any source that
have a helm-popup-info attribute handling a function will popup a tip
as well.
Enable it in helm-source-man-pages.
---
helm-man.el | 31 ++++++++++++++++++++++---------
helm-utils.el | 48 ++++++++++++++++++++++++++++++------------------
2 files changed, 52 insertions(+), 27 deletions(-)
diff --git a/helm-man.el b/helm-man.el
index 1db5c57faf..39c37e2b69 100644
--- a/helm-man.el
+++ b/helm-man.el
@@ -58,6 +58,8 @@ Arguments are passed to `manual-entry' with `format.'"
Will be calculated the first time you invoke Helm with this
source.")
+(defvar helm-source-man-pages 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))))
@@ -90,15 +92,16 @@ source.")
(setq helm-man--pages (mapcar 'car woman-topic-all-completions)))
(helm-init-candidates-in-buffer 'global helm-man--pages))
-(defvar helm-source-man-pages
- (helm-build-in-buffer-source "Manual Pages"
- :init #'helm-man--init
- :persistent-action #'ignore
- :filtered-candidate-transformer
- (lambda (candidates _source)
- (sort candidates #'helm-generic-sort-fn))
- :action '(("Display Man page" . helm-man-default-action))
- :group 'helm-man))
+(defun helm-man-popup-info (name)
+ (let ((output (shell-command-to-string (format "man -f '%s'" name))))
+ (when (string-match (format "\\(%s ?([^(]+)\\) *- ?\\(.*\\)\n" name)
+ output)
+ (match-string 2 output))))
+
+(defclass helm-man-pages-class (helm-source-in-buffer)
+ ((helm-popup-info
+ :initarg :helm-popup-info
+ :initform #'helm-man-popup-info)))
;;;###autoload
(defun helm-man-woman (arg)
@@ -106,6 +109,16 @@ source.")
With a prefix arg reinitialize the cache."
(interactive "P")
(when arg (setq helm-man--pages nil))
+ (unless helm-source-man-pages
+ (setq helm-source-man-pages
+ (helm-make-source "Manual Pages" 'helm-man-pages-class
+ :init #'helm-man--init
+ :persistent-action #'ignore
+ :filtered-candidate-transformer
+ (lambda (candidates _source)
+ (sort candidates #'helm-generic-sort-fn))
+ :action '(("Display Man page" . helm-man-default-action))
+ :group 'helm-man)))
(helm :sources 'helm-source-man-pages
:buffer "*helm man woman*"))
diff --git a/helm-utils.el b/helm-utils.el
index 6922a26c32..936a81db37 100644
--- a/helm-utils.el
+++ b/helm-utils.el
@@ -1038,27 +1038,39 @@ Assume regexp is a pcre based regexp."
(setq helm--show-help-echo-timer nil))
(when helm--maybe-show-help-echo-overlay
(delete-overlay helm--maybe-show-help-echo-overlay))
- (when (and helm-alive-p
- helm-popup-tip-mode
- (member (assoc-default 'name (helm-get-current-source))
- helm-sources-using-help-echo-popup))
- (setq helm--show-help-echo-timer
- (run-with-idle-timer
- 1 nil
- (lambda ()
- (save-selected-window
- (with-helm-window
- ;; Use helm-grep-fname prop instead of help-echo as help-echo
- ;; maybe used by mouse overlay after resume.
- (helm-aif (get-text-property (pos-bol) 'helm-grep-fname)
- (helm-tooltip-show
- (concat " " (abbreviate-file-name it))
- (save-excursion
- (end-of-visual-line) (point)))))))))))
+ (let* ((src (helm-get-current-source))
+ (popup-info-fn (assoc-default 'helm-popup-info src)))
+ (when (and helm-alive-p
+ helm-popup-tip-mode
+ (or (member (assoc-default 'name src)
+ helm-sources-using-help-echo-popup)
+ popup-info-fn))
+ (setq helm--show-help-echo-timer
+ (run-with-idle-timer
+ 1 nil
+ (lambda ()
+ (save-selected-window
+ (with-helm-window
+ ;; Use helm-grep-fname prop instead of help-echo as
help-echo
+ ;; maybe used by mouse overlay after resume.
+ (let ((pos (save-excursion (end-of-visual-line) (point))))
+ (helm-acond ((get-text-property (pos-bol)
'helm-grep-fname)
+ (helm-tooltip-show
+ (concat " " (abbreviate-file-name it))
+ pos))
+ (popup-info-fn
+ (helm-tooltip-show
+ (concat " " (funcall it
(helm-get-selection)))
+ pos))))))))))))
;;;###autoload
(define-minor-mode helm-popup-tip-mode
- "Show help-echo informations in a popup tip at end of line."
+ "Show additional informations in a popup tip at end of line.
+
+When the mode is enabled, popup showup either when the source is one of
+`helm-sources-using-help-echo-popup' or the source has a `helm-popup-info'
+attribute which define a specific function for this source to fetch infos on
+candidate."
:global t
(if helm-popup-tip-mode
(progn