From 3bd573fe13446ff4ec8b8fa15a93aec5a0b1f646 Mon Sep 17 00:00:00 2001 From: "Jose A. Ortega Ruiz" Date: Fri, 20 Feb 2009 01:02:24 +0100 Subject: [PATCH] FUEL: New refactoring command: fuel-refactor-make-generic. --- misc/fuel/README | 2 ++ misc/fuel/fuel-mode.el | 1 + misc/fuel/fuel-refactor.el | 22 ++++++++++++++++++++++ misc/fuel/fuel-syntax.el | 7 ++++--- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/misc/fuel/README b/misc/fuel/README index 79b8f49f9a..0411e0709b 100644 --- a/misc/fuel/README +++ b/misc/fuel/README @@ -139,6 +139,8 @@ beast. | C-cC-xi | replace word by its definition (fuel-refactor-inline-word) | | C-cC-xw | rename all uses of a word (fuel-refactor-rename-word) | | C-cC-xa | extract region as a separate ARTICLE: form | + | C-cC-xg | convert current word definition into GENERIC + method | + | | (fuel-refactor-make-generic) | |-----------------+------------------------------------------------------------| *** In the listener: diff --git a/misc/fuel/fuel-mode.el b/misc/fuel/fuel-mode.el index c4f08f3c62..aa9a7d944e 100644 --- a/misc/fuel/fuel-mode.el +++ b/misc/fuel/fuel-mode.el @@ -213,6 +213,7 @@ interacting with a factor listener is at your disposal. (fuel-mode--key ?x ?a 'fuel-refactor-extract-article) (fuel-mode--key ?x ?i 'fuel-refactor-inline-word) +(fuel-mode--key ?x ?g 'fuel-refactor-make-generic) (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) diff --git a/misc/fuel/fuel-refactor.el b/misc/fuel/fuel-refactor.el index bd62227755..942d439466 100644 --- a/misc/fuel/fuel-refactor.el +++ b/misc/fuel/fuel-refactor.el @@ -145,6 +145,28 @@ word." (if (looking-at-p ";") (point) (fuel-syntax--end-of-symbol-pos)))) + +;;; Convert word to generic + method: + +(defun fuel-refactor-make-generic () + "Inserts a new generic definition with the current word's stack effect. +The word's body is put in a new method for the generic." + (interactive) + (let ((p (point))) + (fuel-syntax--beginning-of-defun) + (unless (re-search-forward fuel-syntax--word-signature-regex nil t) + (goto-char p) + (error "Cannot find a proper word definition here")) + (let ((begin (match-beginning 0)) + (end (match-end 0)) + (name (match-string-no-properties 1)) + (cls (read-string "Method's class (object): " nil nil "object"))) + (goto-char begin) + (insert "GENERIC") + (goto-char (+ end 7)) + (newline 2) + (insert "M: " cls " " name " ")))) + ;;; Inline word: diff --git a/misc/fuel/fuel-syntax.el b/misc/fuel/fuel-syntax.el index 67341120c1..b6409b2fea 100644 --- a/misc/fuel/fuel-syntax.el +++ b/misc/fuel/fuel-syntax.el @@ -212,10 +212,11 @@ fuel-syntax--end-of-def-line-regex fuel-syntax--single-liner-regex)) +(defconst fuel-syntax--word-signature-regex + (format ":[^ ]* \\([^ ]+\\)\\(%s\\)*" fuel-syntax--stack-effect-regex)) + (defconst fuel-syntax--defun-signature-regex - (format "\\(%s\\|%s\\)" - (format ":[^ ]* [^ ]+\\(%s\\)*" fuel-syntax--stack-effect-regex) - "M[^:]*: [^ ]+ [^ ]+")) + (format "\\(%s\\|%s\\)" fuel-syntax--word-signature-regex "M[^:]*: [^ ]+ [^ ]+")) (defconst fuel-syntax--constructor-decl-regex "\\_