Just recently discovered use-package (a macro written by John Wiegley) that comes in handy if you want to avoid .emacs bankruptcy declaration and keep things tidy in your configuration dot file.

After reading the documentation above, and while cleaning up my config code, I found myself clueless as to what would be the best practice to setup Helm mode. Being extensible, many packages have been added in thehelm-foo and helm-bar manner; each comes with its own configuration setup in dot Emacs file. So which construct is considered more efficient?

Scenario 1 (each separate)

(use-package helm
:demand t
:bind ("M-x" . helm-M-x)
:config...
  (helm-mode 1)
)

(use-package helm-descbinds
:config 
(helm-descbinds-mode))

Scenario 2 (nested with require)

(use-package helm
:demand t
:bind ("M-x" . helm-M-x)
:config...
  (require 'helm-descbinds)
  (helm-descbinds-mode)
  (helm-mode 1)
)

Scenario 3 (nested with use-package)

(use-package helm
:demand t
:bind ("M-x" . helm-M-x)
:config...
  (use-package helm-descbinds
  :config (helm-descbinds-mode))
  (helm-mode 1)
)

Obviously helm-descbinds was mentioned here just for sake of illustrating the use case, and in reality there are many other helms waiting in the laundry list.

Another question, what would be the best practice to include the code below inside helm configuration with use-package?

  (require 'helm-eshell)
  (add-hook 'eshell-mode-hook
        #'(lambda ()
        (define-key eshell-mode-map (kbd "C-c C-l")  'helm-eshell-history))) 

Changing above to:

  (use-package helm-eshell
    :bind (:map eshell-mode-map
        ("C-c C-l" . helm-eshell-history)))

The key binding did't work in eshell mode as expected. Any reason why?

My Whole Current Helm Config

(use-package helm
  ;; The default "C-x c" is quite close to "C-x C-c", which quits Emacs.
  ;; Changed to "C-c h". Note: We must set "C-c h" globally, because we
  ;; cannot change `helm-command-prefix-key' once `helm-config' is loaded.
  :demand t
  :bind (("M-x" . helm-M-x)
     ("C-c h o" . helm-occur)
     ("<f1> SPC" . helm-all-mark-rings) ; I modified the keybinding 
     ("M-y" . helm-show-kill-ring)
     ("C-c h x" . helm-register)    ; C-x r SPC and C-x r j
     ("C-c h g" . helm-google-suggest)
     ("C-c h M-:" . helm-eval-expression-with-eldoc)
     ("C-x C-f" . helm-find-files)
     ("C-x b" . helm-mini)      ; *<major-mode> or /<dir> or !/<dir-not-desired> or @<regexp>
     :map helm-map
     ("<tab>" . helm-execute-persistent-action) ; rebind tab to run persistent action
     ("C-i" . helm-execute-persistent-action) ; make TAB works in terminal
     ("C-z" . helm-select-action) ; list actions using C-z
     :map shell-mode-map
     ("C-c C-l" . helm-comint-input-ring) ; in shell mode
     :map minibuffer-local-map
     ("C-c C-l" . helm-minibuffer-history))
  :init
  (setq helm-command-prefix-key "C-c h")
  (setq recentf-save-file "~/.emacs.d/misc/recentf" ; customize yours
    recentf-max-saved-items 50)
  (require 'helm-eshell)        ; question
  (add-hook 'eshell-mode-hook
        #'(lambda ()
        (define-key eshell-mode-map (kbd "C-c C-l")  'helm-eshell-history))) 
  (defun spacemacs//helm-hide-minibuffer-maybe ()
  "Hide minibuffer in Helm session if we use the header line as input field."
  (when (with-helm-buffer helm-echo-input-in-header-line)
    (let ((ov (make-overlay (point-min) (point-max) nil nil t)))
      (overlay-put ov 'window (selected-window))
      (overlay-put ov 'face
                   (let ((bg-color (face-background 'default nil)))
                     `(:background ,bg-color :foreground ,bg-color)))
      (setq-local cursor-type nil))))
  :config
  (when (executable-find "curl")
    (setq helm-google-suggest-use-curl-p t))
  (setq helm-M-x-fuzzy-match t)
  (setq helm-buffers-fuzzy-matching t
    helm-recentf-fuzzy-match    t)
  (setq helm-semantic-fuzzy-match t
    helm-imenu-fuzzy-match    t)
  (setq helm-locate-fuzzy-match t)
  (setq helm-apropos-fuzzy-match t)
  (setq helm-lisp-fuzzy-completion t)
  (add-to-list 'helm-sources-using-default-as-input 'helm-source-man-pages)
  (require 'helm-descbinds)
  (helm-descbinds-mode)
  (projectile-global-mode)
  (setq projectile-completion-system 'helm)
  (helm-projectile-on)
  (require 'helm-config)
  (setq helm-split-window-in-side-p         t ; open helm buffer inside current window, not occupy whole other window
      helm-move-to-line-cycle-in-source     t ; move to end or beginning of source when reaching top or bottom of source.
      helm-ff-search-library-in-sexp        t ; search for library in `require' and `declare-function' sexp.
      helm-scroll-amount                    8 ; scroll 8 lines other window using M-<next>/M-<prior>
      helm-ff-file-name-history-use-recentf t
      helm-echo-input-in-header-line t)
  (add-hook 'helm-minibuffer-set-up-hook
        'spacemacs//helm-hide-minibuffer-maybe)
  (setq helm-autoresize-max-height 0)
  (setq helm-autoresize-min-height 20)
  (helm-autoresize-mode 1)
  (helm-mode 1)
  )

Notes

  • GNU Emacs 25.2.2 (x86_64-pc-linux-gnu, GTK+ Version 3.18.9) of 2017-05-06

closed as too broad by Drew, Stefan, Dan Jul 22 '17 at 15:51

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Regarding eshell, with or without use-package, you still need to use eshell-mode-hook since at least eshell-mode-map is a buffer-local variable. – xuchunyang Jul 20 '17 at 2:50
  • Too broad, IMHO. Too many questions. And a bit of "please improve my code". Please see the guidelines for what makes for a good SE question. There might be more than one good question in there somewhere... – Drew Jul 20 '17 at 4:06
  • The main thing is: which scenario (of the three see above) of Helm setup would be better in use-package syntax? Everything else is plus. – doctorate Jul 20 '17 at 4:20
  • @xuchunyang good to know and this explains why it didn't work in my trial of re-writing it differently. – doctorate Jul 20 '17 at 11:26
  • Which scenario is "better" sounds like a question that invites primarily opinion-based answers - another reason to close the question. But again, there might well be a good, specific question or two hidden within this one. – Drew Jul 20 '17 at 21:55