vim

For discussion on all things (neo)vim.
dominicm 2020-07-08T12:19:41.373900Z

:colder is amazing. I can grep while I'm grepping then return to my grepping.

❤️ 3
walterl 2020-07-08T12:33:26.374100Z

omg thanks for that! I've been struggling with mentally keeping track of my grep-ception stack.

walterl 2020-07-08T12:34:43.374400Z

I usually end up keeping my "main" activity in quickfix, and performing "sub-greps" in a different terminal.

nate 2020-07-08T14:58:21.375Z

Wow. TIL.

nate 2020-07-08T15:00:19.376800Z

I do wish there was a clojure-aware grep, like for finding uses of keywords, namespaces, functions, etc.

nate 2020-07-08T15:00:52.378Z

Some of that may be possible with cider, but having a cli tool would compose better in certain situations.

2020-07-08T15:08:55.378200Z

you can set grepprg and surely one of them should be smart enough to parse clojure identifiers

2020-07-08T15:08:59.378400Z

I use ag as mine

2020-07-08T15:09:59.378700Z

@nate sounds almost like you want tags - I have a tags config for clojure

2020-07-08T15:10:17.378900Z

--exclude=.git
--exclude=.svn
--exclude=resources/*
--exclude=*/resources/*
--exclude=*/public/*
--exclude=.repl/*
--exclude=*/.repl/*
--exclude=out/*
--exclude=*/out/*
--exclude=target/*
--exclude=*/target/*
--exclude=*min.js
--langdef=Clojure
--langmap=Clojure:.clj.cljc.cljs
--regex-clojure=/\([ \t]*create-ns[ \t]+(\^:[^\t ]+)*[ \t]*([^0-9:#@][^ \t\[{(]+)/\2/n,namespace/
--regex-clojure=/\([ \t]*defn[ \t]+(\^:[^\t ]+)*[ \t]*([^0-9:#@][^ \t\[{(]+)/\2/f,function/
--regex-clojure=/\([ \t]*defn-[ \t]+(\^:[^\t ]+)*[ \t]*([^0-9:#@][^ \t\[{(]+)/\2/p,private function/
--regex-clojure=/\([ \t]*defmacro[ \t]+(\^:[^\t ]+)*[ \t]*([^0-9:#@][^ \t\[{(]+)/\2/m,macro/
--regex-clojure=/\([ \t]*definline[ \t]+(\^:[^\t ]+)*[ \t]*([^0-9:#@][^ \t\[{(]+)/\2/i,inline/
--regex-clojure=/\([ \t]*defmulti[ \t]+(\^:[^\t ]+)*[ \t]*([^0-9:#@][^ \t\[{(]+)/\2/a,multimethod definition/
--regex-clojure=/\([ \t]*defmethod[ \t]+(\^:[^\t ]+)*[ \t]*([^0-9:#@][^ \t\[{(]+)/\2/b,multimethod instance/
--regex-clojure=/\([ \t]*defonce[ \t]+(\^:[^\t ]+)*[ \t]*([^0-9:#@][^ \t\[{(]+)/\2/c,definition (once)/
--regex-clojure=/\([ \t]*defstruct[ \t]+(\^:[^\t ]+)*[ \t]*([^0-9:#@][^ \t\[{(]+)/\2/s,struct/
--regex-clojure=/\([ \t]*deftype[ \t]+(\^:[^\t ]+)*[ \t]*([^0-9:#@][^ \t\[{(]+)/\2/s,struct/
--regex-clojure=/\([ \t]*defrecord[ \t]+(\^:[^\t ]+)*[ \t]*([^0-9:#@][^ \t\[{(]+)/\2/s,struct/
--regex-clojure=/\([ \t]*intern[ \t]+(\^:[^\t ]+)*[ \t]*([^0-9:#@][^ \t\[{(]+)/\2/v,intern/
--regex-clojure=/\([ \t]*ns[ \t]+(\^:[^\t ]+)*[ \t]*([^0-9:#@][^ \t\[{(]+)/\2/n,namespace/
--regex-clojure=/\([ \t]*def[ \t]+(\^:[^\t ]+)*[ \t]*([^0-9:#@][^ \t\[{(]+)/\2/d,definition/

2020-07-08T15:11:13.379100Z

should probably be updated so it also knows about newer features like spec, but ctags runs fast and then creates a db that jumps to the definition or usage of a token

2020-07-08T15:11:41.379300Z

as in, you could run ctags followed by tag jump in the same amount of time most grep runs would take

dharrigan 2020-07-08T15:13:02.379500Z

I use that, coupled with vim-vista to jump around my file 🙂

2020-07-08T15:13:43.379800Z

we should have a community maintained ctags config for clojure, because I'm sure mine could be improved but it's much better than the other ones I've seen

💯 2
dharrigan 2020-07-08T15:13:55.380Z

That is a great idea

2020-07-08T15:14:03.380200Z

and who knows how many people have tried to duplicate that same config...

➕ 1
2020-07-08T15:14:48.380400Z

for starters all those usages of [ \t]* which should surely be "whitespace*"

dharrigan 2020-07-08T15:15:22.380600Z

Which ctags do you use?

dharrigan 2020-07-08T15:16:09.380800Z

I use Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert which has Clojure built-in as a parser

2020-07-08T15:16:39.381Z

oh, maybe I should try that one, I haven't tried new versions in a while

dharrigan 2020-07-08T15:17:13.381200Z

It's probably not as complete as your defs

2020-07-08T15:19:41.381700Z

oh yeah, that doesn't know about def, defmulti, defprotocol...

2020-07-08T15:19:57.381900Z

unless there's an implicit "all things starting with def" rule, but then why have a rule for "defn"

2020-07-08T15:21:08.382100Z

but who knows, I'm rusty at reading C

nate 2020-07-08T15:33:53.383600Z

@noisesmith thanks for the tip. I used to use ctags all the time when I was a perl/python/go programmer. I'll try it out again.

2020-07-08T15:37:49.383800Z

I am sure you have something similar but I use this script usually

#!/bin/sh

# intended usage is the extended ctags, not eg. the OSX default, using the
# custom ctags regexes I set up for clojure

find . -name '*.clj' | xargs ctags
after that, C-] over a symbol takes me to a def (usually), and C-o takes me back again (standard vim commands of course)

2020-07-08T15:40:26.384Z

I wonder if C-] can be configured to be smart about namespace aliases...

2020-07-08T15:50:22.384200Z

I guess clojure mode could rebind C-] to be smart about removing the ns prefix at the very least, if not smart about picking the target based on that prefix...

walterl 2020-07-08T16:10:05.384500Z

> Gutentags is a plugin that takes care of the much needed management of tags files in Vim. It will (re)generate tag files as you work while staying completely out of your way. https://github.com/ludovicchabant/vim-gutentags

➕ 1
walterl 2020-07-08T16:12:04.384900Z

Also super useful: vim-fzf has :Tags (Tags in the project (`ctags -R`)) and :BTags (Tags in the current buffer) commands https://github.com/junegunn/fzf.vim

2020-07-08T16:13:47.385200Z

yeah, fzf is great (and a great back-end for defining new commands that sort through lists of things in general)

dominicm 2020-07-08T16:39:32.386200Z

@nate a fun project might be to use the kondo analyzer to write the grep tool you mentioned.

nate 2020-07-08T16:39:58.386400Z

Totally!

nate 2020-07-08T16:40:23.386600Z

or maybe the parcera babashka pod

nate 2020-07-08T16:40:34.386800Z

seems like that might be more amenable to searching

dominicm 2020-07-08T16:41:12.387Z

Parcera doesn't necessarily have details like namespace aliases that are in play.

2020-07-08T16:41:17.387200Z

oooh - a babashka based tag generator for clojure :D

2020-07-08T16:41:43.387400Z

(plus a binding of C-] that knows about ns / ns-alias...)

dominicm 2020-07-08T16:41:56.387600Z

@noisesmith can tags be used to find where a keyword is used?

dominicm 2020-07-08T16:42:29.387800Z

Maybe I'm thinking the wrong thing, buut, I'm thinking of finding uses of ::user/foo

dominicm 2020-07-08T16:42:42.388Z

By searching for :http://user.xxx/foo

dominicm 2020-07-08T16:42:51.388200Z

Or I guess vice versa too

2020-07-08T16:43:52.388400Z

tags allow types of references, I know there's separate definitions for "def" "macro" "function" etc. - I bet there's one that fits for keywords

2020-07-08T16:44:24.388600Z

but that logic would need to be split between the tag generator (make it expand to the full ns) and the tag lookup (use file specific alias)

2020-07-08T16:45:03.388800Z

but I like tags because they exist already, they have extensive infrastructure in the editor, and they carry many semantic distinctions that other kinds of search can't distinguish

2020-07-08T16:45:14.389Z

even def vs. usage is a huge win

dominicm 2020-07-08T16:45:52.389200Z

Existing things are good. That's why I proposed grep as a format to copy.

dominicm 2020-07-08T16:46:08.389400Z

I can wire it into vim-grepper and be cooking

nate 2020-07-08T16:46:23.389600Z

keyword finding is nuanced because you can destructure in multiple ways and use namespace aliases that are all missed by grep

nate 2020-07-08T16:46:29.389800Z

same with namespace usages

dominicm 2020-07-08T16:47:30.390Z

Yeah, that's why a custom grep is super helpful there. I actually am less interested in var search, because I find that's pretty uniform.

nate 2020-07-08T16:48:36.390200Z

precisely

dominicm 2020-07-08T16:53:11.390400Z

You could generate the arguments to grep by referring to an index of namespace aliases...

2020-07-08T16:55:48.390600Z

bonus: make it work with classpath entries (jars, relative paths...)

borkdude 2020-07-08T17:23:25.390800Z

https://github.com/sogaiu/alc.index-defs

💯 1
dominicm 2020-07-08T18:05:04.391500Z

:help cscope

2020-07-08T18:08:47.391600Z

interesting - how common are cscope compatible analysis tools?

dominicm 2020-07-08T18:11:43.391800Z

No idea

dominicm 2020-07-08T18:11:49.392Z

Maybe we'd create the first

dominicm 2020-07-08T18:39:26.392600Z

https://github.com/jpeach/cscope-lsp

dominicm 2020-07-08T18:43:52.393600Z

Just an example of a modern use of cscope dbs. Although perhaps lsp is a better use of time.

2020-07-08T18:44:07.393900Z

there's already an LSP for clojure

2020-07-08T18:44:18.394200Z

but there's direct vim / LSP integration too

dominicm 2020-07-08T18:51:12.394800Z

Yeah, I'm just asking if that's a better avenue I guess