[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/helm fef33e1283 1/3: Allow toggling short doc in helm-M-x
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/helm fef33e1283 1/3: Allow toggling short doc in helm-M-x (#2496) |
Date: |
Fri, 15 Apr 2022 14:58:38 -0400 (EDT) |
branch: elpa/helm
commit fef33e128373aa2f0ff370396d846e90db4ce1ec
Author: Thierry Volpiatto <thievol@posteo.net>
Commit: Thierry Volpiatto <thievol@posteo.net>
Allow toggling short doc in helm-M-x (#2496)
---
helm-command.el | 65 ++++++++++++++++++++++++++++++++++++++++++---------------
helm-help.el | 4 +++-
2 files changed, 51 insertions(+), 18 deletions(-)
diff --git a/helm-command.el b/helm-command.el
index f453ba0ee4..39197b0fc8 100644
--- a/helm-command.el
+++ b/helm-command.el
@@ -42,6 +42,22 @@
"Helm-M-x fuzzy matching when non nil."
:group 'helm-command
:type 'boolean)
+
+(defvar helm-M-x-map
+ (let ((map (make-sparse-keymap)))
+ (set-keymap-parent map helm-comp-read-map)
+ (define-key map (kbd "C-u") nil)
+ (define-key map (kbd "C-u") 'helm-M-x-universal-argument)
+ (define-key map (kbd "C-]") 'helm-M-x-toggle-short-doc)
+ map))
+
+(defcustom helm-M-x-show-short-doc nil
+ "Show short docstring of command when non nil.
+This value can be toggled with
+\\<helm-M-x-map>\\[helm-M-x-toggle-short-doc] while in helm-M-x session."
+ :group 'helm-command
+ :type 'boolean)
+
;;; Faces
;;
@@ -63,6 +79,10 @@
"Face used by `helm-M-x' for activated modes."
:group 'helm-command-faces)
+(defface helm-M-x-short-doc
+ '((t :box (:line-width -1) :foreground "DimGray"))
+ "Face used by `helm-M-x' for short docstring."
+ :group 'helm-command-faces)
(defvar helm-M-x-input-history nil)
(defvar helm-M-x-prefix-argument nil
@@ -101,6 +121,10 @@ Return nil if no mode-map found."
(when (and map-sym (boundp map-sym))
(helm-M-x-get-major-mode-command-alist (symbol-value map-sym)))))
+(defun helm-M-x-toggle-short-doc ()
+ (interactive)
+ (setq helm-M-x-show-short-doc (not helm-M-x-show-short-doc))
+ (helm-update (concat "^" (helm-get-selection))))
(defun helm-M-x-transformer-1 (candidates &optional sort ignore-props)
"Transformer function to show bindings in emacs commands.
@@ -111,11 +135,15 @@ Note that SORT should not be used when fuzzy matching
because
fuzzy matching is running its own sort function with a different
algorithm."
(with-helm-current-buffer
- (cl-loop with local-map = (helm-M-x-current-mode-map-alist)
+ (cl-loop with max-len = (when helm-M-x-show-short-doc
+ (cl-loop for i in candidates maximize (length
i)))
+ with local-map = (helm-M-x-current-mode-map-alist)
for cand in candidates
for local-key = (car (rassq cand local-map))
for key = (substitute-command-keys (format "\\[%s]" cand))
for sym = (intern (if (consp cand) (car cand) cand))
+ for doc = (when max-len
+ (helm-get-first-line-documentation (intern-soft cand)))
for disp = (if (or (eq sym major-mode)
(and (memq sym minor-mode-list)
(boundp sym)
@@ -125,15 +153,25 @@ algorithm."
unless (and (null ignore-props) (or (get sym 'helm-only) (get sym
'no-helm-mx)))
collect
(cons (cond ((and (string-match "^M-x" key) local-key)
- (format "%s %s"
- disp (propertize
- " " 'display
- (propertize local-key 'face
'helm-M-x-key))))
- ((string-match "^M-x" key) disp)
- (t (format "%s %s"
- disp (propertize
- " " 'display
- (propertize key 'face 'helm-M-x-key)))))
+ (format "%s %s %s %s"
+ disp
+ (if doc (make-string (+ 2 (- max-len (+ (length
cand)))) ? ) "")
+ (if doc (propertize doc 'face
'helm-M-x-short-doc) "")
+ (propertize
+ " " 'display
+ (propertize local-key 'face 'helm-M-x-key))))
+ ((string-match "^M-x" key)
+ (format "%s %s %s"
+ disp
+ (if doc (make-string (+ 2 (- max-len (+ (length
cand)))) ? ) "")
+ (if doc (propertize doc 'face
'helm-M-x-short-doc) "")))
+ (t (format "%s %s %s %s"
+ disp
+ (if doc (make-string (+ 2 (- max-len (+
(length cand)))) ? ) "")
+ (if doc (propertize doc 'face
'helm-M-x-short-doc) "")
+ (propertize
+ " " 'display
+ (propertize key 'face 'helm-M-x-key)))))
cand)
into ls
finally return
@@ -175,13 +213,6 @@ algorithm."
(push (substring (helm-cmd--get-current-function-name) 1) results))))
results))
-(defvar helm-M-x-map
- (let ((map (make-sparse-keymap)))
- (set-keymap-parent map helm-comp-read-map)
- (define-key map (kbd "C-u") nil)
- (define-key map (kbd "C-u") 'helm-M-x-universal-argument)
- map))
-
(defun helm-M-x-universal-argument ()
"Same as `universal-argument' but for `helm-M-x'."
(interactive)
diff --git a/helm-help.el b/helm-help.el
index e8bf3b36a9..5a245122e3 100644
--- a/helm-help.el
+++ b/helm-help.el
@@ -2253,12 +2253,14 @@ marking it (`C-c u' or `RET') .
*** You can get help on any command with persistent action
(\\<helm-map>\\[helm-execute-persistent-action])
+*** You can toggle short docstring description with
\\<helm-M-x-map>\\[helm-M-x-toggle-short-doc].
+
*** History source
Helm-M-x is displaying two sources, one for the commands
themselves and one for the command history, more exactly
`extended-command-history', by default the history source is
-displayed in first position, however you can put if in second
+displayed in first position, however you can put it in second
position if you don't like that by customizing
`helm-M-x-reverse-history'.