Skip to content

Commit fbce3e9

Browse files
Avoid constantly checking modes in helm-M-x predicate
1 parent 6efec37 commit fbce3e9

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

helm-command.el

+12-10
Original file line numberDiff line numberDiff line change
@@ -407,16 +407,16 @@ Save COMMAND to `extended-command-history'."
407407
(helm-mode 1))
408408
(read-extended-command)))))
409409

410-
(defun helm-M-x--mode-predicate (sym cur-mode)
410+
(defun helm-M-x--mode-predicate (sym mj-mode lmm-modes)
411411
"Check if symbol SYM is suitable for current mode CUR-MODE.
412412
This predicate honors commands defined with the `interactive' MODES argument."
413413
(let ((modes (command-modes sym)))
414414
(and (commandp sym)
415415
(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))
416+
(or (memq mj-mode modes)
417+
(cl-loop for m in modes thereis
418+
(or (memq m lmm-modes)
419+
(memq m global-minor-modes))))
420420
t))))
421421

422422
;;;###autoload
@@ -438,11 +438,13 @@ You can get help on each command by persistent action."
438438
(list current-prefix-arg)))
439439
(if (or defining-kbd-macro executing-kbd-macro)
440440
(helm-M-x--vanilla-M-x)
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))))
441+
(let ((lmm-modes (buffer-local-value 'local-minor-modes (current-buffer)))
442+
(mj-mode major-mode))
443+
(helm-M-x-read-extended-command
444+
obarray (if (and (fboundp 'command-modes)
445+
helm-M-x-exclude-unusable-commands-in-mode)
446+
(lambda (sym) (helm-M-x--mode-predicate sym mj-mode lmm-modes))
447+
#'commandp)))))
446448
(put 'helm-M-x 'interactive-only 'command-execute)
447449

448450
(provide 'helm-command)

0 commit comments

Comments
 (0)