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

Fix "save before refresh" functionality and use files.el for path comparisons/operations #2546

Merged
merged 5 commits into from
Jan 25, 2019

Conversation

cichli
Copy link
Member

@cichli cichli commented Dec 21, 2018

I tried setting cider-ns-save-files-on-refresh to both t and 'prompt but found neither had any effect. It turns out that clojure-project-dir returns a non-canonical path (e.g. ~/clojure/...), whereas the predicate passed to save-some-buffers was using (file-truename default-directory) which does return canonical paths (e.g. /Users/griffithsm/clojure/...).

I then made the further observation that tools.namespace actually reloads all modified Clojure files on the entire classpath - not just those inside the current project!

To solve this I have modified cider-ns-refresh--save-project-buffers to:

  • Check modified file-visiting buffers against all classpath directories, not just the current project directory.
  • Use proper file/directory path handling functions from files.el rather than string-prefix-p. This means we get rid of the Windows-specific workaround for case-insensitivity there too.

Similarly, the use of string comparisons in cider-expected-ns meant we had to be sure that its input was a canonical path. Again by using functions from files.el we can avoid any platform-related headaches or similar.


  • The commits are consistent with our contribution guidelines
  • You've added tests (if possible) to cover your change(s)
  • All tests are passing (make test)
  • All code passes the linter (make 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)

@cichli cichli requested a review from bbatsov December 21, 2018 21:04
cider-ns.el Outdated Show resolved Hide resolved
@bbatsov
Copy link
Member

bbatsov commented Dec 22, 2018

Long time, no see! It's good to see you back! :-)

cider-ns.el Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@bbatsov bbatsov left a comment

Choose a reason for hiding this comment

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

Apart from my small remarks the PR looks great to me!

@bbatsov
Copy link
Member

bbatsov commented Jan 8, 2019

@cichli ping :-)

@cichli cichli force-pushed the fix-save-on-refresh branch from 40960e9 to 9dab2a5 Compare January 21, 2019 19:15
@cichli
Copy link
Member Author

cichli commented Jan 21, 2019

I have added a new defcustom to control for which modes the saving should happen – defaults to '(clojure-mode).

@cichli cichli force-pushed the fix-save-on-refresh branch 2 times, most recently from 600d9d2 to 2a8d87a Compare January 22, 2019 04:02
CHANGELOG.md Outdated Show resolved Hide resolved
Previously this relied on `clojure-project-dir` from clojure-mode, but
tools.namespace will refresh any modified files on the entire classpath, so they
are worth including too.

Additionally, path comparisons are now made using `file-in-directory-p` rather
than `string-prefix-p`, obviating any issues around path expansion, symlinks,
and platform-specific issues such as case sensitivity.
* Use `file-truename` to relax the need for the given path to be absolute
* Only consider actual directories on the classpath
* Use `file-in-directory-p` and `file-relative-name` rather than
  `string-prefix-p` and `substring`
@cichli cichli force-pushed the fix-save-on-refresh branch from 2a8d87a to 1896b1b Compare January 22, 2019 13:42
@bbatsov bbatsov merged commit d29c59d into clojure-emacs:master Jan 25, 2019
@bbatsov
Copy link
Member

bbatsov commented Jan 25, 2019

Great work!

@cichli cichli deleted the fix-save-on-refresh branch February 4, 2019 16:41
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.

2 participants