Skip to content

Instantly share code, notes, and snippets.

@sogaiu
Last active November 16, 2025 02:31
Show Gist options
  • Select an option

  • Save sogaiu/0e014b4e80633847336dad44a4c4688f to your computer and use it in GitHub Desktop.

Select an option

Save sogaiu/0e014b4e80633847336dad44a4c4688f to your computer and use it in GitHub Desktop.
find-callers-of.janet demo
$ VISUAL=emacs janet find-callers-of.janet file/write ~/src/git-some-janets/repos 2>/dev/null
# emacs +4 codeberg.org/amano.kenji/j3blocks/j3blocks/modules/cmd.janet
run
# emacs +18 codeberg.org/veqq/deforester/deforester.janet
log
# emacs +40 codeberg.org/veqq/deforester/deforester.janet
set-sink-to-logger!
# emacs +7 git.sr.ht/~nullevoid/jermbox/examples/example.janet
command-loop
# emacs +22 git.sr.ht/~subsetpark/bagatto/demo/vendoring/janet_modules/tester.janet
test
# emacs +109 git.sr.ht/~maxgyver83/emailbook-janet/emailbook.janet
add-entry
# emacs +304 git.sr.ht/~maxgyver83/emailbook-janet/emailbook.janet
process-buf
# emacs +123 git.sr.ht/~bakpakin/jvk/bundle/sh.janet
copy-file
# emacs +20 git.sr.ht/~alect/camp-wanna-tya-knot/make-jaylib-janet-shim.janet
main
# emacs +27 notabug.org/debris/lllm-janet/src/main.janet
filewrite
# emacs +87 github.com/saikyun/freja/freja/file-handling.janet
save-file
# emacs +42 github.com/saikyun/freja/freja/checkpoint.janet
save-checkpoint
# emacs +40 github.com/saikyun/janet-find-in-files/replace_in_files.janet
replace-in-file
# emacs +54 github.com/saikyun/janet-find-in-files/replace_in_files.janet
replace-in-file-range
# emacs +5 github.com/saikyun/text-experiment/src/text_api.janet
dump-state
# emacs +40 github.com/saikyun/text-experiment/src/file_handling.janet
save-file
# emacs +9 github.com/pepe/jesty/test/helper.janet
assert
# emacs +9 github.com/pepe/jesty/test/helper.janet
assert
# emacs +123 github.com/pepe/smw/jpm_tree/lib/spork/sh.janet
copy-file
# emacs +250 github.com/pepe/deviman/deviman/init.janet
store-persistor
# emacs +250 github.com/pepe/deviman/deviman/init.janet
store-persistor
# emacs +14 github.com/joy-framework/bundler/src/bundler.janet
write-file
# emacs +22 github.com/joy-framework/tester/src/tester.janet
test
# emacs +6 github.com/joy-framework/db/src/db/helper.janet
file/write-all
# emacs +55 github.com/joy-framework/joy/src/joy/cli/controller.janet
create
# emacs +55 github.com/joy-framework/joy/src/joy/cli/controller.janet
create
# emacs +22 github.com/joy-framework/joy/src/joy/cli/migrations.janet
create
# emacs +49 github.com/joy-framework/joy/src/joy/cli/route.janet
create
# emacs +49 github.com/joy-framework/joy/src/joy/cli/route.janet
create
# emacs +122 github.com/joy-framework/joy/src/joy/http.janet
save-part
# emacs +142 github.com/joy-framework/joy/src/joy/helper.janet
create-file
# emacs +176 github.com/janet-lang/spork/spork/declare-cc.janet
create-buffer-c
# emacs +176 github.com/janet-lang/spork/spork/declare-cc.janet
create-buffer-c
# emacs +176 github.com/janet-lang/spork/spork/declare-cc.janet
create-buffer-c
# emacs +143 github.com/janet-lang/spork/spork/sh.janet
copy-file
# emacs +145 github.com/janet-lang/jpm/jpm/cc.janet
create-buffer-c-impl
# emacs +1878 github.com/janet-lang/janet/src/boot/boot.janet
spit
# emacs +4128 github.com/janet-lang/janet/src/boot/boot.janet
copyfile
# emacs +4757 github.com/janet-lang/janet/src/boot/boot.janet
getstdin
# emacs +23 github.com/janet-lang/janet/examples/life.janet
draw
# emacs +148 github.com/ianthehenry/to-do/src/main.janet
append-task
# emacs +179 github.com/Ruin0x11/janet-shiori/shiori.janet
dolog
# emacs +123 github.com/volodymyrpukha/smw/jpm_tree/lib/spork/sh.janet
copy-file
# emacs +202 github.com/cendyne/image-processor/src/main.janet
process
# emacs +202 github.com/cendyne/image-processor/src/main.janet
process
# emacs +52 github.com/Holmqvist1990/choosing-a-scripting-language/janet/pcm_db.janet
save-db
# emacs +176 github.com/pyrmont/markable/bundle/spork/declare-cc.janet
create-buffer-c
# emacs +176 github.com/pyrmont/markable/bundle/spork/declare-cc.janet
create-buffer-c
# emacs +176 github.com/pyrmont/markable/bundle/spork/declare-cc.janet
create-buffer-c
# emacs +143 github.com/pyrmont/markable/bundle/spork/sh.janet
copy-file
# emacs +176 github.com/pyrmont/predoc/bundle/spork/declare-cc.janet
create-buffer-c
# emacs +176 github.com/pyrmont/predoc/bundle/spork/declare-cc.janet
create-buffer-c
# emacs +176 github.com/pyrmont/predoc/bundle/spork/declare-cc.janet
create-buffer-c
# emacs +143 github.com/pyrmont/predoc/bundle/spork/sh.janet
copy-file
# emacs +5 github.com/pyrmont/predoc/test/executable.janet
copy-file
# emacs +12 github.com/pyrmont/jeep/res/helpers/util.janet
cpr
# emacs +104 github.com/pyrmont/jeep/lib/util.janet
spit-maybe
# emacs +176 github.com/pyrmont/jeep/deps/spork/spork/declare-cc.janet
create-buffer-c
# emacs +176 github.com/pyrmont/jeep/deps/spork/spork/declare-cc.janet
create-buffer-c
# emacs +176 github.com/pyrmont/jeep/deps/spork/spork/declare-cc.janet
create-buffer-c
# emacs +143 github.com/pyrmont/jeep/deps/spork/spork/sh.janet
copy-file
# emacs +35 github.com/pyrmont/arnie/benchmarks/reverse-complement/revcomp.janet
main
# emacs +35 github.com/pyrmont/arnie/benchmarks/reverse-complement/revcomp.janet
main
# emacs +42 github.com/pyrmont/arnie/benchmarks/reverse-complement/revcomp2.janet
main
# emacs +42 github.com/pyrmont/arnie/benchmarks/reverse-complement/revcomp2.janet
main
# emacs +42 github.com/pyrmont/arnie/benchmarks/reverse-complement/revcomp2_113.janet
main
# emacs +42 github.com/pyrmont/arnie/benchmarks/reverse-complement/revcomp2_113.janet
main
# emacs +123 github.com/pyrmont/arnie/deps/spork/sh.janet
copy-file
# emacs +654 github.com/rwtolbert/adopt-janet/adopt/init.janet
print-manual
# emacs +654 github.com/rwtolbert/adopt-janet/adopt/init.janet
print-manual
# emacs +654 github.com/rwtolbert/adopt-janet/adopt/init.janet
print-manual
# emacs +654 github.com/rwtolbert/adopt-janet/adopt/init.janet
print-manual
# emacs +26 github.com/rwtolbert/fltk-janet/examples/native-filechooser.janet
save-file
# emacs +9 github.com/good-place/mansion/test/helper.janet
assert
# emacs +9 github.com/good-place/mansion/test/helper.janet
assert
# emacs +112 github.com/jeannekamikaze/janet-filesystem/filesystem.janet
write-file
# emacs +118 github.com/jeannekamikaze/janet-filesystem/filesystem.janet
copy-file
# emacs +9 github.com/Putnam3145/janet-d/source/tests/helper.janet
assert
# emacs +9 github.com/Putnam3145/janet-d/source/tests/helper.janet
assert
# emacs +35 github.com/tionis/toolbox/src/sh.janet
coerce-file
# emacs +35 github.com/tionis/toolbox/src/sh.janet
coerce-file
# emacs +108 github.com/tionis/cosmo/cosmo/filesystem.janet
write-file
# emacs +114 github.com/tionis/cosmo/cosmo/filesystem.janet
copy-file
# emacs +7 github.com/hackberrydev/alas/src/file_repository.janet
save
# emacs +55 github.com/hackberrydev/alas/src/commands/backup.janet
backup
# emacs +33 github.com/agent-kilo/jwno/src/log.janet
file-logger
# emacs +30 github.com/agent-kilo/jwno/project.janet
generate-resource-header
# emacs +3 github.com/sepisoad/jurl/test/main.janet
download
# emacs +86 github.com/sepisoad/super-janet-typist/script/profile.janet
update
# emacs +86 github.com/sepisoad/super-janet-typist/script/profile.janet
update
# emacs +86 github.com/sepisoad/super-janet-typist/script/profile.janet
update
# emacs +86 github.com/sepisoad/super-janet-typist/script/profile.janet
update
# emacs +46 github.com/sepisoad/labgoo/codes/helpers.janet
gen-page
# emacs +46 github.com/sepisoad/labgoo/codes/helpers.janet
gen-page
# emacs +46 github.com/sepisoad/labgoo/codes/helpers.janet
gen-page
# emacs +46 github.com/sepisoad/labgoo/codes/helpers.janet
gen-page
# emacs +46 github.com/sepisoad/labgoo/codes/helpers.janet
gen-page
# emacs +46 github.com/sepisoad/labgoo/codes/helpers.janet
gen-page
# emacs +46 github.com/sepisoad/labgoo/codes/helpers.janet
gen-page
# emacs +46 github.com/sepisoad/labgoo/codes/helpers.janet
gen-page
# emacs +46 github.com/sepisoad/labgoo/codes/helpers.janet
gen-page
# emacs +46 github.com/sepisoad/labgoo/codes/helpers.janet
gen-page
# emacs +46 github.com/sepisoad/labgoo/codes/helpers.janet
gen-page
# emacs +46 github.com/sepisoad/labgoo/codes/helpers.janet
gen-page
# emacs +46 github.com/sepisoad/labgoo/codes/helpers.janet
gen-page
# emacs +46 github.com/sepisoad/labgoo/codes/helpers.janet
gen-page
# emacs +46 github.com/sepisoad/labgoo/codes/helpers.janet
gen-page
# emacs +46 github.com/sepisoad/labgoo/codes/helpers.janet
gen-page
# emacs +46 github.com/sepisoad/labgoo/codes/helpers.janet
gen-page
# emacs +72 github.com/sepisoad/labgoo/codes/helpers.janet
gen-tag-pages
# emacs +72 github.com/sepisoad/labgoo/codes/helpers.janet
gen-tag-pages
# emacs +72 github.com/sepisoad/labgoo/codes/helpers.janet
gen-tag-pages
# emacs +72 github.com/sepisoad/labgoo/codes/helpers.janet
gen-tag-pages
# emacs +72 github.com/sepisoad/labgoo/codes/helpers.janet
gen-tag-pages
# emacs +72 github.com/sepisoad/labgoo/codes/helpers.janet
gen-tag-pages
# emacs +72 github.com/sepisoad/labgoo/codes/helpers.janet
gen-tag-pages
# emacs +72 github.com/sepisoad/labgoo/codes/helpers.janet
gen-tag-pages
# emacs +72 github.com/sepisoad/labgoo/codes/helpers.janet
gen-tag-pages
# emacs +72 github.com/sepisoad/labgoo/codes/helpers.janet
gen-tag-pages
# emacs +39 github.com/s-lambert/janet-game/src/tile-editor.janet
render-tile-editor
# emacs +19 github.com/JohnDoneth/janet-language-server/language-server/src/main.janet
log
# emacs +19 github.com/JohnDoneth/janet-language-server/language-server/src/main.janet
log
# emacs +169 github.com/JohnDoneth/janet-language-server/language-server/src/main.janet
write-response
# emacs +169 github.com/JohnDoneth/janet-language-server/language-server/src/main.janet
write-response
# emacs +35 github.com/MikeBeller/janet-benchmarksgame/reverse-complement/revcomp.janet
main
# emacs +35 github.com/MikeBeller/janet-benchmarksgame/reverse-complement/revcomp.janet
main
# emacs +42 github.com/MikeBeller/janet-benchmarksgame/reverse-complement/revcomp2.janet
main
# emacs +42 github.com/MikeBeller/janet-benchmarksgame/reverse-complement/revcomp2.janet
main
# emacs +42 github.com/MikeBeller/janet-benchmarksgame/reverse-complement/revcomp2_113.janet
main
# emacs +42 github.com/MikeBeller/janet-benchmarksgame/reverse-complement/revcomp2_113.janet
main
# emacs +47 github.com/cellularmitosis/janet-lzo/misc/zbench.janet
run-z-cmd
# emacs +13 github.com/mpwillson/fcgi/log.janet
write
# emacs +13 github.com/mpwillson/fcgi/log.janet
write
# emacs +24 github.com/mpwillson/fcgi/log.janet
init
# emacs +46 github.com/sogaiu/index-janet/index-janet/main.janet
main
# emacs +46 github.com/sogaiu/index-janet/index-janet/main.janet
main
# emacs +46 github.com/sogaiu/index-janet/index-janet/main.janet
main
# emacs +375 github.com/sogaiu/index-janet/support/idk-janet.janet
main
# emacs +375 github.com/sogaiu/index-janet/support/idk-janet.janet
main
# emacs +375 github.com/sogaiu/index-janet/support/idk-janet.janet
main
# emacs +20 github.com/sogaiu/jaylib-wasm-demo/make-jaylib-janet-shim.janet
main
# emacs +36 github.com/sogaiu/ajrepl/ajrepl/custom-repl.janet
my-getstdin
# emacs +180 github.com/sogaiu/janet-ref/janet-ref/repl.janet
getstdin
# emacs +5 github.com/CFiggers/janet-lsp/src/logging.janet
log
# emacs +5 github.com/CFiggers/janet-lsp/src/logging.janet
log
# emacs +412 github.com/CFiggers/janet-lsp/src/main.janet
write-response
# emacs +412 github.com/CFiggers/janet-lsp/src/main.janet
write-response
# emacs +13 github.com/CFiggers/teddy-editor/src/teddy.janet
handle-keystroke
# emacs +449 github.com/CFiggers/joule-editor/src/joule.janet
editor-refresh-screen
# emacs +648 github.com/CFiggers/joule-editor/src/joule.janet
enter-debugger
# emacs +23 github.com/AlecTroemel/craft-bin/craft-bin/ideas/repl.janet
getform
# emacs +20 github.com/andrewchambers/hermes/src/fetch.janet
dl-progress
# emacs +41 github.com/andrewchambers/hermes/src/hermes-main.janet
load-hpkg-url
# emacs +84 github.com/andrewchambers/hermes/src/builtins.janet
local-file*
# emacs +6 github.com/andrewchambers/hermes/src/protocol.janet
send-msg
# emacs +6 github.com/andrewchambers/hermes/src/protocol.janet
send-msg
# emacs +39 github.com/andrewchambers/hermes/src/protocol.janet
send-file-chunks
# emacs +39 github.com/andrewchambers/hermes/src/protocol.janet
send-file-chunks
# emacs +52 github.com/andrewchambers/hermes/src/protocol.janet
recv-file-chunks
# emacs +35 github.com/andrewchambers/janet-sh/sh.janet
coerce-file
# emacs +35 github.com/andrewchambers/janet-sh/sh.janet
coerce-file
# emacs +62 github.com/andrewchambers/janet-process/process.janet
coerce-input-file
# emacs +365 github.com/andrewchambers/janetsh/src/sh.janet
run-subshell-proc
# emacs +391 github.com/andrewchambers/janetsh/src/sh.janet
launch-job
# emacs +391 github.com/andrewchambers/janetsh/src/sh.janet
launch-job
# emacs +749 github.com/andrewchambers/janetsh/src/sh.janet
out-lines
# emacs +932 github.com/andrewchambers/janetsh/src/sh.janet
make-exec-builtin
# emacs +1019 github.com/andrewchambers/janetsh/src/sh.janet
make-clear-builtin
# emacs +1051 github.com/andrewchambers/janetsh/src/sh.janet
make-alias-builtin
# emacs +1051 github.com/andrewchambers/janetsh/src/sh.janet
make-alias-builtin
# emacs +1051 github.com/andrewchambers/janetsh/src/sh.janet
make-alias-builtin
# emacs +3 github.com/andrewchambers/poolparty/poolparty.janet
serve
# emacs +7 github.com/dalygbarron/kowari/test/kowari.janet
fwritef
# emacs +12 github.com/dalygbarron/kowari/test/kowari.janet
old-test
# emacs +24 github.com/dalygbarron/pingo/test/pingo.janet
save-and-load-bytes
# emacs +7 github.com/dbridges/jty/jty.janet
print-debug
# emacs +7 github.com/dbridges/jty/jty.janet
print-debug
# emacs +8 github.com/runejuhl/toggle-leds/main.janet
toggle-brightness
# emacs +8 github.com/runejuhl/toggle-leds/main.janet
toggle-brightness
# emacs +29 github.com/runejuhl/toggle-leds/main.janet
main
# files pre-searched: 5202
# files searched: 107
# processing time: 1.34 seconds
(import ./location :as l)
(import ./zipper :as j)
(import ./loc-jipper :as j)
(import ./common :as c)
########################################################################
# XXX: just doing defn, defn-, varfn for the moment
(defn find-caller
[zloc]
(var cur-zloc zloc)
(var name nil)
(while (def parent-zloc (j/up cur-zloc))
(set cur-zloc parent-zloc)
(def parent-node-str (l/gen (j/node parent-zloc)))
(def parsed
(try
(parse parent-node-str)
([e]
(eprintf "failed to parse: %s" parent-node-str))))
(when (not parsed)
(set cur-zloc nil)
(break))
#
(def head (first parsed))
(when (get {'defn true 'defn- true 'varfn true} head)
(set name (get parsed 1))
(break)))
#
(when name
(def node (j/node cur-zloc))
(def {:bl bl} (get node 1))
[bl name]))
(defn find-callers-of
[name src &opt opts]
(default opts {:pred identity})
(def {:pred pred} opts)
#
(def tree (l/par src))
(var cur-zloc (j/zip-down tree))
(def results @[])
#
(while (def next-zloc
(j/search-from cur-zloc
|(match (j/node $)
[:symbol _ (@ name)]
$)))
(def parent-zloc (j/up next-zloc))
(when (= :tuple (get (j/node parent-zloc) 0))
(def node (j/node parent-zloc))
(def raw-code-str (l/gen node))
(def parsed
(try
(parse raw-code-str)
([e]
(eprintf "failed to parse: %s" raw-code-str))))
(when (and parsed (pred parsed))
# ensure the first non-trivial element of the tuple is `name`
(when (= name (string (first parsed)))
(def caller (find-caller parent-zloc))
(when caller
(def [caller-line caller-name] caller)
(array/push results [caller-line caller-name])))))
#
(set cur-zloc (j/df-next next-zloc)))
#
results)
(comment
(find-callers-of
"pp"
``
(defn fly [] :flap)
(defn smile
[y]
(pp y))
``)
# =>
@[[3 'smile]]
(find-callers-of
"pp"
``
(defn hello
[x]
(pp x)
(print "hi")
(if true
(pp [:x x])
(print "oh no")))
``)
# =>
@[[1 'hello]
[1 'hello]]
)
########################################################################
(defn main
[_ & args]
(def {:name name
:includes includes
:pred pred
:editor editor} (c/determine-inputs args {:name true}))
# find .janet files
(def src-filepaths
(c/collect-paths includes |(string/has-suffix? ".janet" $)))
# search the paths
(c/search-and-report find-callers-of name src-filepaths
{:pred pred :editor editor}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment