This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-26
Channels
- # announcements (2)
- # aws (4)
- # babashka (5)
- # beginners (91)
- # calva (4)
- # cider (17)
- # clara (13)
- # clj-kondo (14)
- # cljsrn (11)
- # clojure (159)
- # clojure-europe (2)
- # clojure-nl (14)
- # clojure-norway (2)
- # clojure-taiwan (2)
- # clojure-uk (32)
- # clojurescript (101)
- # clojutre (4)
- # cursive (13)
- # data-science (1)
- # datomic (46)
- # emacs (68)
- # figwheel-main (5)
- # fulcro (48)
- # graalvm (7)
- # graphql (6)
- # instaparse (5)
- # joker (4)
- # lambdaisland (1)
- # leiningen (2)
- # malli (9)
- # off-topic (41)
- # pedestal (15)
- # re-frame (47)
- # reagent (7)
- # reitit (14)
- # shadow-cljs (180)
- # spacemacs (58)
- # specter (1)
- # tools-deps (13)
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.
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/
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?
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
@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...
https://github.com/borkdude/clj-kondo/blob/master/doc/editor-integration.md
@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
@lvbarbosa Do you mean unused vars in the entire project?
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
@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
So that would not be an in-editor kind of feedback, but data you use for whatever purpose you want
Is there any possibility of getting that into the editor? :thinking_face: I have no idea of how difficult that would be
I love the way Cursive does it.. I am currently using it to perform this sort of task
@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
That makes sense. Is lsp
the "standard" way to perform analysis across a whole project?
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
But IDEs like Cursive do, that's why they grab information using a project file like project.clj and then give you that information
you could say that IDEs are actively doing stuff, while clj-kondo is passively doing stuff, only linting what you tell it to
In theory you could use the analysis information provided by clj-kondo and then write a small flycheck plugin that provides this information
I see, that makes total sense
Maybe you could look at https://github.com/clojure-emacs/squiggly-clojure for some inspiration as well
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
Very interesting, will have to give this a try too. Thanks.
@UG1C3AD5Z is working on emacs TAGS generation using this
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...
Its good to hear I am not alone ...
I am always looking for ways to navigate code and projects... got this so far https://practicalli.github.io/spacemacs/navigating-code/
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
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
I will have a look, then I may find out what I can do with TAGS 🙂 Thanks.
I am always looking for ways to navigate code and projectsI think TAGS are relevant tot that!
I think I'll add this to the advent of parens blog posts I am doing over December, along with Lambda Island...
thanks for the info, much appreciated.
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
@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 🙂
👋 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.
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
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.
I'm using emacs 26.3.
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.
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)
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
@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.
Spacemacs has its own methods for handling env vars, supposedly more efficient than exec-path-from-shell
@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).
Can it be something with ~/.spacemacs.env
?
https://develop.spacemacs.org/doc/DOCUMENTATION.html#environment-variables-and-path
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.
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)
)
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.
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/
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.
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
i also use nix to manage project dependencies, so i also have a use nix
in my .envrc
files.
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
@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
I am trying, for instance, to make it recognize schema.core/defschema
as a macro that defines a symbol in the current namespace
I would also like to hear what @bozhidar has to say about static clojure code analysis on Emacs :thinking_face:
@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).