0

I've remapped C-x C-f to projectile-find-file since I mostly open files corresponding to the project I'm in. However when I need to create a new file, I fill in the name and projectile doens't find the file, it returns to the buffer I was previously in when pressing ENTER. I googled a bit and found this question on github (https://github.com/bbatsov/projectile/issues/869) with a link to a reddit post. I tried implementing this in my init.el file, but I still can't create a new file.

What am I doing wrong? This is the config in my init.el file.

(require 'helm-projectile)
(setq helm-projectile-on t)
(setq projectile-indexing-method 'native)

(defun maybe-projectile-find-file ()
  (interactive)
  (call-interactively
   (if (projectile-project-p)
       #'projectile-find-file
       #'helm-find-files)))

(global-set-key (kbd "C-x C-f") 'maybe-projectile-find-file)

;; create new file when not exist in current project:
(with-eval-after-load 'helm-projectile
  (defvar helm-source-file-not-found
    (helm-build-dummy-source
        "Create file"
      :action (lambda (cand) (find-file cand))))

  (add-to-list 'helm-projectile-sources-list helm-source-file-not-found t))

(defun maybe-projectile-switch-to-buffer ()
  (interactive)
  (call-interactively
   (if (projectile-project-p)
       #'projectile-switch-to-buffer
       #'helm-mini)))

(global-set-key (kbd "C-x b") 'maybe-projectile-switch-to-buffer)

Your Answer

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

Browse other questions tagged or ask your own question.