Skip to content

Instantly share code, notes, and snippets.

@spott
Created October 5, 2016 16:19
Show Gist options
  • Save spott/145dae38a59bb543524f434665c5c6ee to your computer and use it in GitHub Desktop.
Save spott/145dae38a59bb543524f434665c5c6ee to your computer and use it in GitHub Desktop.
platformio-mode layer
(setq pio-packages
'(
(platformio-mode :toggle (configuration-layer/package-usedp 'projectile))
))
(defun pio/init-platformio-mode ()
(use-package platformio-mode
:defer t
:init
(progn
(defun conditionally-enable ()
"Enable `platformio-mode' only when a `platformio.ini' file is present in project root."
(condition-case nil
(when (projectile-verify-file "platformio.ini")
(platformio-mode 1))
(error nil)))
(add-hook 'c++-mode-hook (conditionally-enable))
(add-hook 'c-mode-hook (conditionally-enable)))
:config
(progn
(platformio-setup-compile-buffer)
(spacemacs/set-leader-keys-for-major-mode 'c++-mode
"pb" 'platformio-build
"pu" 'platformio-upload
"pp" 'platformio-programmer-upload
"ps" 'platformio-spiffs-upload
"pc" 'platformio-clean
"pd" 'platformio-update
)
)))
@spott
Copy link
Author

spott commented Oct 5, 2016

This doesn't appear to work. projectile-verify-file doesn't appear to be in scope during the :init part of use-package. It also doesn't appear to be in scope at the end of the

@LeartS
Copy link

LeartS commented Nov 22, 2016

platformio-mode already provides a platformio-conditionally-enable function which is identical to your conditionally-enable here. To use it in the :init of use-package, you have to make it autoloadable using the :commands key, like here .

I am trying to create a good and complete platformio layer there, if you want you help you're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment