bbatsov / projectile

Project Interaction Library for Emacs
https://docs.projectile.mx
GNU General Public License v3.0
3.99k stars 585 forks source link

Function fails with “mapcar: Symbol’s function definition is void: string-trim” #1382

Closed benf-portable closed 5 years ago

benf-portable commented 5 years ago

Expected behavior

With a .projectile file, all functions should run without error.

Actual behavior

With a .projectile file, some functions fail with an error “mapcar: Symbol’s function definition is void: string-trim”.

Steps to reproduce the problem

Environment & Version information

Projectile version information

Projectile 2.0.0

Emacs version

Emacs 26.1

Operating system

Reproduced on both MacOS 10.13.6 and Debian GNU+Linux 9.7.

pbellon commented 5 years ago

I do encounter the same error on Projectile 20190126.1117 and emacs 26.1 (build 1, x86_64-redhat-linux-gnu, GTK+ Version 3.23.2) of 2018-08-13.

hsiddanthi commented 5 years ago

Able to reproduce this error on Mac 10.13.6 High Sierra, Emacs 26.1 and projectile 2.0.0. The side effect of this error, subsequent calls to magit also run into this error or others.

Having explicit (require 'subr-x) in config resolves this error.

j1n3l0 commented 5 years ago

I am also able to reproduce this on:

Projectile 20190126.1117
GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu) of 2019-03-11
Linux vagrant-ubuntu-trusty-64 3.13.0-165-generic #215-Ubuntu SMP Wed Jan 16 11:46:47 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
achempion commented 5 years ago

Was able to fix it by (require 'subr-x)

j1n3l0 commented 5 years ago

Was able to fix it by (require 'subr-x)

Do you mind sharing where you added that @achempion?

achempion commented 5 years ago

@j1n3l0 inside my ~/.emacs configuration, your config may be inside ~/.spacemacs or ~/emacs.d/init.el depends on your setup

Also I've found that (require 's) by s package will resolve similar issues for packages using string functions

benf-portable commented 5 years ago

Discussion of work-arounds in personal init files is fine, of course. But that's not resolving the issue.

What's needed, as I understand it, is for Projectile to correctly declare its dependencies in the ELPA package. Installing Projectile should bring in any dependencies it needs for its functions; that's the resolution needed for this issue.

bbatsov commented 5 years ago

All of Projectile's dependencies are properly declared.

Also I've found that (require 's) by s package will resolve similar issues for packages using string functions

Projectile doesn't use s at all. subr-x is a built-in Emacs package that's mean to be used with eval-when-compile (as Projectile does). I assume some bad byte-compilation might have caused this problem people are referring to, but the code is exactly what it has been for a very long time.

mpolden commented 4 years ago

I'm experiencing this issue as well and spent quite some time trying to figure it out. The issue is exactly the one described in https://github.com/bbatsov/projectile/issues/1382#issue-411689163.

  1. ~/project contains a .projectile file with contents /ignored/.
  2. The file ~/project/foo is opened.
  3. The following message appears in minibuffer: mapcar: Symbol’s function definition is void: string-trim
  4. Subsequent projectile-grep invocations fail with the same message.

Reproduced with GNU Emacs 26.3 (build 1, x86_64-apple-darwin18.2.0, NS appkit-1671.20 Version 10.14.3 (Build 18D109)) of 2019-09-02.

Can we reopen this issue?

Edit 1: As already mentioned in this thread: If I force subr-x to load before projectile, this issue does not occur (e.g. https://github.com/mpolden/emacs.d/commit/7ead4deeaf2d154eab0a892772e28f9bf2c405ee). Edit 2: If you use desktop-save-mode and Emacs restores the buffer from the project with a .projectile, projectile-grep is permanently broken every time you start Emacs.

mpolden commented 4 years ago

It's definitively something to do with byte compilation, as @bbatsov suggests.

If I remove the byte-compiled projectile.elc after doing M-x package-install RET projectile RET and restart Emacs, the issue is gone.

If I recompile projectile.el with M-x byte-compile-file and restart Emacs, the issue returns.

mpolden commented 4 years ago

projectile-parse-dirconfig-file is the function that complains about undefined string-trim when you call projectile-grep.

thkoch2001 commented 4 years ago

+1 to reopening. I got the same problem after adding a .projectile file with Debians projectile 2.0.0-2 package.

alxdb commented 4 years ago

Also just had this problem.

One thing that comes to mind is that I'm loading a byte compiled config in my init.el. Other than that I believe everything I'm doing is pretty vanilla (just Emacs, no use-package, using package.el). Certainly as @bbatsov suggests this is most likely a byte compilation issue, but it would be nice if we could hone in on what the actual problem is. Anyone else with this issue byte compiling their config?

I also remember reading on straight.el's readme that package.el can cause issues with byte compilation, but again, it would be nice if the error could be described more precisely.

mpolden commented 4 years ago

FWIW I was unable to trigger this on Emacs 27.

jayanta-sarkar commented 2 months ago

Able to reproduce this error on Mac 10.13.6 High Sierra, Emacs 26.1 and projectile 2.0.0. The side effect of this error, subsequent calls to magit also run into this error or others.

Having explicit (require 'subr-x) in config resolves this error.

jayanta-sarkar commented 2 months ago

This did work for me as well for emacs 26.3 on ubuntu