Fork me on GitHub
#vim
<
2020-07-08
>
dominicm12:07:41

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

❤️ 9
walterl12:07:26

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

walterl12:07:43

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

nate14:07:21

Wow. TIL.

nate15:07:19

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

nate15:07:52

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

noisesmith15:07:55

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

noisesmith15:07:59

I use ag as mine

noisesmith15:07:59

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

noisesmith15:07:17

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

noisesmith15:07:13

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

noisesmith15:07:41

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

dharrigan15:07:02

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

noisesmith15:07:43

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

💯 6
dharrigan15:07:55

That is a great idea

noisesmith15:07:03

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

3
noisesmith15:07:48

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

dharrigan15:07:22

Which ctags do you use?

dharrigan15:07:09

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

noisesmith15:07:39

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

dharrigan15:07:13

It's probably not as complete as your defs

noisesmith15:07:41

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

noisesmith15:07:57

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

noisesmith15:07:08

but who knows, I'm rusty at reading C

nate15:07:53

@U051SS2EU 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.

noisesmith15:07:49

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)

noisesmith15:07:26

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

noisesmith15:07:22

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

walterl16:07:05

> 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

3
walterl16:07:04

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

noisesmith16:07:47

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

dominicm16:07:32

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

nate16:07:58

Totally!

nate16:07:23

or maybe the parcera babashka pod

nate16:07:34

seems like that might be more amenable to searching

dominicm16:07:12

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

noisesmith16:07:17

oooh - a babashka based tag generator for clojure :D

noisesmith16:07:43

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

dominicm16:07:56

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

dominicm16:07:29

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

dominicm16:07:51

Or I guess vice versa too

noisesmith16:07:52

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

noisesmith16:07:24

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)

noisesmith16:07:03

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

noisesmith16:07:14

even def vs. usage is a huge win

dominicm16:07:52

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

dominicm16:07:08

I can wire it into vim-grepper and be cooking

nate16:07:23

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

nate16:07:29

same with namespace usages

dominicm16:07:30

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.

nate16:07:36

precisely

dominicm16:07:11

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

noisesmith16:07:48

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

dominicm18:07:04

:help cscope

noisesmith18:07:47

interesting - how common are cscope compatible analysis tools?

dominicm18:07:49

Maybe we'd create the first

dominicm18:07:52

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

noisesmith18:07:07

there's already an LSP for clojure

noisesmith18:07:18

but there's direct vim / LSP integration too

dominicm18:07:12

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