- 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:
(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)
(require 'fuel-syntax)
(require 'fuel-base)
+(require 'etags)
+
\f
;;; Word definitions in buffer
\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:
(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))))