1
submitted 11 months ago by MrPapouille@alien.top to c/emacs@communick.news

I know it is possible to set local variables for a mode through dir-locals.el. But what could I do if I want to run a command such as:

(shell-command "sass --watch style.sass "static/css/style.css")

or activating a virtual env using:

(pyvenv-activate "env/")

top 5 comments
sorted by: hot top controversial new old
[-] rtpg@alien.top 1 points 11 months ago

for activating a virtual environment, I highly recommend checking out direnv. It has good integration with Emacs through direnv-mode, but also will handle your shell stuff for you. Pretty much fixed a lot of my tooling problems.

I am a bit curious about how one could do the shell-command thing though. In dir-locals you can exec code, but I think that would execute on every file that you open (which is probably not what you want)

[-] MrPapouille@alien.top 1 points 11 months ago

Thank you, I will take a look at direnv. The idea is to run the command once indeed. I know there is hooks when switching project, but how to use them here is out of my knowledge.

[-] rtpg@alien.top 1 points 11 months ago

One thing I found is that projectile-switch-project-action is the action invoked after switching to a project. This defaults to projectile-file-file, but you might be able to make a function that spawns the process (if it doesn't exist already of course) and then call projectile-find-file.

(figured this out by scrolling through projectile.el and looking for switch-project)

[-] MrPapouille@alien.top 1 points 11 months ago

I posted this question on Doom emacs #help 's discord, and someone suggested to use: projectile-after-switch-project-hook
I'm not sure if I can place it inside my dir-locals.el, that hook could be evaluated before reading dir-locals and if I'm correct nothing would happen so.
Anyway, those are good starting points, I will take a look and if I find a solution, come back here to let you know.

[-] sleekelite@alien.top 1 points 11 months ago

Probably don’t want to do that for python, instead do https://github.com/wyuenho/emacs-pet

this post was submitted on 23 Oct 2023
1 points (100.0% liked)

Emacs

310 readers
1 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS