bbatsov / helm-projectile

Helm UI for Projectile
327 stars 71 forks source link

Helm source ‘Projectile files’: before-init-hook Should be defined as a symbol #163

Closed ghost closed 2 years ago

ghost commented 2 years ago

截屏2022-08-05 18 38 49

ghost commented 2 years ago

How to avoid this warning? @dandavison

luizalbertocviana commented 2 years ago

I was able to correct it with the following change.

   (remove-hook 'helm-after-update-hook #'helm-projectile--move-to-real)
   (remove-hook 'helm-cleanup-hook #'helm-projectile--remove-move-to-real))

+(defun helm-source-projectile-files-list-before-init-hook ()
+  (add-hook 'helm-after-update-hook #'helm-projectile--move-to-real)
+  (add-hook 'helm-cleanup-hook #'helm-projectile--remove-move-to-real))
+
 (defvar helm-source-projectile-files-list
   (helm-build-sync-source "Projectile files"
-    :before-init-hook (lambda ()
-                        (add-hook 'helm-after-update-hook #'helm-projectile--move-to-real)
-                        (add-hook 'helm-cleanup-hook #'helm-projectile--remove-move-to-real))
+    :before-init-hook 'helm-source-projectile-files-list-before-init-hook
     :candidates (lambda ()
                   (when (projectile-project-p)
                     (with-helm-current-buffer

@bbatsov is this workaround good enough? Or do you have something else in mind?

bbatsov commented 2 years ago

I don't follow the upstream changes in Helm, so it's hard to say what's the best approach here.

ghost commented 2 years ago

I was able to correct it with the following change.

   (remove-hook 'helm-after-update-hook #'helm-projectile--move-to-real)
   (remove-hook 'helm-cleanup-hook #'helm-projectile--remove-move-to-real))

+(defun helm-source-projectile-files-list-before-init-hook ()
+  (add-hook 'helm-after-update-hook #'helm-projectile--move-to-real)
+  (add-hook 'helm-cleanup-hook #'helm-projectile--remove-move-to-real))
+
 (defvar helm-source-projectile-files-list
   (helm-build-sync-source "Projectile files"
-    :before-init-hook (lambda ()
-                        (add-hook 'helm-after-update-hook #'helm-projectile--move-to-real)
-                        (add-hook 'helm-cleanup-hook #'helm-projectile--remove-move-to-real))
+    :before-init-hook 'helm-source-projectile-files-list-before-init-hook
     :candidates (lambda ()
                   (when (projectile-project-p)
                     (with-helm-current-buffer

@bbatsov is this workaround good enough? Or do you have something else in mind?

if you patch it like this, helm projectile find file will not work ...

luizalbertocviana commented 2 years ago

@yuchunzhou you are right, thanks for noticing that. Try this instead:

   (remove-hook 'helm-after-update-hook #'helm-projectile--move-to-real)
   (remove-hook 'helm-cleanup-hook #'helm-projectile--remove-move-to-real))

+(defvar helm-source-projectile-files-list-before-init-hook
+  (lambda ()
+    (add-hook 'helm-after-update-hook #'helm-projectile--move-to-real)
+    (add-hook 'helm-cleanup-hook #'helm-projectile--remove-move-to-real)))
+
 (defvar helm-source-projectile-files-list
   (helm-build-sync-source "Projectile files"
-    :before-init-hook (lambda ()
-                        (add-hook 'helm-after-update-hook #'helm-projectile--move-to-real)
-                        (add-hook 'helm-cleanup-hook #'helm-projectile--remove-move-to-real))
+    :before-init-hook 'helm-source-projectile-files-list-before-init-hook
     :candidates (lambda ()
                   (when (projectile-project-p)
                     (with-helm-current-buffer
ghost commented 2 years ago

Maybe to find the reason in upstream helm code base is the right direction, so i close this issue right now.