Writing your own Emacs interactive functions with completion

Here’s how to use Ido in Emacs to write your own interactive functions with completion. In this example, we’ll make a function that completes directories but Ido provides functions for reading files, buffers, and more.

This function will go to the given repo in my dev directory, and if that repo isn’t cloned yet, will clone it from my GitHub first.

(defun tj-goto (repo)
  "Go to or clone the given dev `repo'."
  (interactive
   (list
    (ido-read-directory-name "Directory: " "~/dev/")))
  (let* ((dev-dir "~/dev/")
         (repo-dir repo))
    (if (file-exists-p repo-dir)
        (projectile-find-file-in-directory repo)
      (shell-command (format "cd %s; git clone [email protected]:travisjeffery/%s.git" dev-dir repo))
      (projectile-find-file-in-directory repo))))