bbatsov / projectile

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

`projectile-replace` doesn't work. #1115

Open kaiwk opened 7 years ago

kaiwk commented 7 years ago

Expected behavior

M-x projectile-replace or C-c p r, replace the function name in the git project.

Actual behavior

It does nothing but put the message 'All files processed'.

Steps to reproduce the problem

It seems this command always act like that, and I don't know the command before.

Environment & Version information

Projectile version information

Projectile 20170106.606

Here is my configuration:

(use-package projectile
  :diminish projectile-mode
  :init
  (projectile-mode t)
  :config
  (add-to-list 'projectile-globally-ignored-files "*.png")
  (add-to-list 'projectile-globally-ignored-files "*.jpg")
  (add-to-list 'projectile-globally-ignored-files "*.zip")
  (setq projectile-require-project-root nil)
  (setq projectile-indexing-method 'native)
  (setq projectile-enable-caching t)
  (setq projectile-globally-ignored-directories
        (append '(
                  ".git"
                  ".svn"
                  "out"
                  "repl"
                  "target"
                  "venv"
                  "node_modules")
                projectile-globally-ignored-directories))
  (setq projectile-globally-ignored-files
        (append '(
                  ".DS_Store"
                  "*.gz"
                  "*.pyc"
                  "*.jar"
                  "*.tar.gz"
                  "*.tgz"
                  "*.zip")
                projectile-globally-ignored-files)))

Emacs version

25.1.1

Operating system

OS X 10.12.3

Besides, projectile-replace-regexp works well.

nordlow commented 5 years ago

I'm having the same problem on Linux. Both projectile-replace and projectile-replace-regexp silently skip lots of replacements.

asheshambasta commented 5 years ago

This indeed seems broken for me too: the replacement starts presenting me the matches to replace and then exits midway. Is there a workaround?

WhittlesJr commented 5 years ago

+1. Could we reopen this?

tamenol commented 4 years ago

Bumping this as I have the same problem.

EDIT: for me (W10, Emacs 26.2) projectile-replace-regexp also doens't replace matches and goes straight to 'All files processed'

aljab012 commented 2 years ago

+1, Could you reopen this?

bbatsov commented 2 years ago

This issue needs a reliable reproduction, though. projectile-replace has always worked fine for me.

aljab012 commented 2 years ago

The issue appear to be the same as https://github.com/hlissner/doom-emacs/issues/4687

> Executing 'doom info' with Emacs 27.2 at 2022-03-21 07:25:45
    generated    Mar 21, 2022 07:25:45
      system       Arch Linux Linux 5.16.15-arch1-1 x86_64
      emacs        27.2 ~/.emacs.d/ -> ~/.emacs.d/
      doom         21.12.0-alpha grafted, HEAD -> master, origin/master, origin/HEAD 42e57637 2022-02-23 17:49:53 +0100 ~/.doom.d/ -> ~/.doom.d/
      shell        /usr/bin/zsh
      features     XPM JPEG TIFF GIF PNG RSVG CAIRO SOUND GPM DBUS GSETTINGS GLIB NOTIFY INOTIFY ACL GNUTLS LIBXML2 FREETYPE HARFBUZZ M17N_FLT LIBOTF ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD JSON PDUMPER LCMS2 GMP
      traits       batch server-running envvar-file
      modules      :completion company vertico :ui doom doom-dashboard doom-quit (emoji +github +unicode) hl-todo modeline ophints (popup +defaults) treemacs vc-gutter vi-tilde-fringe workspaces :editor (evil +everywhere) file-templates fold format snippets :emacs dired electric undo vc :checkers syntax (spell +flyspell) grammar :tools (eval +overlay) lookup lsp (magit +forge) :os tty :lang emacs-lisp (go +lsp) json javascript markdown org sh yaml :config (default +bindings +smartparens)
      packages     (prettier-js)

Projectile appears to skip matches on open buffers in the background.

I turned toggle-debug-on-error on but it looks projectile fails silently.

Any tips on how to debug this?

rogual commented 2 years ago

This doesn't look like a Projectile bug to me.

In fileloop.el.gz, in fileloop-continue, the line:

(switch-to-buffer (current-buffer))

seems to lose the point position set by fileloop--scan-function. This means the fileloop--operate-function is called with point in the wrong place, and can't do the replacement.

As a quick fix, I hacked mine to say:

(let ((pos (point)))
  (switch-to-buffer (current-buffer))
  (goto-char pos))

...which seems to be working so far, but I'm not an Emacs guru and don't know if it's ultimately a good fix.

If you want to try the workaround, you can find the code to edit with M-x find-function <RET> fileloop-continue.

aljab012 commented 2 years ago

I tested @rogual Solution and it seems to work for me

Mekk commented 2 years ago

For some time (emacs update? projectile update? some dep update) projectile-replace partially stopped working for me in the very specific way: while it worked correctly on non-yet open files, it seemed to replace only „from point down” inside active buffers. It was most troublesome while making a few massive replacements in order, as first replace moved cursor down (to last replacement made) in many buffers, so successive attempts to replace sth else handled only bottom parts of those files.

I even tested that manually visiting some buffers and Ctrl-Home-ing cursor to the top helps (projectile-replace finds nothing, I visit some buffers and move cursor to the top, I retry, replacements are made).

Also (commenting linked doom issue) I didn't see any warnings or errors. Just „succesfull” replace performed from point down instead of being performed on complete files.

Suggestion above seems related, I am yet to try.

Mekk commented 2 years ago

If I bisect properly, fileloop was introduced to projectile here (for emacs 27+): https://github.com/bbatsov/projectile/commit/1ac84bf2f2141cb789449f7e379ac33a95035f93 and it seems fairly possible that I started to have problems since I upgraded to emacs27.

I initially thought that reverting to the „old way” also in emacs27+ would help, but sth doesn't work then (I tried simply changing to false condition in https://github.com/bbatsov/projectile/blob/4d6da873ae54dbf6043b015efd9b737e2ce152c6/projectile.el#L4408 ) but then for some reason replacing stops after first match (on emacs 27.1) so I suppose „old way” is not fully compatible with such emacs.

Mekk commented 2 years ago

Hmm, I found https://git.savannah.gnu.org/cgit/emacs.git/commit/?h=emacs-27.1&id=a477a7b86ba which landed in

$ git tag --contains a477a7b86ba
emacs-28.0.90
emacs-28.0.91
emacs-28.0.92
emacs-28.1

So mayhaps we have emacs 27 problem here, resolved by upgrade to emacs 28…

gubblebozer commented 2 years ago

@Mekk, I think you're right! projectile-replace seems to be working just fine for me now after a recent upgrade from emacs 27.(something) to emacs 28.1.

Mekk commented 2 years ago

In my case it also preliminarily seems so (although I am yet to test it more).

So more-or-less it seems that projectile-replace doesn't work properly on Emacs 27 due to the bug in emacs-provided fileloop library. On Emacs 26 and Emacs 28 replacing works (on 26 because this library is not yet available and projectile uses alternative implementation, on 28 because the bug in fileloop is fixed).

jgarvin commented 10 months ago

In emacs 29.1 with projectile 20230713.1023 it worked for me one time, but then fails as originally described ("All files processed") every time after.

patrickaroo commented 9 months ago

Ditto for me.