babashka-sci-dev

teodorlu 2023-01-29T12:33:35.449769Z

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?

borkdude 2023-01-29T12:34:26.919059Z

yes

🫑 1
teodorlu 2023-01-29T12:45:53.056179Z

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")

teodorlu 2023-01-29T12:47:41.222979Z

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

borkdude 2023-01-29T12:49:05.366429Z

yeah, editing the -f would be the solution

πŸ‘ 1
teodorlu 2023-01-29T13:12:32.214159Z

PR: Move neil dep upgrade helptext into subcommand https://github.com/babashka/neil/pull/155 Thread πŸ‘‰

teodorlu 2023-01-29T13:12:59.492079Z

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.

teodorlu 2023-01-29T13:13:22.595989Z

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.

teodorlu 2023-01-29T13:14:04.860559Z

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

teodorlu 2023-01-29T13:15:06.794579Z

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.

borkdude 2023-01-29T13:42:39.344139Z

Yep

borkdude 2023-01-29T13:44:33.827569Z

Merged, lots better already - agreed with the other points

πŸ‘ 1
teodorlu 2023-01-29T15:27:31.458139Z

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?

borkdude 2023-01-29T15:28:22.227449Z

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

πŸ‘ 1
teodorlu 2023-01-29T15:36:14.313509Z

Cool! PR: https://github.com/babashka/neil/pull/156

βœ… 1
lispyclouds 2023-01-29T17:31:16.576879Z

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.

lispyclouds 2023-01-29T17:32:50.872159Z

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 πŸ˜„

borkdude 2023-01-29T17:56:38.302629Z

I don't really care about formatting

lispyclouds 2023-01-29T17:57:36.687889Z

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

borkdude 2023-01-29T17:57:37.481129Z

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

borkdude 2023-01-29T17:58:01.539369Z

I can try to adopt clojure-lsp cljfmt

borkdude 2023-01-29T17:58:04.307829Z

in my own editor

borkdude 2023-01-29T17:58:08.976469Z

if that helps you

lispyclouds 2023-01-29T17:58:13.919929Z

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

lispyclouds 2023-01-29T17:59:04.178809Z

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

borkdude 2023-01-29T18:21:22.508849Z

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)))

borkdude 2023-01-29T18:21:47.174999Z

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

borkdude 2023-01-29T18:22:11.608499Z

I guess clojure-mode hooks into that

borkdude 2023-01-29T18:23:57.038739Z

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

borkdude 2023-01-29T18:25:05.942329Z

@ericdallo do you know?

ericdallo 2023-01-29T18:46:42.718859Z

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

ericdallo 2023-01-29T18:47:06.192169Z

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

borkdude 2023-01-29T18:48:01.871219Z

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

ericdallo 2023-01-29T18:48:02.474049Z

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

borkdude 2023-01-29T18:48:15.680199Z

is cljfmt also supported for other editors?

ericdallo 2023-01-29T18:48:36.338609Z

You mean only cljfmt without clojure-lsp?

borkdude 2023-01-29T18:48:49.944919Z

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

πŸ‘ 1
borkdude 2023-01-29T18:48:59.298919Z

facepalm

borkdude 2023-01-29T18:49:29.889959Z

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

ericdallo 2023-01-29T18:50:25.735599Z

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

borkdude 2023-01-29T18:50:38.912059Z

:-D

borkdude 2023-01-29T18:50:43.698619Z

does cider also use cljfmt somehow?

borkdude 2023-01-29T18:51:19.025509Z

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

ericdallo 2023-01-29T18:51:19.474099Z

AFAIK it does its own way of formatting following ClojureStyleGuide

ericdallo 2023-01-29T18:51:29.389469Z

Good question haha

borkdude 2023-01-29T18:51:46.659509Z

and tonsky also has other opinions on formatting

borkdude 2023-01-29T18:52:10.927299Z

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

lispyclouds 2023-01-29T18:52:33.894159Z

Hence I was hoping for a config and I can adapt my setup to it πŸ˜…

ericdallo 2023-01-29T18:52:42.225719Z

Totally configurable via .cljfmt.edn if you want

borkdude 2023-01-29T18:52:59.849819Z

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

borkdude 2023-01-29T18:53:04.168339Z

from now on I'll use that

ericdallo 2023-01-29T18:53:32.358349Z

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

borkdude 2023-01-29T18:54:17.535789Z

Cursive does not support formatting?

lispyclouds 2023-01-29T18:54:20.062739Z

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

borkdude 2023-01-29T18:54:59.829719Z

ok

lispyclouds 2023-01-29T18:55:44.463519Z

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

borkdude 2023-01-29T18:55:46.547149Z

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

borkdude 2023-01-29T18:56:00.829839Z

@rahul080327 dude, use clojure-lsp native image

lispyclouds 2023-01-29T18:56:15.473739Z

But it shells to cljfmt I think

borkdude 2023-01-29T18:56:33.737779Z

of course not, it's fully self-contained

lispyclouds 2023-01-29T18:57:09.699899Z

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

borkdude 2023-01-29T18:57:27.674439Z

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

lispyclouds 2023-01-29T18:57:51.179979Z

Yeah I tried that and remember some errors with cljfmt

ericdallo 2023-01-29T19:00:52.020879Z

@borkdude 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?

borkdude 2023-01-29T19:01:30.770569Z

well, e.g. in elisp

borkdude 2023-01-29T19:01:46.883819Z

do you have a conditional at hand?

ericdallo 2023-01-29T19:02:41.453839Z

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

borkdude 2023-01-29T19:03:19.782459Z

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

borkdude 2023-01-29T19:03:47.921909Z

(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)))

ericdallo 2023-01-29T19:04:23.028079Z

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

borkdude 2023-01-29T19:04:49.729719Z

(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)

ericdallo 2023-01-29T19:05:09.635429Z

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

ericdallo 2023-01-29T19:05:26.691749Z

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

borkdude 2023-01-29T19:05:41.978309Z

I usually format my whole buffer

borkdude 2023-01-29T19:06:07.322189Z

not just one region

borkdude 2023-01-29T19:06:17.871659Z

anyway this works

ericdallo 2023-01-29T19:06:20.019959Z

me too, but anyway, that would work

lispyclouds 2023-01-29T19:10:08.710859Z

lsp formatting works! awesome.

πŸš€ 2
borkdude 2023-01-29T19:11:11.239799Z

@rahul080327 yay! issue solved then

lispyclouds 2023-01-29T19:11:30.614129Z

yep!

borkdude 2023-01-29T19:14:13.351369Z

> @borkdude 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 :)

ericdallo 2023-01-29T19:17:12.582889Z

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

borkdude 2023-01-29T19:19:14.453089Z

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

ericdallo 2023-01-29T19:21:14.782159Z

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

borkdude 2023-01-29T19:22:19.748459Z

I'm looking forward to the docs

ericdallo 2023-01-29T19:23:44.567129Z

https://clojure-lsp.io/settings/#classpath-config-paths

borkdude 2023-01-29T19:25:30.048149Z

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

borkdude 2023-01-29T19:25:38.106359Z

That's convenient

ericdallo 2023-01-29T19:26:17.712359Z

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

borkdude 2023-01-29T19:26:35.103939Z

It's almost like these tools are getting popular

πŸ˜‚ 1
pez 2023-01-29T20:29:41.233489Z

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

lispyclouds 2023-01-29T20:30:53.247859Z

@borkdude added this little config and i think you'd like that too? https://github.com/lispyclouds/dotfiles/blob/main/.cljfmt.edn

lispyclouds 2023-01-29T20:32:51.603869Z

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 πŸ™πŸΎ

πŸ‘ 1
lispyclouds 2023-01-29T20:34:05.633369Z

@ericdallo would be cool if zprint could be supported too, its config is quite the thing πŸ˜„

ericdallo 2023-01-29T20:34:53.776459Z

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

lispyclouds 2023-01-29T20:35:49.284919Z

yeah its very ideal to have it, love clojure-lsp as it is already! its indispensable πŸ™πŸΎ

πŸ’œ 1