comparison lisp/calc/calc-prog.el @ 59309:5a2b8e50c551

(calc-edit-macro-finish-edit, calc-finish-formula-edit) (calc-macro-repeats, calc-edit-macro-adjust-buffer) calc-edit-format-macro-buffer, calc-edit-macro-pre-finish-edit): Use calc-edit-top for the beginning of the edited object. (calc-user-define-edit): Change the header for editing macros. Remove unnecessary variable.
author Jay Belanger <jay.p.belanger@gmail.com>
date Sun, 02 Jan 2005 17:08:31 +0000
parents 603f6649f30b
children 5f8090982771 cb67264d6096
comparison
equal deleted inserted replaced
59308:8f487d424820 59309:5a2b8e50c551
682 (cond ((or (stringp cmd) 682 (cond ((or (stringp cmd)
683 (and (consp cmd) 683 (and (consp cmd)
684 (eq (car-safe (nth 3 cmd)) 'calc-execute-kbd-macro))) 684 (eq (car-safe (nth 3 cmd)) 'calc-execute-kbd-macro)))
685 (let* ((mac (elt (nth 1 (nth 3 cmd)) 1)) 685 (let* ((mac (elt (nth 1 (nth 3 cmd)) 1))
686 (str (edmacro-format-keys mac t)) 686 (str (edmacro-format-keys mac t))
687 (macbeg)
688 (kys (nth 3 (nth 3 cmd)))) 687 (kys (nth 3 (nth 3 cmd))))
689 (calc-edit-mode 688 (calc-edit-mode
690 (list 'calc-edit-macro-finish-edit cmdname kys) 689 (list 'calc-edit-macro-finish-edit cmdname kys)
691 t (format "Editing keyboard macro (%s, bound to %s).\n" 690 t (format (concat
692 cmdname kys)) 691 "Editing keyboard macro (%s, bound to %s).\n"
693 (goto-char (point-max)) 692 "Original keys: %s \n")
694 (insert "Original keys: " (elt (nth 1 (nth 3 cmd)) 0) "\n" ) 693 cmdname kys (elt (nth 1 (nth 3 cmd)) 0)))
695 (setq macbeg (point))
696 (insert str "\n") 694 (insert str "\n")
697 (calc-edit-format-macro-buffer) 695 (calc-edit-format-macro-buffer)
698 (calc-show-edit-buffer) 696 (calc-show-edit-buffer)))
699 (goto-char (point-min))
700 (search-forward "Original")
701 (forward-line 2)))
702 (t (let* ((func (calc-stack-command-p cmd)) 697 (t (let* ((func (calc-stack-command-p cmd))
703 (defn (and func 698 (defn (and func
704 (symbolp func) 699 (symbolp func)
705 (get func 'calc-user-defn))) 700 (get func 'calc-user-defn)))
706 (kys (concat "z" (char-to-string (car def)))) 701 (kys (concat "z" (char-to-string (car def))))
715 (format "Editing formula (%s, %s, bound to %s).\n" 710 (format "Editing formula (%s, %s, bound to %s).\n"
716 intcmd algcmd kys)) 711 intcmd algcmd kys))
717 (insert (math-showing-full-precision 712 (insert (math-showing-full-precision
718 (math-format-nice-expr defn (frame-width))) 713 (math-format-nice-expr defn (frame-width)))
719 "\n")) 714 "\n"))
720 (calc-show-edit-buffer) 715 (calc-show-edit-buffer))
721 (goto-char (point-min))
722 (forward-line 3))
723 (error "That command's definition cannot be edited"))))))) 716 (error "That command's definition cannot be edited")))))))
724 717
725 ;; Formatting the macro buffer 718 ;; Formatting the macro buffer
726 719
727 (defun calc-edit-macro-repeats () 720 (defun calc-edit-macro-repeats ()
728 (goto-char (point-min)) 721 (goto-char calc-edit-top)
729 (while 722 (while
730 (re-search-forward "^\\([0-9]+\\)\\*" nil t) 723 (re-search-forward "^\\([0-9]+\\)\\*" nil t)
731 (setq num (string-to-int (match-string 1))) 724 (setq num (string-to-int (match-string 1)))
732 (setq line (buffer-substring (point) (line-end-position))) 725 (setq line (buffer-substring (point) (line-end-position)))
733 (goto-char (line-beginning-position)) 726 (goto-char (line-beginning-position))
736 (insert line "\n") 729 (insert line "\n")
737 (setq num (1- num))))) 730 (setq num (1- num)))))
738 731
739 (defun calc-edit-macro-adjust-buffer () 732 (defun calc-edit-macro-adjust-buffer ()
740 (calc-edit-macro-repeats) 733 (calc-edit-macro-repeats)
741 (goto-char (point-min)) 734 (goto-char calc-edit-top)
742 (while (re-search-forward "^RET$" nil t) 735 (while (re-search-forward "^RET$" nil t)
743 (delete-char 1)) 736 (delete-char 1))
744 (goto-char (point-min)) 737 (goto-char calc-edit-top)
745 (while (and (re-search-forward "^$" nil t) 738 (while (and (re-search-forward "^$" nil t)
746 (not (= (point) (point-max)))) 739 (not (= (point) (point-max))))
747 (delete-char 1))) 740 (delete-char 1)))
748 741
749 (defun calc-edit-macro-command () 742 (defun calc-edit-macro-command ()
867 (insert ";; calc digits\n"))) 860 (insert ";; calc digits\n")))
868 861
869 (defun calc-edit-format-macro-buffer () 862 (defun calc-edit-format-macro-buffer ()
870 "Rewrite the Calc macro editing buffer." 863 "Rewrite the Calc macro editing buffer."
871 (calc-edit-macro-adjust-buffer) 864 (calc-edit-macro-adjust-buffer)
872 (goto-char (point-min)) 865 (goto-char calc-edit-top)
873 (search-forward "Original keys:")
874 (forward-line 1)
875 (insert "\n")
876 (skip-chars-forward " \t\n")
877 (let ((type (calc-edit-macro-command-type))) 866 (let ((type (calc-edit-macro-command-type)))
878 (while (not (string-equal type "")) 867 (while (not (string-equal type ""))
879 (cond 868 (cond
880 ((or 869 ((or
881 (string-equal type "calc-algebraic-entry") 870 (string-equal type "calc-algebraic-entry")
911 (forward-line 1) 900 (forward-line 1)
912 (calc-edit-macro-combine-var-name) 901 (calc-edit-macro-combine-var-name)
913 (calc-edit-macro-combine-var-name)) 902 (calc-edit-macro-combine-var-name))
914 (t (forward-line 1))) 903 (t (forward-line 1)))
915 (setq type (calc-edit-macro-command-type)))) 904 (setq type (calc-edit-macro-command-type))))
916 (goto-char (point-min))) 905 (goto-char calc-edit-top))
917 906
918 ;; Finish editing the macro 907 ;; Finish editing the macro
919 908
920 (defun calc-edit-macro-pre-finish-edit () 909 (defun calc-edit-macro-pre-finish-edit ()
921 (goto-char (point-min)) 910 (goto-char calc-edit-top)
922 (while (re-search-forward "\\(^\\| \\)RET\\($\\|\t\\| \\)" nil t) 911 (while (re-search-forward "\\(^\\| \\)RET\\($\\|\t\\| \\)" nil t)
923 (search-backward "RET") 912 (search-backward "RET")
924 (delete-char 3) 913 (delete-char 3)
925 (insert "<return>"))) 914 (insert "<return>")))
926 915
916 (defvar calc-edit-top)
927 (defun calc-edit-macro-finish-edit (cmdname key) 917 (defun calc-edit-macro-finish-edit (cmdname key)
928 "Finish editing a Calc macro. 918 "Finish editing a Calc macro.
929 Redefine the corresponding command." 919 Redefine the corresponding command."
930 (interactive) 920 (interactive)
931 (let ((cmd (intern cmdname))) 921 (let ((cmd (intern cmdname)))
932 (calc-edit-macro-pre-finish-edit) 922 (calc-edit-macro-pre-finish-edit)
933 (goto-char (point-max)) 923 (let* ((str (buffer-substring calc-edit-top (point-max)))
934 (re-search-backward "^Original keys:")
935 (forward-line 1)
936 (let* ((str (buffer-substring (point) (point-max)))
937 (mac (edmacro-parse-keys str t))) 924 (mac (edmacro-parse-keys str t)))
938 (if (= (length mac) 0) 925 (if (= (length mac) 0)
939 (fmakunbound cmd) 926 (fmakunbound cmd)
940 (fset cmd 927 (fset cmd
941 (list 'lambda '(arg) 928 (list 'lambda '(arg)
944 (vector (key-description mac) 931 (vector (key-description mac)
945 mac) 932 mac)
946 'arg key))))))) 933 'arg key)))))))
947 934
948 (defun calc-finish-formula-edit (func) 935 (defun calc-finish-formula-edit (func)
949 (goto-char (point-min))
950 (forward-line 3)
951 (let ((buf (current-buffer)) 936 (let ((buf (current-buffer))
952 (str (buffer-substring (point) (point-max))) 937 (str (buffer-substring calc-edit-top (point-max)))
953 (start (point)) 938 (start (point))
954 (body (calc-valid-formula-func func))) 939 (body (calc-valid-formula-func func)))
955 (set-buffer calc-original-buffer) 940 (set-buffer calc-original-buffer)
956 (let ((val (math-read-expr str))) 941 (let ((val (math-read-expr str)))
957 (if (eq (car-safe val) 'error) 942 (if (eq (car-safe val) 'error)