ZachMassia / PlatformIO-Mode

PlatformIO Integration for Emacs
GNU General Public License v3.0
68 stars 20 forks source link

Depend on built-in `project.el`. #24

Open fernandodemorais-jf opened 2 years ago

fernandodemorais-jf commented 2 years ago

Hello!

First of all, thanks for this great package! I've been using it for quite some time. Very neat and very useful!


Can we switch to depending on the project.el (built-in), instead of the projectile.el?

Currently, functions platformio-conditionally-enable and platformio--exec have been modified, in my local installation, to use project.el and look like this:

(defun platformio-conditionally-enable ()
  "Enable `platformio-mode' only when a `platformio.ini' file is present in project root."
  (condition-case nil
      (let* ((ini "platformio.ini")
         (files (project-files (project-current t)))
         (match (string-match-p ini (format "%s" files))))
    (when match
      (platformio-mode 1)))
    (error nil)))

(defun platformio--exec (target)
  "Call `platformio ... TARGET' in the root of the project."
  (let* ((project (project-current t))
     (default-directory (project-root project))
     (buffers (project-buffers project))
         (cmd (concat "platformio -f -c emacs " target)))
    (unless default-directory
      (user-error "Not in a project, aborting"))
    (save-some-buffers (not compilation-ask-about-save)
                       (lambda ()
                         (when (member (current-buffer) buffers)
               t)))
    (compilation-start cmd 'platformio-compilation-mode)))

There are certainly more elegant ways of doing what I did above, but the functions do their job.

If I can suggest, perhaps the usage of projectile.el could be preserved via some custom variable and some more code, for those who prefer it, but the mandatory dependency could come out with an implementation in the spirit of what I've been using in my settings.


What do you think?

Thanks!

jayemar commented 1 year ago

I would love to have the option to use project.el instead of projectile as I don't use projectile anywhere else. @fernandodemorais-jf if you already have working code I'd be happy to help you work on getting a merge request put together to submit to the project.