684 |
(eq (car-safe (nth 3 cmd)) 'calc-execute-kbd-macro))) |
(eq (car-safe (nth 3 cmd)) 'calc-execute-kbd-macro))) |
685 |
(let* ((mac (elt (nth 1 (nth 3 cmd)) 1)) |
(let* ((mac (elt (nth 1 (nth 3 cmd)) 1)) |
686 |
(str (edmacro-format-keys mac t)) |
(str (edmacro-format-keys mac t)) |
|
(macbeg) |
|
687 |
(kys (nth 3 (nth 3 cmd)))) |
(kys (nth 3 (nth 3 cmd)))) |
688 |
(calc-edit-mode |
(calc-edit-mode |
689 |
(list 'calc-edit-macro-finish-edit cmdname kys) |
(list 'calc-edit-macro-finish-edit cmdname kys) |
690 |
t (format "Editing keyboard macro (%s, bound to %s).\n" |
t (format (concat |
691 |
cmdname kys)) |
"Editing keyboard macro (%s, bound to %s).\n" |
692 |
(goto-char (point-max)) |
"Original keys: %s \n") |
693 |
(insert "Original keys: " (elt (nth 1 (nth 3 cmd)) 0) "\n" ) |
cmdname kys (elt (nth 1 (nth 3 cmd)) 0))) |
|
(setq macbeg (point)) |
|
694 |
(insert str "\n") |
(insert str "\n") |
695 |
(calc-edit-format-macro-buffer) |
(calc-edit-format-macro-buffer) |
696 |
(calc-show-edit-buffer) |
(calc-show-edit-buffer))) |
|
(goto-char (point-min)) |
|
|
(search-forward "Original") |
|
|
(forward-line 2))) |
|
697 |
(t (let* ((func (calc-stack-command-p cmd)) |
(t (let* ((func (calc-stack-command-p cmd)) |
698 |
(defn (and func |
(defn (and func |
699 |
(symbolp func) |
(symbolp func) |
712 |
(insert (math-showing-full-precision |
(insert (math-showing-full-precision |
713 |
(math-format-nice-expr defn (frame-width))) |
(math-format-nice-expr defn (frame-width))) |
714 |
"\n")) |
"\n")) |
715 |
(calc-show-edit-buffer) |
(calc-show-edit-buffer)) |
|
(goto-char (point-min)) |
|
|
(forward-line 3)) |
|
716 |
(error "That command's definition cannot be edited"))))))) |
(error "That command's definition cannot be edited"))))))) |
717 |
|
|
718 |
;; Formatting the macro buffer |
;; Formatting the macro buffer |
719 |
|
|
720 |
(defun calc-edit-macro-repeats () |
(defun calc-edit-macro-repeats () |
721 |
(goto-char (point-min)) |
(goto-char calc-edit-top) |
722 |
(while |
(while |
723 |
(re-search-forward "^\\([0-9]+\\)\\*" nil t) |
(re-search-forward "^\\([0-9]+\\)\\*" nil t) |
724 |
(setq num (string-to-int (match-string 1))) |
(setq num (string-to-int (match-string 1))) |
731 |
|
|
732 |
(defun calc-edit-macro-adjust-buffer () |
(defun calc-edit-macro-adjust-buffer () |
733 |
(calc-edit-macro-repeats) |
(calc-edit-macro-repeats) |
734 |
(goto-char (point-min)) |
(goto-char calc-edit-top) |
735 |
(while (re-search-forward "^RET$" nil t) |
(while (re-search-forward "^RET$" nil t) |
736 |
(delete-char 1)) |
(delete-char 1)) |
737 |
(goto-char (point-min)) |
(goto-char calc-edit-top) |
738 |
(while (and (re-search-forward "^$" nil t) |
(while (and (re-search-forward "^$" nil t) |
739 |
(not (= (point) (point-max)))) |
(not (= (point) (point-max)))) |
740 |
(delete-char 1))) |
(delete-char 1))) |
862 |
(defun calc-edit-format-macro-buffer () |
(defun calc-edit-format-macro-buffer () |
863 |
"Rewrite the Calc macro editing buffer." |
"Rewrite the Calc macro editing buffer." |
864 |
(calc-edit-macro-adjust-buffer) |
(calc-edit-macro-adjust-buffer) |
865 |
(goto-char (point-min)) |
(goto-char calc-edit-top) |
|
(search-forward "Original keys:") |
|
|
(forward-line 1) |
|
|
(insert "\n") |
|
|
(skip-chars-forward " \t\n") |
|
866 |
(let ((type (calc-edit-macro-command-type))) |
(let ((type (calc-edit-macro-command-type))) |
867 |
(while (not (string-equal type "")) |
(while (not (string-equal type "")) |
868 |
(cond |
(cond |
902 |
(calc-edit-macro-combine-var-name)) |
(calc-edit-macro-combine-var-name)) |
903 |
(t (forward-line 1))) |
(t (forward-line 1))) |
904 |
(setq type (calc-edit-macro-command-type)))) |
(setq type (calc-edit-macro-command-type)))) |
905 |
(goto-char (point-min))) |
(goto-char calc-edit-top)) |
906 |
|
|
907 |
;; Finish editing the macro |
;; Finish editing the macro |
908 |
|
|
909 |
(defun calc-edit-macro-pre-finish-edit () |
(defun calc-edit-macro-pre-finish-edit () |
910 |
(goto-char (point-min)) |
(goto-char calc-edit-top) |
911 |
(while (re-search-forward "\\(^\\| \\)RET\\($\\|\t\\| \\)" nil t) |
(while (re-search-forward "\\(^\\| \\)RET\\($\\|\t\\| \\)" nil t) |
912 |
(search-backward "RET") |
(search-backward "RET") |
913 |
(delete-char 3) |
(delete-char 3) |
914 |
(insert "<return>"))) |
(insert "<return>"))) |
915 |
|
|
916 |
|
(defvar calc-edit-top) |
917 |
(defun calc-edit-macro-finish-edit (cmdname key) |
(defun calc-edit-macro-finish-edit (cmdname key) |
918 |
"Finish editing a Calc macro. |
"Finish editing a Calc macro. |
919 |
Redefine the corresponding command." |
Redefine the corresponding command." |
920 |
(interactive) |
(interactive) |
921 |
(let ((cmd (intern cmdname))) |
(let ((cmd (intern cmdname))) |
922 |
(calc-edit-macro-pre-finish-edit) |
(calc-edit-macro-pre-finish-edit) |
923 |
(goto-char (point-max)) |
(let* ((str (buffer-substring calc-edit-top (point-max))) |
|
(re-search-backward "^Original keys:") |
|
|
(forward-line 1) |
|
|
(let* ((str (buffer-substring (point) (point-max))) |
|
924 |
(mac (edmacro-parse-keys str t))) |
(mac (edmacro-parse-keys str t))) |
925 |
(if (= (length mac) 0) |
(if (= (length mac) 0) |
926 |
(fmakunbound cmd) |
(fmakunbound cmd) |
933 |
'arg key))))))) |
'arg key))))))) |
934 |
|
|
935 |
(defun calc-finish-formula-edit (func) |
(defun calc-finish-formula-edit (func) |
|
(goto-char (point-min)) |
|
|
(forward-line 3) |
|
936 |
(let ((buf (current-buffer)) |
(let ((buf (current-buffer)) |
937 |
(str (buffer-substring (point) (point-max))) |
(str (buffer-substring calc-edit-top (point-max))) |
938 |
(start (point)) |
(start (point)) |
939 |
(body (calc-valid-formula-func func))) |
(body (calc-valid-formula-func func))) |
940 |
(set-buffer calc-original-buffer) |
(set-buffer calc-original-buffer) |