]> gitweb.factorcode.org Git - factor.git/commitdiff
FUEL: New refactoring: rename word.
authorJose A. Ortega Ruiz <jao@gnu.org>
Thu, 22 Jan 2009 22:25:17 +0000 (23:25 +0100)
committerJose A. Ortega Ruiz <jao@gnu.org>
Thu, 22 Jan 2009 22:25:17 +0000 (23:25 +0100)
misc/fuel/README
misc/fuel/fuel-mode.el
misc/fuel/fuel-refactor.el
misc/fuel/fuel-xref.el

index 759f26c1b2efd116a7e5b742db11600b2b50eb4e..69e5a982995de36c7578ecdc4cd072fead7f5895 100644 (file)
@@ -122,6 +122,7 @@ beast.
     - C-cC-xr : extract region as a separate word
     - C-cC-xi : replace word at point by its definition
     - C-cC-xv : extract region as a separate vocabulary
+    - C-cC-xw : rename all uses of a word
 
 *** In the listener:
 
index e30443f4fd03c0691658d19ef219d7f13244d8bd..88ad73864a31df751bb1bcfea97bafe5acee9216 100644 (file)
@@ -198,10 +198,11 @@ interacting with a factor listener is at your disposal.
 (fuel-mode--key ?e ?w 'fuel-edit-word)
 (fuel-mode--key ?e ?x 'fuel-eval-definition)
 
-(fuel-mode--key ?x ?s 'fuel-refactor-extract-sexp)
+(fuel-mode--key ?x ?i 'fuel-refactor-inline-word)
 (fuel-mode--key ?x ?r 'fuel-refactor-extract-region)
+(fuel-mode--key ?x ?s 'fuel-refactor-extract-sexp)
 (fuel-mode--key ?x ?v 'fuel-refactor-extract-vocab)
-(fuel-mode--key ?x ?i 'fuel-refactor-inline-word)
+(fuel-mode--key ?x ?w 'fuel-refactor-rename-word)
 
 (fuel-mode--key ?d ?> 'fuel-show-callees)
 (fuel-mode--key ?d ?< 'fuel-show-callers)
index f44234ae1b62c64829fb820bfa4dd8fa12d94a7c..061adbb82c87bb3a1a59832e5a550c4cd3448b68 100644 (file)
@@ -18,6 +18,8 @@
 (require 'fuel-syntax)
 (require 'fuel-base)
 
+(require 'etags)
+
 \f
 ;;; Word definitions in buffer
 
@@ -167,7 +169,28 @@ word."
 \f
 ;;; Rename word:
 
+(defsubst fuel-refactor--rename-word (from to file)
+  (let ((files (fuel-xref--word-callers-files from)))
+    (tags-query-replace from to t `(cons ,file ',files))
+    files))
 
+(defun fuel-refactor--def-word ()
+  (save-excursion
+    (fuel-syntax--beginning-of-defun)
+    (or (and (looking-at fuel-syntax--method-definition-regex)
+             (match-string-no-properties 2))
+        (and (looking-at fuel-syntax--word-definition-regex)
+             (match-string-no-properties 2)))))
+
+(defun fuel-refactor-rename-word (&optional arg)
+  "Rename globally the word whose definition point is at.
+With prefix argument, use word at point instead."
+  (interactive "P")
+  (let* ((from (if arg (fuel-syntax-symbol-at-point) (fuel-refactor--def-word)))
+         (from (read-string "Rename word: " from))
+         (to (read-string (format "Rename '%s' to: " from)))
+         (buffer (current-buffer)))
+    (fuel-refactor--rename-word from to (buffer-file-name))))
 
 \f
 ;;; Extract vocab:
index cae7923bee145e833a5e1d904560abec14a3d443..4d444ebe3e19f0a58848a221d03775bc53387857 100644 (file)
@@ -128,11 +128,17 @@ cursor at the first ocurrence of the used word."
       (message "")
       (fuel-popup--display (fuel-xref--buffer)))))
 
+(defun fuel-xref--callers (word)
+  (let ((cmd `(:fuel* (((:quote ,word) fuel-callers-xref)))))
+    (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
+
 (defun fuel-xref--show-callers (word)
-  (let* ((cmd `(:fuel* (((:quote ,word) fuel-callers-xref))))
-         (res (fuel-eval--retort-result (fuel-eval--send/wait cmd))))
+  (let ((refs (fuel-xref--callers word)))
     (with-current-buffer (fuel-xref--buffer) (setq fuel-xref--word word))
-    (fuel-xref--fill-and-display word "using" res)))
+    (fuel-xref--fill-and-display word "using" refs)))
+
+(defun fuel-xref--word-callers-files (word)
+  (mapcar 'third (fuel-xref--callers word)))
 
 (defun fuel-xref--show-callees (word)
   (let* ((cmd `(:fuel* (((:quote ,word) fuel-callees-xref))))