FUEL: New refactoring: extract region as ARTICLE: (C-cC-xa).
parent
96d84731e3
commit
3ad52dd85b
|
@ -129,6 +129,7 @@ beast.
|
||||||
| | (fuel-refactor-extract-vocab) |
|
| | (fuel-refactor-extract-vocab) |
|
||||||
| C-cC-xi | replace word by its definition (fuel-refactor-inline-word) |
|
| 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-xw | rename all uses of a word (fuel-refactor-rename-word) |
|
||||||
|
| C-cC-xa | extract region as a separate ARTICLE: form |
|
||||||
|-----------------+------------------------------------------------------------|
|
|-----------------+------------------------------------------------------------|
|
||||||
|
|
||||||
*** In the listener:
|
*** In the listener:
|
||||||
|
|
|
@ -198,6 +198,7 @@ interacting with a factor listener is at your disposal.
|
||||||
(fuel-mode--key ?e ?w 'fuel-edit-word)
|
(fuel-mode--key ?e ?w 'fuel-edit-word)
|
||||||
(fuel-mode--key ?e ?x 'fuel-eval-definition)
|
(fuel-mode--key ?e ?x 'fuel-eval-definition)
|
||||||
|
|
||||||
|
(fuel-mode--key ?x ?a 'fuel-refactor-extract-article)
|
||||||
(fuel-mode--key ?x ?i 'fuel-refactor-inline-word)
|
(fuel-mode--key ?x ?i 'fuel-refactor-inline-word)
|
||||||
(fuel-mode--key ?x ?r 'fuel-refactor-extract-region)
|
(fuel-mode--key ?x ?r 'fuel-refactor-extract-region)
|
||||||
(fuel-mode--key ?x ?s 'fuel-refactor-extract-sexp)
|
(fuel-mode--key ?x ?s 'fuel-refactor-extract-sexp)
|
||||||
|
|
|
@ -78,17 +78,19 @@
|
||||||
(when found (setq result (fuel-refactor--reuse-p (car found)))))
|
(when found (setq result (fuel-refactor--reuse-p (car found)))))
|
||||||
(and result found))))
|
(and result found))))
|
||||||
|
|
||||||
(defun fuel-refactor--insert-word (word stack-effect code)
|
(defsubst fuel-refactor--insertion-point ()
|
||||||
(let ((beg (save-excursion (fuel-syntax--beginning-of-defun) (point)))
|
(max (save-excursion (fuel-syntax--beginning-of-defun) (point))
|
||||||
(end (save-excursion
|
(save-excursion
|
||||||
(re-search-backward fuel-syntax--end-of-def-regex nil t)
|
(re-search-backward fuel-syntax--end-of-def-regex nil t)
|
||||||
(forward-line 1)
|
(forward-line 1)
|
||||||
(skip-syntax-forward "-"))))
|
(skip-syntax-forward "-"))))
|
||||||
(let ((start (goto-char (max beg end))))
|
|
||||||
|
(defun fuel-refactor--insert-word (word stack-effect code)
|
||||||
|
(let ((start (goto-char (fuel-refactor--insertion-point))))
|
||||||
(open-line 1)
|
(open-line 1)
|
||||||
(insert ": " word " " stack-effect "\n" code " ;\n")
|
(insert ": " word " " stack-effect "\n" code " ;\n")
|
||||||
(indent-region start (point))
|
(indent-region start (point))
|
||||||
(move-overlay fuel-stack--overlay start (point)))))
|
(move-overlay fuel-stack--overlay start (point))))
|
||||||
|
|
||||||
(defun fuel-refactor--extract-other (start end code)
|
(defun fuel-refactor--extract-other (start end code)
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
|
@ -233,5 +235,30 @@ The region is extended to the closest definition boundaries."
|
||||||
(mark-defun)
|
(mark-defun)
|
||||||
(mark))))
|
(mark))))
|
||||||
|
|
||||||
|
;;; Extract article:
|
||||||
|
|
||||||
|
(defun fuel-refactor-extract-article (begin end)
|
||||||
|
"Extracts region as a new ARTICLE form."
|
||||||
|
(interactive "r")
|
||||||
|
(let ((topic (read-string "Article topic: "))
|
||||||
|
(title (read-string "Article title: ")))
|
||||||
|
(kill-region begin end)
|
||||||
|
(insert (format "{ $subsection %s }\n" topic))
|
||||||
|
(end-of-line 0)
|
||||||
|
(save-excursion
|
||||||
|
(goto-char (fuel-refactor--insertion-point))
|
||||||
|
(open-line 1)
|
||||||
|
(let ((start (point)))
|
||||||
|
(insert (format "ARTICLE: %S %S\n" topic title))
|
||||||
|
(yank)
|
||||||
|
(when (looking-at "^ *$") (end-of-line 0))
|
||||||
|
(insert " ;")
|
||||||
|
(unwind-protect
|
||||||
|
(progn
|
||||||
|
(move-overlay fuel-stack--overlay start (point))
|
||||||
|
(sit-for fuel-stack-highlight-period))
|
||||||
|
(delete-overlay fuel-stack--overlay))))))
|
||||||
|
|
||||||
|
|
||||||
(provide 'fuel-refactor)
|
(provide 'fuel-refactor)
|
||||||
;;; fuel-refactor.el ends here
|
;;; fuel-refactor.el ends here
|
||||||
|
|
|
@ -158,7 +158,9 @@
|
||||||
"PREDICATE" "PRIMITIVE"
|
"PREDICATE" "PRIMITIVE"
|
||||||
"UNION"))
|
"UNION"))
|
||||||
|
|
||||||
(defconst fuel-syntax--no-indent-def-starts '("SINGLETONS"
|
(defconst fuel-syntax--no-indent-def-starts '("ARTICLE"
|
||||||
|
"HELP"
|
||||||
|
"SINGLETONS"
|
||||||
"SYMBOLS"
|
"SYMBOLS"
|
||||||
"TUPLE"
|
"TUPLE"
|
||||||
"VARS"))
|
"VARS"))
|
||||||
|
@ -179,13 +181,12 @@
|
||||||
|
|
||||||
(defconst fuel-syntax--single-liner-regex
|
(defconst fuel-syntax--single-liner-regex
|
||||||
(regexp-opt '("ABOUT:"
|
(regexp-opt '("ABOUT:"
|
||||||
"ARTICLE:"
|
|
||||||
"ALIAS:"
|
"ALIAS:"
|
||||||
"CONSTANT:" "C:"
|
"CONSTANT:" "C:"
|
||||||
"DEFER:"
|
"DEFER:"
|
||||||
"FORGET:"
|
"FORGET:"
|
||||||
"GENERIC:" "GENERIC#"
|
"GENERIC:" "GENERIC#"
|
||||||
"HELP:" "HEX:" "HOOK:"
|
"HEX:" "HOOK:"
|
||||||
"IN:" "INSTANCE:"
|
"IN:" "INSTANCE:"
|
||||||
"LIBRARY:"
|
"LIBRARY:"
|
||||||
"MAIN:" "MATH:" "MIXIN:"
|
"MAIN:" "MATH:" "MIXIN:"
|
||||||
|
|
Loading…
Reference in New Issue