Allow history relative to a particular project #751

Closed
trptcolin opened this Issue Aug 28, 2012 · 6 comments

Comments

3 participants
@trptcolin
Collaborator

trptcolin commented Aug 28, 2012

As described in trptcolin/reply#70

This should just require passing a custom history file path to reply via the :history-file option, since the functionality is available as of this commit in reply.

I'm assuming this should probably be a :repl-options feature, not on by default, since you'd probably want it stored relative in your project directory, and gitignores may or may not be set up with this in mind on existing projects.

I'm putting this here in case someone else can get to it before me.

@technomancy

This comment has been minimized.

Show comment Hide comment
@technomancy

technomancy Aug 28, 2012

Owner

If we default it to target/repl-history then .gitignores shouldn't have trouble with it, though it'll get removed by clean.

Owner

technomancy commented Aug 28, 2012

If we default it to target/repl-history then .gitignores shouldn't have trouble with it, though it'll get removed by clean.

@trptcolin

This comment has been minimized.

Show comment Hide comment
@trptcolin

trptcolin Aug 28, 2012

Collaborator

Hmm, interesting. My first impression is that I'd be surprised to have lein clean blow out repl history, but I'm open to thinking about the problem more. Or, since lein2 isn't final yet, maybe the gitignore concern isn't a big deal. We could still provide repl-options as a fallback for folks who really want a global path (presumably from default user profiles).

Collaborator

trptcolin commented Aug 28, 2012

Hmm, interesting. My first impression is that I'd be surprised to have lein clean blow out repl history, but I'm open to thinking about the problem more. Or, since lein2 isn't final yet, maybe the gitignore concern isn't a big deal. We could still provide repl-options as a fallback for folks who really want a global path (presumably from default user profiles).

@technomancy

This comment has been minimized.

Show comment Hide comment
@technomancy

technomancy Aug 28, 2012

Owner

Yeah, I don't really mind the gitignore issues; it's obvious enough what to do with it. The minor annoyance is worth the extra feature.

Owner

technomancy commented Aug 28, 2012

Yeah, I don't really mind the gitignore issues; it's obvious enough what to do with it. The minor annoyance is worth the extra feature.

@michaelklishin

This comment has been minimized.

Show comment Hide comment
@michaelklishin

michaelklishin Sep 18, 2012

Collaborator

We already use the :repl-options key in leiningen.repl:

(defn options-for-reply [project & {:keys [attach port]}]
  (let [repl-options (:repl-options project)]
    (clojure.set/rename-keys
      (merge
        repl-options
        {:init (if-let [init-ns (or (:init-ns repl-options) (:main project))]
                 `(do (require '~init-ns) (in-ns '~init-ns)
                      ~(:init repl-options))
                 (:init repl-options))}
        (cond
          attach
            {:attach (if-let [host (repl-host project)]
                       (str host ":" attach)
                       (str attach))}
          port
            {:port (str port)}
          :else
            {}))
      {:prompt :custom-prompt
       :init :custom-init})))

(reply/launch-nrepl (options-for-reply project :attach repl-port))

So we just need to pick a good location default. Yesterday @technomancy suggested ./.lein-repl-history because
lein clean will wipe out target/*. I will look into adding that.

Collaborator

michaelklishin commented Sep 18, 2012

We already use the :repl-options key in leiningen.repl:

(defn options-for-reply [project & {:keys [attach port]}]
  (let [repl-options (:repl-options project)]
    (clojure.set/rename-keys
      (merge
        repl-options
        {:init (if-let [init-ns (or (:init-ns repl-options) (:main project))]
                 `(do (require '~init-ns) (in-ns '~init-ns)
                      ~(:init repl-options))
                 (:init repl-options))}
        (cond
          attach
            {:attach (if-let [host (repl-host project)]
                       (str host ":" attach)
                       (str attach))}
          port
            {:port (str port)}
          :else
            {}))
      {:prompt :custom-prompt
       :init :custom-init})))

(reply/launch-nrepl (options-for-reply project :attach repl-port))

So we just need to pick a good location default. Yesterday @technomancy suggested ./.lein-repl-history because
lein clean will wipe out target/*. I will look into adding that.

@michaelklishin

This comment has been minimized.

Show comment Hide comment
@michaelklishin

michaelklishin Sep 18, 2012

Collaborator

I see a couple of options:

  • Add a new project map default
  • Calculate REPLy options on the fly

New project map default

This is trivial to implement but will leave ./.lein-repl-history files all over your filesystem if you have a habit of launching lein repl from random shell tabs (I do).

Caclulate REPLy options on the fly

A bit more work but sounds like for non-project directories it would be better to use a shared location.

So I'd suggest going with the latter. Thoughts?

Also, I cannot find a predicate that says "are we in a project directory". Is there one?

Collaborator

michaelklishin commented Sep 18, 2012

I see a couple of options:

  • Add a new project map default
  • Calculate REPLy options on the fly

New project map default

This is trivial to implement but will leave ./.lein-repl-history files all over your filesystem if you have a habit of launching lein repl from random shell tabs (I do).

Caclulate REPLy options on the fly

A bit more work but sounds like for non-project directories it would be better to use a shared location.

So I'd suggest going with the latter. Thoughts?

Also, I cannot find a predicate that says "are we in a project directory". Is there one?

@technomancy

This comment has been minimized.

Show comment Hide comment
@technomancy

technomancy Sep 18, 2012

Owner

Let's add it to options-for-reply if it's not already in :repl-options and you're in a project.

The presence of a :root key in the project map is a good indicator that we're in a project dir.

Owner

technomancy commented Sep 18, 2012

Let's add it to options-for-reply if it's not already in :repl-options and you're in a project.

The presence of a :root key in the project map is a good indicator that we're in a project dir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment