From 7d2fae3f274d8e0e08e3a61173e0d4cc5639e3d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Kryger?= Date: Sun, 29 Dec 2024 12:08:12 +0000 Subject: [PATCH 1/7] refactor(helm): Ensure bindings are present but avoid eval-after-load Using `after` uses `eval-after-load` unconditionally, which, in case of setting up bindings is an overkill, as all bindings are in global map --- modules/init-helm-projectile.el | 1 + modules/init-helm.el | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/init-helm-projectile.el b/modules/init-helm-projectile.el index 2af41076..8b34be14 100644 --- a/modules/init-helm-projectile.el +++ b/modules/init-helm-projectile.el @@ -90,6 +90,7 @@ project's file using completion and show it in another window." (helm-projectile-on))) (use-package treemacs-projectile + :defer t :bind (("C-c e" . #'treemacs) ("C-c E" . #'treemacs-projectile))) diff --git a/modules/init-helm.el b/modules/init-helm.el index 2c696b87..5f37bafb 100644 --- a/modules/init-helm.el +++ b/modules/init-helm.el @@ -66,12 +66,12 @@ (helm-mode)) (use-package helm-descbinds - :after (helm) + :defer t :bind - (("C-h b" . #'helm-descbinds))) + ("C-h b" . #'helm-descbinds)) (use-package helm-ag - :after (helm) + :defer t :custom (helm-ag-insert-at-point 'symbol) :bind @@ -79,23 +79,22 @@ ("C-S-f" . #'helm-do-ag-this-file))) (use-package helm-ag - :after (helm) + :defer t :unless exordium-helm-projectile :bind - (("C-S-a" . #'helm-ag-project-root))) + ("C-S-a" . #'helm-ag-project-root)) (use-package helm-rg - :after (helm) :defer t) (use-package helm-rg - :after (helm) :unless exordium-helm-projectile + :defer t :bind - (("C-S-r" . #'helm-rg))) + ("C-S-r" . #'helm-rg)) (use-package helm-swoop - :after (helm) + :defer t :commands (helm-swoop--edit-complete helm-swoop--edit-cancel helm-swoop--edit-delete-all-lines) From 3901bb22147f2b25d92054c4a8bffa1e171f30ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Kryger?= Date: Sun, 29 Dec 2024 12:08:39 +0000 Subject: [PATCH 2/7] feat(helm): Add keybinding to switch form isearch to helm-swoop --- modules/init-helm.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/init-helm.el b/modules/init-helm.el index 5f37bafb..0890f42e 100644 --- a/modules/init-helm.el +++ b/modules/init-helm.el @@ -95,6 +95,14 @@ (use-package helm-swoop :defer t + :init + (use-package isearch + :ensure nil + :defer t + :bind + (:map isearch-mode-map + ("C-S-s" . #'helm-swoop-from-isearch))) + :commands (helm-swoop--edit-complete helm-swoop--edit-cancel helm-swoop--edit-delete-all-lines) From c2b91a8d38b05a5ab9386a15a3bdbe62e0ba9bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Kryger?= Date: Fri, 10 Jan 2025 13:18:35 +0000 Subject: [PATCH 3/7] feat(helm): Add extra keybindings Add a new keybinding for Google suggest and remap `switch-to-buffer` to `helm-buffers-list`, which offers a couple alternative actions on buffers. Also turn on detailed completions. --- README.md | 1 + modules/init-helm.el | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/README.md b/README.md index 932185ab..37bbefbe 100644 --- a/README.md +++ b/README.md @@ -349,6 +349,7 @@ Keybinding | Description M-y | Select yank pop. C-x b | Switch buffer. C-x C-f | Find file. +C-x c g | Google suggest. #### Other Helm tools diff --git a/modules/init-helm.el b/modules/init-helm.el index 0890f42e..cf4cc2ce 100644 --- a/modules/init-helm.el +++ b/modules/init-helm.el @@ -18,6 +18,7 @@ ;; C-S-a Search with Ag: in current project root. ;; See also`init-helm-porojectile.el'. ;; C-S-s Helm Swoop +;; C-x c g Helm Google suggest. ;;; Code: @@ -28,6 +29,9 @@ (use-package helm :diminish + :bind + (:map helm-command-map + ("g" . #'helm-google-suggest)) :custom (helm-split-window-default-side 'other) (helm-split-window-other-side-when-one-window 'right) From e45dd5c28f9631dedb78571aad58243e7fa69310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Kryger?= Date: Sun, 29 Dec 2024 12:09:14 +0000 Subject: [PATCH 4/7] feat!: Prevent helm-xref messing up with xref unless helm-everywhere `helm-xref` unconditionally hijacks `xref-show-xrefs-function` and `xref-show-definitions-function`. I don't think this is expected. BREAKING CHANGE: don't install `helm-xref` unless in `exordium-helm-everywhere` --- modules/init-helm.el | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/modules/init-helm.el b/modules/init-helm.el index cf4cc2ce..9485605e 100644 --- a/modules/init-helm.el +++ b/modules/init-helm.el @@ -120,12 +120,9 @@ ("C-c C-k" . #'helm-swoop--edit-cancel) ("C-c C-q C-k" . #'helm-swoop--edit-delete-all-lines))) -(use-package helm-xref - :after helm - :if exordium-helm-everywhere - :commands helm-xref - :config - (setq xref-show-xrefs-function 'helm-xref-show-xrefs)) +(when exordium-helm-everywhere + (use-package helm-xref + :defer t)) From bdedd8a1737049e7e6fd5163399a51e43aa0d9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Kryger?= Date: Tue, 14 Jan 2025 12:26:37 +0000 Subject: [PATCH 5/7] refactor(helm)!: `switch-to-buffer` functions now show affixation Need to use generic `completing-read` framework to get affixation to work. The latter however doesn't have any actions defined, so copying relevant attributes from `helm-source-buffers-list`. BREAKING CHANGE: When `exordium-helm-everywhere` the binding `C-x b` now points to `switch-to-buffer` (was: `helm-buffers-list`). This is consistent with other bindings (for example `C-x 4 b` - `switch-to-buffer-other-window`), but some extra behaviour from `helm-buffers-list` is not available (i.e., candidate buffers sorting and highlighting). --- modules/init-helm.el | 89 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 2 deletions(-) diff --git a/modules/init-helm.el b/modules/init-helm.el index 9485605e..66671a95 100644 --- a/modules/init-helm.el +++ b/modules/init-helm.el @@ -54,19 +54,104 @@ (use-package helm :diminish :when exordium-helm-everywhere + :functions (exordium--helm-swith-to-buffer-update-sources + exordium--helm-switch-to-buffer-completing-read) + :init + (use-package helm-lib + :ensure helm + :defer t + :autoload (helm-this-command + helm-symbol-name + helm-get-attr + helm-set-attr + helm-mklist)) + (use-package helm-mode + :ensure helm + :defer t + :autoload (helm-completing-read-default-handler)) + (use-package helm-source + :ensure helm + :defer t + :autoload (helm-make-source)) + + (defun exordium--helm-swith-to-buffer-update-sources (&rest args) + "Copy relevant attributes from a `helm-source-buffers' to `:sources' in ARGS." + (if-let* ((args (car args)) + ((plistp args)) + (sources (cl-remove-if (lambda (source) + (equal "Unknown candidate" + (helm-get-attr 'name source))) + (plist-get args :sources))) + (source-buffers (helm-make-source "Buffers" 'helm-source-buffers))) + (progn + (dolist (source sources) + (helm-set-attr 'filtered-candidate-transformer + (append '(helm-skip-boring-buffers) + (helm-get-attr 'filtered-candidate-transformer + source)) + source) + (dolist (attr '(keymap + action + persistent-action + persistent-help + help-message + match + mode-line + heder-line + find-file-target)) + (helm-set-attr attr + (helm-get-attr attr source-buffers) + source))) + (plist-put args + :sources (append sources + (list helm-source-buffer-not-found)))) + args)) + + (defun exordium--helm-switch-to-buffer-completing-read (&rest args) + ; checkdoc-params: (args) + "Ensure `helm-source-buffers' attributes are used." + (let* ((current-command (or (helm-this-command) this-command)) + (str-command (if current-command + (helm-symbol-name current-command) + "completing-read")) + (buf-name (format "*%s*" str-command))) + (unwind-protect + (progn + (advice-add + 'helm + :filter-args #'exordium--helm-swith-to-buffer-update-sources) + + (apply #'helm-completing-read-default-handler + (append args + (list str-command buf-name)))) + (advice-remove + 'helm #'exordium--helm-swith-to-buffer-update-sources)))) + :custom (history-delete-duplicates t) (helm-M-x-always-save-history t) (helm-M-x-show-short-doc t) + (completions-detailed exordium-help-extensions) + :bind (([remap execute-extended-command] . #'helm-M-x) ; M-x ([remap yank-pop] . #'helm-show-kill-ring) ; M-y ([remap find-file] . #'helm-find-files) ; C-x C-f ([remap find-file-read-only] . #'helm-recentf)) ; C-x C-r + :config ;; Do not show these files in helm buffer - (add-to-list 'helm-boring-file-regexp-list "\\.tsk$") - (add-to-list 'helm-boring-file-regexp-list "\\.log\\.") + (dolist (pat (list (rx ".tsk" string-end) + (rx ".log."))) + (add-to-list 'helm-boring-file-regexp-list pat)) + + (require 'helm-mode) + (dolist (fun '(switch-to-buffer + switch-to-buffer-other-frame + switch-to-buffer-other-tab + switch-to-buffer-other-window)) + (add-to-list 'helm-completing-read-handlers-alist + (cons fun #'exordium--helm-switch-to-buffer-completing-read))) (helm-mode)) (use-package helm-descbinds From 9c95fdc5087245cc0b4d50203e0c7489b0149b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Kryger?= Date: Tue, 14 Jan 2025 15:19:05 +0000 Subject: [PATCH 6/7] feat(helm-projectile): add affixation function This is done in an attempt to provide a consistent interface when switching to a buffer, and is hidden behind `exordium-extra-help` flag. This is done similarily to what Exordium does for `switch-to-buffer` and `helpful` commands do under the hood. Both of these, when `completions-detailed` is non-nil use `helm-completing-read-extra-metadata` to select an affixation function. --- modules/init-helm-projectile.el | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/modules/init-helm-projectile.el b/modules/init-helm-projectile.el index 8b34be14..7741ca4a 100644 --- a/modules/init-helm-projectile.el +++ b/modules/init-helm-projectile.el @@ -86,6 +86,40 @@ project's file using completion and show it in another window." (helm-add-action-to-source "ripgrep (rg) in project `C-S-r'" #'exordium-helm-projectile--switch-project-and-do-rg helm-source-projectile-projects) + ;; The following lambda is constructed similarly to what + ;; `helm-completing-read-default-1' does. However, it's calculated once on + ;; startup (when `helm-projectile' package is configured) and not on each + ;; `helm-projectile-switch-to-buffer'/`helm-projectile' call (which is how + ;; original behaves). This has been done in an attempt to making this + ;; solution slightly simpler as we need to modify a helm-source prototype + ;; which would be cumbersome to do dynamically. Caveat is that it doesn't + ;; let user to use their desired annotation or affixation function via + ;; `completion-extra-properties' when `completions-detailed' is non-nil. + (when exordium-help-extensions + (let* ((metadata (completion-metadata "" 'internal-complete-buffer nil)) + (category (completion-metadata-get metadata 'category)) + (sort-fn (unless (eq helm-completion-style 'helm-fuzzy) + (or + (completion-metadata-get + metadata 'display-sort-function) + (lambda (candidates) + (sort candidates #'helm-generic-sort-fn))))) + (metadata (assoc-default category helm-completing-read-extra-metadata)) + (afun (completion-metadata-get metadata 'annotation-function)) + (afix (completion-metadata-get metadata 'affixation-function))) + (when (or afun afix) + (helm-set-attr + 'filtered-candidate-transformer + (list + 'helm-skip-boring-buffers + (lambda (candidates _source) + (helm-completion--decorate + (if (and sort-fn (> (length helm-pattern) 0)) + (funcall sort-fn candidates) + candidates) + afun afix category))) + helm-source-projectile-buffers-list)))) + (when exordium-helm-everywhere (helm-projectile-on))) From 51f0824d6820c0f02719270395bb7e23b38cf7fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Kryger?= Date: Mon, 13 Jan 2025 15:02:13 +0000 Subject: [PATCH 7/7] doc(helm): Bump helm sections one level up --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 37bbefbe..1dccd765 100644 --- a/README.md +++ b/README.md @@ -334,7 +334,7 @@ Keybinding | Description See [Projectile](https://github.com/bbatsov/projectile) documentation for other keys. -### Helm +## Helm Helm can be set up as a primary completion and selection narrowing framework for most commonly used functions. You can achieve that by setting @@ -351,7 +351,7 @@ Keybinding | Description C-x C-f | Find file. C-x c g | Google suggest. -#### Other Helm tools +### Other Helm tools Helm is a pretty good when you need quickly scan search results. The commands below will start different search modes. By default, they will use symbol under the point.