]> gitweb.factorcode.org Git - factor.git/commitdiff
FUEL: New refactoring command: fuel-refactor-make-generic.
authorJose A. Ortega Ruiz <jao@gnu.org>
Fri, 20 Feb 2009 00:02:24 +0000 (01:02 +0100)
committerJose A. Ortega Ruiz <jao@gnu.org>
Fri, 20 Feb 2009 00:02:24 +0000 (01:02 +0100)
misc/fuel/README
misc/fuel/fuel-mode.el
misc/fuel/fuel-refactor.el
misc/fuel/fuel-syntax.el

index 79b8f49f9af67e9aa5fd6ce73b17c327d227f90b..0411e0709bf86bd09d46862d1a335c16f513e4a8 100644 (file)
@@ -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:
index c4f08f3c6205f40cfefb064940ba2c003dc6d45d..aa9a7d944e17f2de75089370ec86fc2299a49e15 100644 (file)
@@ -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)
index bd622277551b170cc0841833be19a0a0aac111f4..942d4394662fc28a0b7c1769a2ceb3f259fd4cc9 100644 (file)
@@ -145,6 +145,28 @@ word."
                                 (if (looking-at-p ";") (point)
                                   (fuel-syntax--end-of-symbol-pos))))
 
+\f
+;;; 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 " "))))
+
 \f
 ;;; Inline word:
 
index 67341120c1e1d8bd87da7c9165f36a2f84da2dea..b6409b2fead9606ed62d91b375f7d832042948a7 100644 (file)
           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
   "\\_<C: +\\(\\w+\\) +\\(\\w+\\)\\( .*\\)?$")