| 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:
(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)
(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:
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+\\)\\( .*\\)?$")