From ae2e9b41929bf99d4e1ed6702a2e0bf17c69c1a6 Mon Sep 17 00:00:00 2001 From: "Jose A. Ortega Ruiz" Date: Thu, 22 Jan 2009 23:25:17 +0100 Subject: [PATCH 1/2] FUEL: New refactoring: rename word. --- misc/fuel/README | 1 + misc/fuel/fuel-mode.el | 7 ++++--- misc/fuel/fuel-refactor.el | 23 +++++++++++++++++++++++ misc/fuel/fuel-xref.el | 12 +++++++++--- 4 files changed, 37 insertions(+), 6 deletions(-) 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-xref.el b/misc/fuel/fuel-xref.el index cae7923bee..4d444ebe3e 100644 --- a/misc/fuel/fuel-xref.el +++ b/misc/fuel/fuel-xref.el @@ -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)))) From 742241e8815c03409da54e4bd47f84903f027eb3 Mon Sep 17 00:00:00 2001 From: "Jose A. Ortega Ruiz" Date: Fri, 23 Jan 2009 00:23:11 +0100 Subject: [PATCH 2/2] FUEL: Fix for stack effect recognition. --- misc/fuel/fuel-syntax.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 "