@@ -59,6 +59,12 @@ This value can be toggled with
59
59
" When nil, do not sort helm-M-x's commands history."
60
60
:type 'boolean )
61
61
62
+ (defcustom helm-M-x-exclude-unusable-commands-in-mode nil
63
+ " When non nil exclude commands not usable in current buffer.
64
+ This will exclude only commands defined with `interactive' MODES argument, for
65
+ other commands, they will be displayed even if unusable as lon as they satisfies
66
+ `commandp' ."
67
+ :type 'boolean )
62
68
63
69
; ;; Faces
64
70
; ;
@@ -401,6 +407,18 @@ Save COMMAND to `extended-command-history'."
401
407
(helm-mode 1 ))
402
408
(read-extended-command )))))
403
409
410
+ (defun helm-M-x--mode-predicate (sym cur-mode )
411
+ " Check is symbol SYM is suitable for current mode CUR-MODE.
412
+ This predicate honors commands defined with the `interactive' MODES argument."
413
+ (let ((modes (command-modes sym)))
414
+ (and (commandp sym)
415
+ (if modes
416
+ (or (memq cur-mode modes)
417
+ (memq (car modes)
418
+ (buffer-local-value 'local-minor-modes helm-current-buffer))
419
+ (memq (car modes) global-minor-modes))
420
+ t ))))
421
+
404
422
;;;### autoload
405
423
(defun helm-M-x (_arg )
406
424
" Preconfigured `helm' for Emacs commands.
@@ -420,7 +438,11 @@ You can get help on each command by persistent action."
420
438
(list current-prefix-arg)))
421
439
(if (or defining-kbd-macro executing-kbd-macro)
422
440
(helm-M-x--vanilla-M-x)
423
- (helm-M-x-read-extended-command obarray)))
441
+ (helm-M-x-read-extended-command
442
+ obarray (if (and (fboundp 'command-modes )
443
+ helm-M-x-exclude-unusable-commands-in-mode)
444
+ (lambda (sym ) (helm-M-x--mode-predicate sym major-mode))
445
+ #'commandp ))))
424
446
(put 'helm-M-x 'interactive-only 'command-execute )
425
447
426
448
(provide 'helm-command )
0 commit comments