diff --git a/misc/fuel/README b/misc/fuel/README index 759f26c1b2..69e5a98299 100644 --- a/misc/fuel/README +++ b/misc/fuel/README @@ -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: diff --git a/misc/fuel/fuel-mode.el b/misc/fuel/fuel-mode.el index e30443f4fd..88ad73864a 100644 --- a/misc/fuel/fuel-mode.el +++ b/misc/fuel/fuel-mode.el @@ -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 ?r 'fuel-refactor-extract-region) -(fuel-mode--key ?x ?v 'fuel-refactor-extract-vocab) (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 ?w 'fuel-refactor-rename-word) (fuel-mode--key ?d ?> 'fuel-show-callees) (fuel-mode--key ?d ?< 'fuel-show-callers) diff --git a/misc/fuel/fuel-refactor.el b/misc/fuel/fuel-refactor.el index f44234ae1b..061adbb82c 100644 --- a/misc/fuel/fuel-refactor.el +++ b/misc/fuel/fuel-refactor.el @@ -18,6 +18,8 @@ (require 'fuel-syntax) (require 'fuel-base) +(require 'etags) + ;;; Word definitions in buffer @@ -167,7 +169,28 @@ word." ;;; 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)))) ;;; Extract vocab: diff --git a/misc/fuel/fuel-syntax.el b/misc/fuel/fuel-syntax.el index 66b77df49e..6f33eb2993 100644 --- a/misc/fuel/fuel-syntax.el +++ b/misc/fuel/fuel-syntax.el @@ -244,7 +244,8 @@ ;; Comments: ("\\_<\\(#?!\\) .*\\(\n\\|$\\)" (1 "<") (2 ">")) ("\\_<\\(#?!\\)\\(\n\\|$\\)" (1 "<") (2 ">")) - ("\\_<\\((\\) \\([^)\n]*?\\) \\()\\)\\_>" (1 "b")) + (" \\((\\)( \\([^\n]*\\) )\\()\\)\\( \\|\n\\)" (1 "b")) + (" \\((\\) \\([^\n]*\\) \\()\\)\\( \\|\n\\)" (1 "b")) ;; Strings ("\\( \\|^\\)\\(\"\\)[^\n\r\f]*\\(\"\\)\\( \\|\n\\)" (2 "\"") (3 "\"")) ("\\_<<\\(\"\\)\\_>" (1 "