FUEL: New refactoring command: fuel-refactor-make-generic.
							parent
							
								
									52365c76fd
								
							
						
					
					
						commit
						3bd573fe13
					
				| 
						 | 
				
			
			@ -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:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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:
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
  "\\_<C: +\\(\\w+\\) +\\(\\w+\\)\\( .*\\)?$")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue