Skip to content

Commit

Permalink
Add *repl-prompt*.
Browse files Browse the repository at this point in the history
  • Loading branch information
bakpakin committed Sep 21, 2024
1 parent 8084e4c commit 2570e0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
All notable changes to this project will be documented in this file.

## ??? - Unreleased
- Change how JANET_PROFILE is loaded to allow more easily customizing the environment.
- Add `*repl-prompt*` dynamic binding to allow customizing the built in repl.
- Add multiple path support in the `JANET_PATH` environment variables. This lets
user more easily import modules from many directories.

Expand Down
11 changes: 7 additions & 4 deletions src/boot/boot.janet
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,9 @@
(defdyn *pretty-format*
"Format specifier for the `pp` function")

(defdyn *repl-prompt*
"Allow setting a custom prompt at the default REPL. Not all REPLs will respect this binding.")

(defn pp
``Pretty-print to stdout or `(dyn *out*)`. The format string used is `(dyn *pretty-format* "%q")`.``
[x]
Expand Down Expand Up @@ -4643,17 +4646,15 @@
(if-not quiet
(print "Janet " janet/version "-" janet/build " " (os/which) "/" (os/arch) "/" (os/compiler) " - '(doc)' for help"))
(flush)
(def env (make-env))
(defn getprompt [p]
(when-let [custom-prompt (get env *repl-prompt*)] (break (custom-prompt p)))
(def [line] (parser/where p))
(string "repl:" line ":" (parser/state p :delimiters) "> "))
(defn getstdin [prompt buf _]
(file/write stdout prompt)
(file/flush stdout)
(file/read stdin :line buf))
(def env (make-env))
(when-let [profile.janet (dyn *profilepath*)]
(def new-env (dofile profile.janet :exit true))
(merge-module env new-env "" false))
(when debug-flag
(put env *debug* true)
(put env *redef* true))
Expand All @@ -4665,6 +4666,8 @@
(setdyn *doc-color* (if colorize true))
(setdyn *lint-error* error-level)
(setdyn *lint-warn* error-level)
(when-let [profile.janet (dyn *profilepath*)]
(dofile profile.janet :exit true :env env))
(repl getchunk nil env)))))

###
Expand Down

3 comments on commit 2570e0f

@pepe
Copy link
Member

@pepe pepe commented on 2570e0f Sep 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the profile fix. It bothered me a lot.

@sogaiu
Copy link
Contributor

@sogaiu sogaiu commented on 2570e0f Sep 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tried it out:

$ janet
Janet 1.37.0-dev-2570e0f7 linux/x64/gcc - '(doc)' for help
repl:1:> (setdyn *repl-prompt* (fn [p] ""))
<function 0x5625609E5D40>
(+ 1 2)
3
:a
:a
(get {:a 1} :a)
1

Apart from use with editors, I think this can also be nice for copy-pasting example sessions as the helpful delimiter hints don't need to be removed.

TYVM!

@noncom
Copy link

@noncom noncom commented on 2570e0f Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow I've been waiting for this!

Please sign in to comment.