Fork me on GitHub
#babashka-sci-dev
<
2023-01-29
>
teodorlu12:01:35

Should we consider trimming down the helptext from neil / neil -h and putting detailed subcommand usage in neil SUBCOMMAND -h ? I was considering adding a new paragraph to the neil dep helptext (ref https://github.com/babashka/neil/issues/108), but it's already long. -- Right now: 1. We have a global hand-crafted helptext 2. neil dep add has its own helptext - neil dep add -h 3. neil dep search has its own helptext - neil dep search -h 4. Other subcommands don't seem to have any subcommand helptext. A first step could be to move the neil dep upgrade docs into neil dep upgrade -b. Thoughts?

teodorlu12:01:53

is it possible to install a local neil development version with bbin - that runs src/babashka/neil.clj directly, rather than the generated neil script? (when I won't have to bb gen-script locally) -- Right now, when bbin install . --as neil-dev from the neil repo, I get this in ~/.babashka/bbin/bin/neil-dev:

(def script-root "/home/teodorlu/dev/babashka/neil")
(def script-main-opts-first "-f")
(def script-main-opts-second "/home/teodorlu/dev/babashka/neil/neil")
I'd prefer this:
(def script-root "/home/teodorlu/dev/babashka/neil")
(def script-main-opts-first "-m")
(def script-main-opts-second "babashka.neil/-main")

teodorlu12:01:41

manually editing the bbin shim to run -m babashka.neil/-main is enough for me right now 🙂

borkdude12:01:05

yeah, editing the -f would be the solution

👍 2
teodorlu13:01:32

PR: Move neil dep upgrade helptext into subcommand https://github.com/babashka/neil/pull/155 Thread 👉

teodorlu13:01:59

I'm happy with the neil dep versions -h helptext:

$ neil-dev dep upgrade -h
Usage: neil dep upgrade [lib] [options]

  neil dep upgrade [options]            Upgrade all libraries
  neil dep upgrade LIB [options]        Upgrade a single library
  neil dep upgrade --lib LIB [options]  Upgrade a single library

Options:

  --lib                         Fully qualified library name.
  --dry-run                     dep upgrade only. Prevents updates to deps.edn.
  --alias      <alias>          Add to alias <alias>.
  --no-aliases                  Prevents updates to alias :extra-deps when upgrading.

Examples:

  neil dep upgrade                           ; upgrade all deps.
  neil dep upgrade --dry-run                 ; print deps that would be upgraded.
  neil dep upgrade --alias lint`             ; update only deps for the `lint` alias.
  neil dep upgrade :lib clj-kondo/clj-kondo  ; update a single dep.

teodorlu13:01:22

But I still think the global helptext is a bit too verbose:

$ neil-dev -h
Usage: neil <subcommand> <options>

Most subcommands support the options:
  --alias      Override alias name.
  --deps-file  Override deps.edn file name.

Subcommands:

add
  dep    Alias for `neil dep add`.
  test   adds cognitect test runner to :test alias.
  build  adds tools.build build.clj file and :build alias.
  kaocha adds kaocha test runner to :kaocha alias.
  nrepl  adds nrepl server to :nrepl alias.

dep
  add: Adds --lib, a fully qualified symbol, to deps.edn :deps.
    Run `neil dep add --help` to see all options.

  search: Search Clojars for a string in any attribute of an artifact
    Run `neil dep search --help` to see all options.

  upgrade: Upgrade libs in the deps.edn file.
    Run `neil dep upgrade --help` to see all options.

  update: Alias for `upgrade`.

license
  list   Lists commonly-used licenses available to be added to project. Takes an optional search string to filter results.
  search Alias for `list`
  add    Writes license text to a file
    Options:
    --license The key of the license to use (e.g. epl-1.0, mit, unlicense). --license option name may be elided when license key is provided as first argument.
    --file    The file to write. Defaults to 'LICENSE'.

new
  Create a project using deps-new
    Run `neil new --help` to see all options.

version
  Commands for managing the :version key in the deps.edn project config.
    Run `neil version --help` to see all options.

test
  Run tests. Assumes `neil add test`. Run `neil test --help` to see all options.

teodorlu13:01:04

I like the neil dep add docs from neil -h. They are quick to skim.

teodorlu13:01:06

I think it would be good to get the neil dep SUBCOMMAND docs down to one line each. But we still need to let the user know they can get subcommand docs.

borkdude13:01:33

Merged, lots better already - agreed with the other points

👍 2
teodorlu15:01:31

This seems to be working for installing a development version of neil with #babashka-bbin - and it doesn't require re-running gen-script on changes:

$ bbin install . --as neil-dev --main-opts '["-m" babashka.neil/-main]'
Should we add those to the ## Dev section of the README below the local brew installation instructions?

borkdude15:01:22

Oh nice, I didn't know that. Yes please!

👍 2
lispyclouds17:01:16

would it help to have a code style/formatting guide for the source code in bb and friends? could be helpful for contributors as I myself found my formatter rearranging stuff i dont wanna change.

lispyclouds17:01:50

if we can suggest a tool and config, i for one would be happy to follow it and think of one less thing when contributing 😄

borkdude17:01:38

I don't really care about formatting

lispyclouds17:01:36

The thing is I have a tendency to format the file before saving and it moves things around unrelated to my changes

borkdude17:01:37

as long as it's the same as my emacs does it :P

borkdude17:01:01

I can try to adopt clojure-lsp cljfmt

borkdude17:01:04

in my own editor

borkdude17:01:08

if that helps you

lispyclouds17:01:13

Yeah if you can get your emacs conf to a file I’m happy too!

lispyclouds17:01:04

I don’t really care about the formatting rules just that if I can have access to a rule set I’m happy

borkdude18:01:22

This is what I'm using to format my buffer:

(defun iwb ()
  "Indent whole buffer."
  (interactive)
  (delete-trailing-whitespace)
  (indent-region (point-min) (point-max) nil)
  (untabify (point-min) (point-max)))

borkdude18:01:47

and I think it depends on the mode, e.g. clojure-mode , how it formats

borkdude18:01:11

I guess clojure-mode hooks into that

borkdude18:01:57

I don't know actually which part is responsible for doing that :)

ericdallo18:01:42

Indent-region will call the indent-region-function variable, which could be some Elisp package or lsp-mode for example. I'd suggest try clojure-lsp formatting that uses cljfmt under the hood, via lsp-format-buffer

ericdallo18:01:06

I find myself doing that on clj-kondo multiple times and needing to rollback to not change a lot of stuff :p

borkdude18:01:01

ok, fine, I'll change to lsp-format-buffer instead

ericdallo18:01:02

If using clojure-lsp, you could even setup a CI that runs clojure-lsp format to make sure things are formatted as well, it's what we do in Nubank and clojure-lsp related projects

borkdude18:01:15

is cljfmt also supported for other editors?

ericdallo18:01:36

You mean only cljfmt without clojure-lsp?

borkdude18:01:49

oh right, clojure-lsp also works in vim of course

👍 2
borkdude18:01:29

does clojure-lsp does something with the clj-kondo analysis to enhance cljfmt formatting?

ericdallo18:01:25

ATM no, but will do after I merge a PR that will check :style/indent metadata to format like cider

borkdude18:01:43

does cider also use cljfmt somehow?

borkdude18:01:19

cider is dependent on a JVM REPL. does it not format CLJS code when you don't have a REPL? so many questions...

ericdallo18:01:19

AFAIK it does its own way of formatting following ClojureStyleGuide

ericdallo18:01:29

Good question haha

borkdude18:01:46

and tonsky also has other opinions on formatting

borkdude18:01:10

I'm fine with going with clojure-lsp. I think I only see differences in with-let etc compared to my emacs formatter

lispyclouds18:01:33

Hence I was hoping for a config and I can adapt my setup to it 😅

ericdallo18:01:42

Totally configurable via .cljfmt.edn if you want

borkdude18:01:59

@U7ERLH6JX if you will use clojure-lsp formatting, we will have the same one

borkdude18:01:04

from now on I'll use that

ericdallo18:01:32

Even if not using in editor, possible to use via cli like Cursive users do

borkdude18:01:17

Cursive does not support formatting?

lispyclouds18:01:20

Yeah I use zprint via the cli, will make it behave like default cljfmt

lispyclouds18:01:44

Or this is an opportunity to try cljfmt, will change after years. Couldn’t find a good native image back then

borkdude18:01:46

@UKFSJSM38 can I call (lsp-format-buffer) from a keyboard shortcut, but fall back to something else when I'm not connected to lsp?

borkdude18:01:00

@U7ERLH6JX dude, use clojure-lsp native image

lispyclouds18:01:15

But it shells to cljfmt I think

borkdude18:01:33

of course not, it's fully self-contained

lispyclouds18:01:09

Ah really, I couldn’t get lsp formatting to work, will poke more

borkdude18:01:27

@U7ERLH6JX if you use clojure-lsp from vim you should be able to call lsp-format-buffer or so right

lispyclouds18:01:51

Yeah I tried that and remember some errors with cljfmt

ericdallo19:01:52

@U04V15CAJ lsp-format-buffer expects LSP is connect so you would need to create a custom function that check if LSP is connected (there is a function for that) and if not call other function. Why you would not be connected to LSP though?

borkdude19:01:30

well, e.g. in elisp

borkdude19:01:46

do you have a conditional at hand?

ericdallo19:01:41

doom-emacs does that automatically and bind to SPC c f (code format), but it probably has smart checks

borkdude19:01:19

(when (lsp--capability "documentFormattingProvider")
    (lsp-format-buffer))

borkdude19:01:47

(defun iwb ()
  "Indent whole buffer."
  (interactive)
  (delete-trailing-whitespace)
  (if (lsp--capability "documentFormattingProvider")
      (lsp-format-buffer)
    (indent-region (point-min) (point-max) nil))
  (untabify (point-min) (point-max)))

ericdallo19:01:23

a better check would be checking if (lsp-workspaces) is t

borkdude19:01:49

(require 'lsp)

(defun iwb ()
  "Indent whole buffer."
  (interactive)
  (delete-trailing-whitespace)
  (if (and (lsp-workspaces)
           (lsp--capability "documentFormattingProvider"))
      (lsp-format-buffer)
    (indent-region (point-min) (point-max) nil))
  (untabify (point-min) (point-max)))

(global-set-key (kbd "<f7>") 'iwb)

ericdallo19:01:09

@U04V15CAJ you probably don't need that custom function as lsp-mode already does that automatically if you have lsp-enable-indentation set to t

ericdallo19:01:26

it would set indent-region-function to lsp-format-buffer

borkdude19:01:41

I usually format my whole buffer

borkdude19:01:07

not just one region

borkdude19:01:17

anyway this works

ericdallo19:01:20

me too, but anyway, that would work

lispyclouds19:01:08

lsp formatting works! awesome.

🚀 4
borkdude19:01:11

@U7ERLH6JX yay! issue solved then

borkdude19:01:13

> @U04V15CAJ you probably don't need that custom function as lsp-mode already does that automatically if you have lsp-enable-indentation set to t Is this the mode where lsp formats while you're typing? I'd rather not :)

ericdallo19:01:12

oh, you are right, I have that disabled for that reason and I'm discussing with lsp-mode folks to disable it by default.

borkdude19:01:14

@UKFSJSM38 does cljfmt support exporting configs inside dependencies so your macro users get the same formatting everywhere?

ericdallo19:01:14

no, not natively in cljfmt, but if using via clojure-lsp you could: • use clojure-lsp export feature like clj-kondo via :classpath-config-paths and use the setting :cljfmt to configure custom format • use style/indent after that PR I mentioned is merged, next release

borkdude19:01:19

I'm looking forward to the docs

borkdude19:01:30

Oh that's awesome, you just copied clj-kondo's way of doing :)

borkdude19:01:38

That's convenient

ericdallo19:01:17

Yep :) We use at nubank and with that we use the same convention for formatting/hooks and everything for more than 1000 projects

borkdude19:01:35

It's almost like these tools are getting popular

😂 2
pez20:01:41

> is cljfmt also supported for other editors? Calva uses cljfmt as its formatting engine.

lispyclouds20:01:51

rest all i think im cool with cljfmt's defaults, im used to aligning the map key values but can also see issues so will make peace with it 🙏:skin-tone-5:

👍 2
lispyclouds20:01:05

@UKFSJSM38 would be cool if zprint could be supported too, its config is quite the thing 😄

ericdallo20:01:53

Yeah, there is a issue for that, I'll probably do that in the future, one more deps though

lispyclouds20:01:49

yeah its very ideal to have it, love clojure-lsp as it is already! its indispensable 🙏:skin-tone-5:

💜 2