7

I am able to add few extra sources to helm like this

(setq helm-mini-default-sources '(helm-source-buffers-list
                                  helm-source-recentf
                                  helm-source-dired-recent-dirs
                                  helm-chrome-source
                                  hgs/helm-c-source-stars
                                  hgs/helm-c-source-repos
                                  hgs/helm-c-source-search
                                  helm-source-buffer-not-found))

The last thing i need to add to this is helm-M-x. I just need to add all commands to default sources. By this i can invoke a single function and I can go to anything or i can invoke any command.

But helm-M-x is a function and its source-code doesn't have any sources. Any help on how to achieve this?

1
  • Why about creating Emacs commands source by yourself?
    – xuchunyang
    Jun 30 '15 at 3:09
4
(defvar helm-source-emacs-commands
  (helm-build-sync-source "Emacs commands"
    :candidates (lambda ()
                  (let ((cmds))
                    (mapatoms
                     (lambda (elt) (when (commandp elt) (push elt cmds))))
                    cmds))
    :coerce #'intern-soft
    :action #'command-execute)
  "A simple helm source for Emacs commands.")

;; Try it
(helm :sources helm-source-emacs-commands)
2
4

Based on xuchunyang's answer, I was able to add helm-M-x to helm sources.

(defvar helm-source-emacs-commands
  (helm-build-sync-source "Emacs commands"
    :candidates (lambda ()
                  (let ((cmds))
                    (mapatoms
                     (lambda (elt) (when (commandp elt) (push elt cmds))))
                    cmds))
    :coerce #'intern-soft
    :action #'command-execute)
  "A simple helm source for Emacs commands.")

(defvar helm-source-emacs-commands-history
  (helm-build-sync-source "Emacs commands history"
    :candidates (lambda ()
                  (let ((cmds))
                    (dolist (elem extended-command-history)
                      (push (intern elem) cmds))
                    cmds))
    :coerce #'intern-soft
    :action #'command-execute)
  "Emacs commands history")

(setq helm-mini-default-sources '(helm-source-emacs-commands-history
                                  helm-source-emacs-commands))
1
  • Great, this helps me a lot for helm-for-files.
    – ReneFroger
    Jul 2 '15 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.