sebastiencs / omnibox

Lightweight completion/selection system for Emacs
53 stars 3 forks source link

Omnibox and Projectile #1

Open tsmarques opened 6 years ago

tsmarques commented 6 years ago

Hi,

this seems like a great package and I'd like to apply it to some projectile functions. Is there any documentation, or tips on creating a new "handler", e.g for projectile-switch-project?

Thanks, tsm

sebastiencs commented 6 years ago

Hi @tsmarques, I'm glad you like it ! I will update the readme and add some documentation. The function you can use is omnibox:

(omnibox
 :prompt "super prompt: "
 :candidates '("word" "another" "one" "project")
 :title " my feature ")
tsmarques commented 6 years ago

Hi,

thanks for the answer. With that I was able to come up with the following:

(defun omnibox-projectile-switch-project nil
      (interactive)
      (omnibox
       :prompt "Projects: "
       :candidates projectile-known-projects
       :action (lambda (candidate)
                 (projectile-switch-project-by-name candidate))
       :title "Switch Project: "))

to show a list of known projects and do the switch. Though this calls projectile-switch-project-action which will prompt the project's files with either Helm or other completion system. By using

    (defun omnibox-projectile-find-file nil
          (interactive)
          (let* ((omnibox-projectile-project-root (projectile-project-root)))
          (omnibox
           :prompt (format "[%s]: " (projectile-project-name))
           :candidates (projectile-current-project-files)
           :action (lambda (candidate)
                     (find-file (expand-file-name candidate omnibox-projectile-project-root)))
           :title "Open File: ")))

    (setq projectile-switch-project-action 'omnibox-projectile-find-file)

it works well.

I had to use let because as soon the (omnibox bit was executed (projectile-project-root) pointed again to my emacs config's root directory.