Fork me on GitHub
#emacs
<
2019-11-26
>
Jcaw09:11:03

Doom has a Discord and Spacemacs has a Gitter. Both are pretty active.

Jcaw09:11:25

The /r/emacs subreddit is the de-facto social hub for Emacs. Its pretty good but users can be a mixed bag. Some will give you measured advice, some are zealous to a particular approach.

Jcaw09:11:59

If you want to see a bunch of different workflows, look at Sacha Chua's Emacs Chats. She interviews a few famous names from the diaspora and they break down how they use Emacs. Steve Purcell is a good one to start with - he's the guy in charge of MELPA. https://pages.sachachua.com/emacs-chats/

Lucas Barbosa14:11:00

Hey, with Cursive I am able to know which symbols in a namespace are not being used in the project. The symbols are kind of faded/gray. Is there a way to have that information in Emacs?

dpsutton14:11:16

lsp can provide this information

Lucas Barbosa14:11:14

Is there a known way to do it? I'm using Cider but I'm not sure if this is available Wait, that seems to be a completely different thing. I'll try it out! Thanks

practicalli-johnny15:11:45

@lvbarbosa 'clj-kondo' will highlight unused symbols in the namespace as you are typing, includes ns requres too. Just need to install its binary and add flycheck-clj-kondo for Emacs...

Lucas Barbosa15:11:17

@jr0cket I am using it already, but what I need is unused symbols across the entire project.. something like static analysis.. It seems that lsp is what I need

borkdude15:11:57

@lvbarbosa Do you mean unused vars in the entire project?

borkdude15:11:17

(a symbol is not always a var, that's why I'm asking)

Lucas Barbosa15:11:52

Yes! Unused vars. What I am actually doing is: I have a project that depends on an internal lib, but that lib has been deprecated. I am “slurping” into my project the pieces of that library that I need. The process is: I copy the namespace from the deprecated library into my project and delete what I don’t need. In Cursive, I easily know what is not being used, since the editor highlights the vars that are not being used. In emacs I don’t have that ability. It looks like lsp makes that work. What do you think? @borkdude

borkdude15:11:54

@lvbarbosa Clj-kondo can do that too, but it doesn't do it while linting, since the user might not have linted the entire project yet (kind of an open world assumption) But it can be done using the analysis output: https://github.com/borkdude/clj-kondo/tree/master/analysis#unused-vars

borkdude15:11:45

So that would not be an in-editor kind of feedback, but data you use for whatever purpose you want

Lucas Barbosa20:11:19

Is there any possibility of getting that into the editor? :thinking_face: I have no idea of how difficult that would be

Lucas Barbosa20:11:43

I love the way Cursive does it.. I am currently using it to perform this sort of task

borkdude21:11:34

@lvbarbosa The reason clj-kondo doesn't do this is that in the editor it lints only one single file at a time and fetches information it needs additionally from the cache. But to know if a var is used in some other namespace, it would have to lint all the other files and/or read the entire cache, which is not good for performance

Lucas Barbosa21:11:13

That makes sense. Is lsp the "standard" way to perform analysis across a whole project?

borkdude21:11:40

LSP is just a protocol. clj-kondo has an lsp server too btw, which is used for VSCode. See https://github.com/borkdude/clj-kondo.lsp But in general clj-kondo has no idea about what your project looks like unless you instruct it to, e.g. lint the entire classpath

borkdude21:11:17

But IDEs like Cursive do, that's why they grab information using a project file like project.clj and then give you that information

borkdude21:11:43

you could say that IDEs are actively doing stuff, while clj-kondo is passively doing stuff, only linting what you tell it to

borkdude21:11:22

In theory you could use the analysis information provided by clj-kondo and then write a small flycheck plugin that provides this information

borkdude21:11:40

or maybe as a cider-nrepl plugin

Lucas Barbosa21:11:23

I see, that makes total sense

borkdude21:11:11

Maybe you could look at https://github.com/clojure-emacs/squiggly-clojure for some inspiration as well

borkdude15:11:01

so this would be the script you would write, using clj-kondo as a library: https://github.com/borkdude/clj-kondo/blob/master/analysis/src/clj_kondo/tools/unused_vars.clj

👍 4
practicalli-johnny15:11:54

Very interesting, will have to give this a try too. Thanks.

borkdude15:11:22

@UG1C3AD5Z is working on emacs TAGS generation using this

practicalli-johnny16:11:06

Ah, TAGS is something else I think I should have but never figured out what it was... I read the ctags docs and it never really said what it was or give examples of use. Maybe I read the wrong docs...

borkdude16:11:50

Same here 😅

borkdude16:11:06

I use cider for navigation

practicalli-johnny16:11:13

Its good to hear I am not alone ...

practicalli-johnny16:11:01

I am always looking for ways to navigate code and projects... got this so far https://practicalli.github.io/spacemacs/navigating-code/

borkdude16:11:15

I'm doing a lot of rg and C-x f, I'm pretty basic I guess 😉

borkdude16:11:24

I bet you can write a small cider middleware that invokes clj-kondo and then highlights the relevant symbol? I've never done this kind of thing before though

👍 4
sogaiu16:11:06

if anyone wants to give it a try, here are some instructions for generating clj-kondo-powered TAGS files (including what to do in emacs to use the results): https://gist.github.com/sogaiu/6cb947b00ae13d00d4ae16ab7aaf97e4

borkdude16:11:44

That's interesting! Maybe also relevant for your blog @jr0cket?

practicalli-johnny17:11:47

I will have a look, then I may find out what I can do with TAGS 🙂 Thanks.

sogaiu17:11:21

@jr0cket please don't hestitate to provide feedback of any kind 🙂

borkdude17:11:49

I am always looking for ways to navigate code and projectsI think TAGS are relevant tot that!

practicalli-johnny17:11:49

I think I'll add this to the advent of parens blog posts I am doing over December, along with Lambda Island...

practicalli-johnny17:11:02

thanks for the info, much appreciated.

borkdude17:11:16

maybe you have enough for three days now 😉

sogaiu17:11:55

a couple of related bits: TAGS files are basically just index files -- it turns out that it may be possible to leverage them in emacs for things other than navigation (e.g. completion as well as query-replace) https://github.com/company-mode/company-mode/blob/master/company-etags.el https://github.com/syohex/emacs-ac-etags

practicalli-johnny15:11:16

@lvbarbosa if you are successful with lsp, I would be very interested to know how you are using it. lsp is a layer in Spacemacs now, so was going to give it a try once I had figured out what I could use it for 🙂

respatialized17:11:11

👋 hello #emacs! I've been thwarted all day by a problem that some of you may have dealt with: getting my cider-launched REPL to fetch my environment variables. I would really like to use aero to load my config. But all my tests fail because the JVM Clojure process CIDER launches doesn't inherit the env vars that I use aero's syntax to fetch. I have (exec-path-from-shell-initialize) in my config. exec-path-from-shell-copy-env works for individual values, but I'd rather not have to enumerate all of them every time I add new ones. The variables are found successfully when I run boot from a regular shell, so I still can run tests, but I would prefer to not have this weird drift between my development environment and other contexts in which my code gets run. Here are some potentially confounding factors: • I'm on spacemacs • I usually run a daemonized emacs (though even fresh instances have this problem) • The daemonized process launches from my i3wm config. Sorry for the long question! I will gladly write up whatever solution is identified for anyone who wants documentation on it.

practicalli-johnny17:11:33

Are you using Spacemacs develop or master ? I am assuming Linux as you are using i3wm. Do you have the same issue when running Emacs from a terminal window? It could also be the version of Emacs you are using

respatialized18:11:37

Thanks for the quick response! I am on develop. I just launched a fresh CIDER repl from a terminal emacsclient and confirmed the same issue crops up there, but it does not if I launch a separate emacs instance with emacs --no-window-system. Guess I can make do with terminal emacs until I fully identify the source of the problem.

respatialized18:11:18

I'm using emacs 26.3.

respatialized18:11:13

Actually, the terminal is less than ideal, as I'd have to restart emacs entirely any time an env var gets added or changed because the shell process it's running in hasn't yet picked up that change.

practicalli-johnny20:11:01

My guess is that what ever shell you are using to run Emacs from does not have the environment variables. Assuming you are using Bash shell on Linux, perhaps your environment variables are in your .bashrc file and not your .profiles file. That seems to tie up with your testing, as emacsclient will use the environment variables from the daemnon process. If you stop the daemon process, you should be able to run emacs command in a terminal to start the graphical Emacs version and pick up the environment variables set in .bashrc (assuming that is the case). If that works then you just need to figure out how to get your daemon process to pick up environment variables (which narrows the scope of the question down considerably)

practicalli-johnny21:11:37

If you run the Emacs daemon process under your own user account, then configuring your accounts .profile to read the .bashrc environment variables may be a simple solution, eg. adding this code to your .profile

if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

Jcaw12:11:50

@UFTRLDZEW if practicalli's solutions work, let us know. If not, I've had similar issues so I can dig into my config and figure out how I solved them.

Jcaw12:11:22

Spacemacs has its own methods for handling env vars, supposedly more efficient than exec-path-from-shell

respatialized20:11:54

@jack.crawley92 @jr0cket Unfortunately, this didn't work for me. Regardless of whether the vars were set in .bash_profile or in .bashrc, they're not getting picked up. If I can fix this with a Spacemacs built-in, all to the better. (sorry for not responding sooner. I ended up punting on this and deferring to aero to manage the config data I was hoping to pull from env vars).

Jcaw22:11:07

That's the one. If you're using an old init.el , it might not have a spacemacs/user-env section. I remember there being no fallback behaviour if the declaration is missing.

Jcaw22:11:57

This is the defun you need to add to your init.el.

(defun dotspacemacs/user-env ()
  "Environment variables setup.
This function defines the environment variables for your Emacs session. By
default it calls `spacemacs/load-spacemacs-env' which loads the environment
variables declared in `~/.spacemacs.env' or `~/.spacemacs.d/.spacemacs.env'.
See the header of this file for more information."
  ;; Comment this out if you want to explicitly use
  ;; `exec-path-from-shell-initialize'
  (spacemacs/load-spacemacs-env)
  )

Jcaw22:11:10

Make sure there's an explicit call to (spacemacs/load-spacemacs-env). I don't think this method tracks environment variable changes, although you should be able to manually reload.

onetom13:12:07

im an intellij/cursive user, but an ex-colleague of mine was a long-time emacs user and on his setup using direnv seemed to work perfectly with emacs, even using the emacs server/client setup. https://direnv.net/

onetom13:12:27

in fact, im using direnv together with intellij too, since that's also started once but the different run configurations might run with completely different environment variables.

onetom13:12:29

i just commit a .envrc into my projects which usually contain a [ -f .env ] && dotenv line, which is a simple direnv builtin, which sources the .env file if it exists

onetom13:12:34

i also use nix to manage project dependencies, so i also have a use nix in my .envrc files.

onetom13:12:42

to make it work almost instantenously, i also put a custom version of that use_nix function into my ~/.direnvrc as documented in the wiki: https://github.com/direnv/direnv/wiki/Nix#using-a-global-use_nix-with-garbage-collection-prevention so it caches the env vars produced by my per-project nix-shell environment into ./.direnv/cache-* files

Lucas Barbosa17:11:13

@jr0cket It seems to work well. However, I am failing to configure it to recognize symbols defined by my custom macros. I tried to add a .lsp/config.edn and a .lsp/settings.json with "macro-defs" as the docs specify, with no success. Maybe @snoe can shine some light on this for us

👀 4
Lucas Barbosa17:11:52

I am trying, for instance, to make it recognize schema.core/defschema as a macro that defines a symbol in the current namespace

Lucas Barbosa19:11:31

I would also like to hear what @bozhidar has to say about static clojure code analysis on Emacs :thinking_face:

borkdude21:11:19

@lvbarbosa btw, clj-kondo does support schema

aw_yeah 4
respatialized20:11:54
replied to a thread::wave: hello #emacs! I've been thwarted all day by a problem that some of you may have dealt with: *getting my cider-launched REPL to fetch my environment variables*. I would really like to use `aero` to load my config. But all my tests fail because the JVM Clojure process CIDER launches doesn't inherit the env vars that I use `aero`'s syntax to fetch. I have `(exec-path-from-shell-initialize)` in my config. `exec-path-from-shell-copy-env` works for individual values, but I'd rather not have to enumerate all of them every time I add new ones. The variables are found successfully when I run `boot` from a regular shell, so I still can run tests, but I would prefer to not have this weird drift between my development environment and other contexts in which my code gets run. Here are some potentially confounding factors: • I'm on `spacemacs` • I usually run a daemonized `emacs` (though even fresh instances have this problem) • The daemonized process launches from my `i3wm` config. Sorry for the long question! I will gladly write up whatever solution is identified for anyone who wants documentation on it.

@jack.crawley92 @jr0cket Unfortunately, this didn't work for me. Regardless of whether the vars were set in .bash_profile or in .bashrc, they're not getting picked up. If I can fix this with a Spacemacs built-in, all to the better. (sorry for not responding sooner. I ended up punting on this and deferring to aero to manage the config data I was hoping to pull from env vars).