Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a command to delete history item at point #3574

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Zzull
Copy link

@Zzull Zzull commented Nov 7, 2023

This PR adds a command to delete an history item at point.

The first commit is important because it makes cider-repl-input-history global. It was already sort of global before because the history was shared across REPLs and saved to a unique file but now it's downright a defvar instead of a defvar-local. I went in that direction because it felt like it was the simplest way of dealing with acknowledgment of deletion of an item across multiple REPLs.

The first commit now stores histories on a per-project basis


Before submitting the PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):

  • The commits are consistent with our contribution guidelines
  • You've added tests (if possible) to cover your change(s)
  • All tests are passing (eldev test)
  • All code passes the linter (eldev lint) which is based on elisp-lint and includes
  • You've updated the changelog (if adding/changing user-visible functionality)
  • You've updated the user manual (if adding/changing user-visible functionality)

Thanks!

If you're just starting out to hack on CIDER you might find this section of its
manual
extremely useful.

@Zzull
Copy link
Author

Zzull commented Nov 7, 2023

On a side note, it looks like eldev linter doesn't agree with the CI on how to indent

cider-repl.el:354:0 (indent)     !          (contents)
cider-repl.el:355:0 (indent)     !          (insert-before-markers
cider-repl.el:356:0 (indent)     !           (propertize
cider-repl.el:357:0 (indent)     !            (if (string-blank-p contents) ";;\n" (concat ";; " contents "\n"))
cider-repl.el:358:0 (indent)     !            'font-lock-face 'font-lock-comment-face))))
Found 5 warnings in file `cider-repl.el'

@vemv
Copy link
Member

vemv commented Nov 7, 2023

Thanks for the PR!

The first commit is important because it makes cider-repl-input-history global. It was already sort of global before because the history was shared across REPLs

Although it may be true, I sense that having per-project repl histories would be the best new direction - WDYT?

@vemv
Copy link
Member

vemv commented Nov 7, 2023

On a side note, it looks like eldev linter doesn't agree with the CI on how to indent

Probably it's a matter of using our Makefile instead

@Zzull
Copy link
Author

Zzull commented Nov 7, 2023

On a side note, it looks like eldev linter doesn't agree with the CI on how to indent

Probably it's a matter of using our Makefile instead

make lint and eldev lint yielded the same result (that cider-repl.el has a block poorly indented)

@Zzull
Copy link
Author

Zzull commented Nov 7, 2023

Thanks for the PR!

The first commit is important because it makes cider-repl-input-history global. It was already sort of global before because the history was shared across REPLs

Although it may be true, I sense that having per-project repl histories would be the best new direction - WDYT?

I can totally try to split the history on a per-project basis

@vemv
Copy link
Member

vemv commented Nov 7, 2023

make lint and eldev lint yielded the same result (that cider-repl.el has a block poorly indented)

Maybe you're on a different Emacs version - we use 28 for linting. The Makefile has a comment indicating how to override the local Emacs.

I can totally try to split the history on a per-project basis

Thanks!

I assume it's never been like that / it's something we want? @bbatsov

To me it makes sense because a given project's sexprs are often irrelevant / invalid (not compile-able) in another project.

@Zzull Zzull force-pushed the master branch 2 times, most recently from 995f11b to d96930b Compare November 7, 2023 23:25
@Zzull
Copy link
Author

Zzull commented Nov 7, 2023

Maybe you're on a different Emacs version - we use 28 for linting. The Makefile has a comment indicating how to override the local Emacs.

Absolutely. Thank you

To me it makes sense because a given project's sexprs are often irrelevant / invalid (not compile-able) in another project.

It's done in the first commit (which is a bit hard to read…)

@bbatsov
Copy link
Member

bbatsov commented Nov 8, 2023

I assume it's never been like that / it's something we want? @bbatsov

I'd be fine by this, although I'm not sure how it can be made reliably.(e.g. what would you use as project id for remote connections?) I'll take a look at the proposed implementation.

cider-repl.el Outdated
The value of `cider-repl-input-history' and `cider-repl-history-file' are set by
this function."
(when-let* ((dir (clojure-project-dir))
(file (concat dir "/.cider-history")))
Copy link
Member

Choose a reason for hiding this comment

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

I'd better to use expand-file-name instead of concat. Also - I'd move the file name to a constant.

@@ -1592,16 +1595,6 @@ If USE-CURRENT-INPUT is non-nil, use the current input."
:type 'integer
:safe #'integerp)

(defcustom cider-repl-history-file nil
Copy link
Member

Choose a reason for hiding this comment

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

You can't just delete this - you'll have to add a deprecation warning for it, so people would know it's no longer being used. If we want to avoid breaking changes we'd probably want to keep the old behavior if this variable is set.

cider-repl.el Outdated
@@ -194,6 +194,9 @@ CIDER 1.7."
This property value must be unique to avoid having adjacent inputs be
joined together.")

(defvar-local cider-repl-history-file nil
Copy link
Member

Choose a reason for hiding this comment

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

Related to my other remark - you should probably use a different name for the buffer-local var, to avoid breaking changes.

@bbatsov
Copy link
Member

bbatsov commented Nov 8, 2023

I quickly went over the code and it looks reasonable overall, but it also introduces a breaking change that I think would be prudent to ignore. Probably it'd be best to keep the old behavior if someone set an file name explicitly and switch to the logging per project if they haven't.

cider-repl.el Outdated
The value of `cider-repl-input-history' and `cider-repl-history-file' are set by
this function."
(when-let* ((dir (clojure-project-dir))
(file (concat dir "/.cider-history")))
Copy link
Member

Choose a reason for hiding this comment

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

Probably we should have one file per platform: clj, cljs, bb

cider-repl.el Outdated Show resolved Hide resolved
@Zzull
Copy link
Author

Zzull commented Nov 10, 2023

Hello,

Almost all comments have been addressed.

I still have two things I would like your advice on:

  • I don't have a remote machine accessible with clojure on it to make sure that cider-repl--find-dir-for-history behaves the way it should. Do you think tramp-tramp-file-p is enough?
  • I couldn't find a way to get the type of the REPL to suffix the name of the history file with. It seems that it is too early to call (cider-runtime) (returns 'generic) nor get the value of cider-repl-type (nil) when cider-repl-history-load is called. And anyways, after initialization, (cider-runtime) returns 'clojure for a cljs project and cider-repl-type has the value 'clj for a babashka project. Do you have other leads?

@vemv
Copy link
Member

vemv commented Nov 10, 2023

Thanks much!

It's looking great.

Do you think tramp-tramp-file-p is enough?

Most definitely.

Do you have other leads?

If you don't mind I'll pick up this branch, fix some nits and then also add the 'platform' refinement. Then I'll squash everything, keeping you as the author. It's how I operate normally, to avoid long feedback loops.

We can keep the PR open in the meantime.

@vemv vemv marked this pull request as draft November 11, 2023 22:47
@@ -576,6 +577,16 @@ text from the *cider-repl-history* buffer."
(with-current-buffer cider-repl-history-repl-buffer
(undo)))

(defun cider-repl-history-delete ()
Copy link
Member

Choose a reason for hiding this comment

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

delete-item-at-point

Copy link
Member

Choose a reason for hiding this comment

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

(or entry)

Note that CIDER writes the history to the file when you kill the REPL
buffer, which includes invoking `cider-quit`, or when you quit Emacs.
Note that CIDER stores the history in a file named by
`cider-repl-local-history-name` located at the root of your project if
Copy link
Member

Choose a reason for hiding this comment

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

Probably this should be named cider-repl-project-history-file or something along those lines, as I think local history might be slightly misleading in this case. (and yeah - I realize there might not always be a project associated with a REPL)

@bbatsov
Copy link
Member

bbatsov commented Nov 12, 2023

I'll also add that currently CIDER doesn't have persistent history by default and I think it's a good idea to keep this behavior. Frankly, I really don't care much about history between sessions and I guess I'm not the only one, given there has been little demand to change the default behavior over the years.

@vemv
Copy link
Member

vemv commented Nov 12, 2023

Frankly, I really care about history between sessions

I didn't get this - what behavior should remain unchanged?

@bbatsov
Copy link
Member

bbatsov commented Nov 12, 2023

I meant to write "don't care". I think this should be some opt-in, not a default. (just as storing the global history to file is)

@vemv
Copy link
Member

vemv commented Nov 12, 2023

From my side it's something I've always missed (really), but it was more in the 'nice-to-have' area. There was always something more important 😄

Maybe we can keep it under a defcustom indeed, enabling it later after some months for gaining confidence in the solution.

@bbatsov
Copy link
Member

bbatsov commented Nov 12, 2023

Yeah, that's fair. I'm just always a bit wary of serializing data to files (and reading it back) as often people run into issues with broken entries due to various reason. (probably less so in this case, given the simple nature of the history format, but I've had my fair share of issues with seemingly trivial serialization)

@bbatsov
Copy link
Member

bbatsov commented Nov 27, 2023

So, what are we doing about this PR?

@vemv
Copy link
Member

vemv commented Nov 27, 2023

I'll pick it up early December, sorry for the delay.

@bbatsov
Copy link
Member

bbatsov commented Feb 28, 2024

@vemv Any updates on this front?

@vemv
Copy link
Member

vemv commented Feb 28, 2024

Perhaps this weekend, sorry for the delay.

@bbatsov
Copy link
Member

bbatsov commented May 7, 2024

@vemv Friendly reminder about this one. :-) I want us to start finalizing the scope of the next release.

@vemv
Copy link
Member

vemv commented May 7, 2024

Sure, I'm finally closing a sprint which didn't leave a lot of OSS time available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants