Skip to content

Commit

Permalink
[helm] Provide fuzzy matching for Helm-M-x
Browse files Browse the repository at this point in the history
Following the advice from duianto #13100 we are
setting completion-styles for helm-M-x to include
the emacs version specific fuzzy strategy as last
resort.

Before no fuzzy matching occured within command
searches.
  • Loading branch information
smile13241324 committed May 11, 2020
1 parent f9ffb8d commit c7ed2fc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
35 changes: 22 additions & 13 deletions layers/+completion/helm/funcs.el
Expand Up @@ -114,8 +114,8 @@ If DEFAULT-INPUTP is non nil then the current region or symbol at point
(interactive)
(call-interactively
(spacemacs//helm-do-search-find-tool "helm-file-do"
dotspacemacs-search-tools
default-inputp)))
dotspacemacs-search-tools
default-inputp)))

(defun spacemacs/helm-file-smart-do-search-region-or-symbol ()
"Search in current file using `dotspacemacs-search-tools' with
Expand Down Expand Up @@ -183,8 +183,8 @@ If DEFAULT-INPUTP is non nil then the current region or symbol at point
(interactive)
(call-interactively
(spacemacs//helm-do-search-find-tool "helm-files-do"
dotspacemacs-search-tools
default-inputp)))
dotspacemacs-search-tools
default-inputp)))

(defun spacemacs/helm-files-smart-do-search-region-or-symbol ()
"Search in files using `dotspacemacs-search-tools' with default input.
Expand Down Expand Up @@ -247,8 +247,8 @@ If DEFAULT-INPUTP is non nil then the current region or symbol at point
(interactive)
(call-interactively
(spacemacs//helm-do-search-find-tool "helm-dir-do"
dotspacemacs-search-tools
default-inputp)))
dotspacemacs-search-tools
default-inputp)))

(defun spacemacs/helm-dir-smart-do-search-region-or-symbol ()
"Search in current directory using `dotspacemacs-search-tools'.
Expand Down Expand Up @@ -313,8 +313,8 @@ If DEFAULT-INPUTP is non nil then the current region or symbol at point
(interactive)
(call-interactively
(spacemacs//helm-do-search-find-tool "helm-buffers-do"
dotspacemacs-search-tools
default-inputp)))
dotspacemacs-search-tools
default-inputp)))

(defun spacemacs/helm-buffers-smart-do-search-region-or-symbol ()
"Search in opened buffers using `dotspacemacs-search-tools' with
Expand Down Expand Up @@ -412,8 +412,8 @@ If DEFAULT-INPUTP is non nil then the current region or symbol at point
(let ((projectile-require-project-root nil))
(call-interactively
(spacemacs//helm-do-search-find-tool "helm-project-do"
dotspacemacs-search-tools
default-inputp))))
dotspacemacs-search-tools
default-inputp))))

(defun spacemacs/helm-project-smart-do-search-region-or-symbol ()
"Search in current project using `dotspacemacs-search-tools' with
Expand Down Expand Up @@ -600,9 +600,9 @@ to buffers)."
(with-current-buffer "*helm ag results*"
(setq spacemacs--gne-min-line 5
spacemacs--gne-max-line (save-excursion
(goto-char (point-max))
(previous-line)
(line-number-at-pos))
(goto-char (point-max))
(previous-line)
(line-number-at-pos))
spacemacs--gne-line-func
(lambda (c)
(helm-ag--find-file-action
Expand Down Expand Up @@ -636,3 +636,12 @@ to buffers)."
(interactive)
(let ((helm-boring-buffer-regexp-list nil))
(call-interactively #'helm-buffers-list)))

;; Command search ---------------------------------------------------------------------

(defun spacemacs/helm-M-x-fuzzy-matching ()
"Helm M-x with fuzzy matching enabled"
(interactive)
(let ((completion-styles completion-styles))
(add-to-list 'completion-styles `,(if (version< emacs-version "27") 'helm-flex 'flex) t)
(command-execute 'helm-M-x)))
8 changes: 4 additions & 4 deletions layers/+completion/helm/packages.el
Expand Up @@ -80,7 +80,7 @@
(evil-ex-define-cmd "buffers" 'helm-buffers-list))
;; use helm by default for M-x, C-x C-f, and C-x b
(unless (configuration-layer/layer-usedp 'smex)
(global-set-key (kbd "M-x") 'helm-M-x))
(global-set-key (kbd "M-x") 'spacemacs/helm-M-x-fuzzy-matching))
(global-set-key (kbd "C-x C-f") 'spacemacs/helm-find-files)
(global-set-key (kbd "C-x b") 'helm-buffers-list)
;; use helm everywhere
Expand Down Expand Up @@ -122,8 +122,8 @@
(kbd "C-c C-e") 'spacemacs/helm-find-files-edit)
(defun spacemacs//add-action-helm-find-files-edit ()
(helm-add-action-to-source
"Edit files in dired `C-c C-e'" 'spacemacs//helm-find-files-edit
helm-source-find-files))
"Edit files in dired `C-c C-e'" 'spacemacs//helm-find-files-edit
helm-source-find-files))
(add-hook 'helm-find-files-before-init-hook
'spacemacs//add-action-helm-find-files-edit))
;; Add minibuffer history with `helm-minibuffer-history'
Expand Down Expand Up @@ -151,7 +151,7 @@
;; to overwrite any key binding
(unless (configuration-layer/layer-usedp 'smex)
(spacemacs/set-leader-keys
dotspacemacs-emacs-command-key 'helm-M-x)))))
dotspacemacs-emacs-command-key 'spacemacs/helm-M-x-fuzzy-matching)))))
:config
(progn
(helm-mode)
Expand Down
2 changes: 1 addition & 1 deletion layers/+misc/multiple-cursors/packages.el
Expand Up @@ -57,7 +57,7 @@
"smst" 'mc/reverse-regions)
(setq mc/always-run-for-all t)
(with-eval-after-load 'multiple-cursors-core
(add-to-list 'mc/cmds-to-run-once 'helm-M-x)
(add-to-list 'mc/cmds-to-run-once 'spacemacs/helm-M-x-fuzzy-matching)
(add-to-list 'mc/cmds-to-run-once 'counsel-M-x)
(add-to-list 'mc/cmds-to-run-once 'spacemacs/default-pop-shell)
))))

0 comments on commit c7ed2fc

Please sign in to comment.