]> git.eshelyaron.com Git - emacs.git/commitdiff
(refactor-backends): Support local refactor-backend-functions
authorEshel Yaron <me@eshelyaron.com>
Wed, 10 Apr 2024 19:29:32 +0000 (21:29 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 10 Apr 2024 19:29:32 +0000 (21:29 +0200)
lisp/progmodes/refactor.el

index d02675b8e1d243bd5e68e02196f5690a47ffa139..ac9e9128c759b34d8cccf4f955451f292c154ca3 100644 (file)
@@ -74,18 +74,23 @@ operations that BACKEND supports.")
 
 (defun refactor-backends ()
   "Return alist of refactor operations and backends that support them."
-  (let ((act-be-alist nil))
-    (pcase-dolist (`(,be . ,acts)
-                   (seq-keep #'funcall refactor-backend-functions))
-      (dolist (act acts)
-        (push be (alist-get act act-be-alist))))
-    act-be-alist))
+  (let ((op-be-alist nil))
+    (run-hook-wrapped
+     'refactor-backend-functions
+     (lambda (be-fun &rest _)
+       (pcase (funcall be-fun)
+         (`(,be . ,ops)
+          (dolist (op ops)
+            (push be (alist-get op op-be-alist)))))))
+    op-be-alist))
 
 ;;;###autoload
 (defun refactor (operation backend)
   (interactive
    (let* ((op-be-alist (refactor-backends))
-          (op (funcall refactor-read-operation-function op-be-alist)))
+          (op (if op-be-alist
+                  (funcall refactor-read-operation-function op-be-alist)
+                (user-error "No refactor operations available"))))
      (list op (car (alist-get op op-be-alist)))))
   (pcase operation
     ('rename (refactor-rename backend))
@@ -94,8 +99,7 @@ operations that BACKEND supports.")
     ;; ('inline (refactor-inline backend))
     ;; ('organize (refactor-organize backend))
     ;; ('simplify (refactor-simplify backend))
-    (_ (refactor-backend-custom-operation backend operation))
-    ))
+    (_ (refactor-backend-custom-operation backend operation))))
 
 (cl-defgeneric refactor-backend-custom-operation (backend operation)
   "Apply custom refactoring OPERATION provided by BACKEND.")