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?

  • 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)
  • i tried to build another source just like this gist.github.com/ChillarAnand/23119413409f00b7e995#file-helm-el but it didn't work as expected? – ChillarAnand Jul 1 '15 at 15:08
  • I've tried yours, it works fine, but just for the histroy of Emacs commands, so you have to use helm-M-x to run some commands to build that history first, because helm doesn't save history across session by default. – xuchunyang Jul 2 '15 at 2:01
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))
  • 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.