/[emacs]/emacs/lisp/calc/calc-embed.el
ViewVC logotype

Diff of /emacs/lisp/calc/calc-embed.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by eliz, Tue Nov 13 07:28:01 2001 UTC revision 1.3 by walters, Wed Nov 14 09:02:55 2001 UTC
# Line 35  Line 35 
35     (calc-set-command-flag 'renum-stack)     (calc-set-command-flag 'renum-stack)
36     (message (if (calc-change-mode 'calc-show-plain n nil t)     (message (if (calc-change-mode 'calc-show-plain n nil t)
37                  "Including \"plain\" formulas in Calc Embedded mode."                  "Including \"plain\" formulas in Calc Embedded mode."
38                "Omitting \"plain\" formulas in Calc Embedded mode.")))                "Omitting \"plain\" formulas in Calc Embedded mode."))))
 )  
39    
40    
41    
# Line 251  This is not required to be present for u Line 250  This is not required to be present for u
250                     (if calc-embedded-quiet                     (if calc-embedded-quiet
251                         "Type `M-# x'"                         "Type `M-# x'"
252                       "Give this command again")))))                       "Give this command again")))))
253    (scroll-down 0)    ; fix a bug which occurs when truncate-lines is changed.    (scroll-down 0))    ; fix a bug which occurs when truncate-lines is changed.
 )  
254  (setq calc-embedded-quiet nil)  (setq calc-embedded-quiet nil)
255    
256    
# Line 267  This is not required to be present for u Line 265  This is not required to be present for u
265             (and (eq (car-safe (aref calc-embedded-info 8)) 'calcFunc-evalto)             (and (eq (car-safe (aref calc-embedded-info 8)) 'calcFunc-evalto)
266                  (eq (car-safe (nth 1 (aref calc-embedded-info 8)))                  (eq (car-safe (nth 1 (aref calc-embedded-info 8)))
267                      'calcFunc-assign)))                      'calcFunc-assign)))
268         (calc-select-part 2))         (calc-select-part 2)))
 )  
269    
270    
271  (defun calc-embedded-update-formula (arg)  (defun calc-embedded-update-formula (arg)
# Line 294  This is not required to be present for u Line 291  This is not required to be present for u
291              (progn              (progn
292                (save-excursion                (save-excursion
293                  (calc-embedded-update info 14 'eval t))                  (calc-embedded-update info 14 'eval t))
294                (goto-char (+ (aref info 4) pt)))))))                (goto-char (+ (aref info 4) pt))))))))
 )  
295    
296    
297  (defun calc-embedded-edit (arg)  (defun calc-embedded-edit (arg)
# Line 311  This is not required to be present for u Line 307  This is not required to be present for u
307                  (math-format-nice-expr (aref info 8) (frame-width))))                  (math-format-nice-expr (aref info 8) (frame-width))))
308       (calc-edit-mode (list 'calc-embedded-finish-edit info))       (calc-edit-mode (list 'calc-embedded-finish-edit info))
309       (insert str "\n")))       (insert str "\n")))
310    (calc-show-edit-buffer)    (calc-show-edit-buffer))
 )  
311    
312  (defun calc-embedded-finish-edit (info)  (defun calc-embedded-finish-edit (info)
313    (let ((buf (current-buffer))    (let ((buf (current-buffer))
# Line 332  This is not required to be present for u Line 327  This is not required to be present for u
327              (error (nth 2 val))))              (error (nth 2 val))))
328        (calc-embedded-original-buffer t info)        (calc-embedded-original-buffer t info)
329        (aset info 8 val)        (aset info 8 val)
330        (calc-embedded-update info 14 t t)))        (calc-embedded-update info 14 t t))))
 )  
331    
332  (defun calc-do-embedded-activate (arg cbuf)  (defun calc-do-embedded-activate (arg cbuf)
333    (calc-plain-buffer-only)    (calc-plain-buffer-only)
# Line 362  This is not required to be present for u Line 356  This is not required to be present for u
356            (or (eq (car-safe (aref info 8)) 'error)            (or (eq (car-safe (aref info 8)) 'error)
357                (goto-char (aref info 5))))))                (goto-char (aref info 5))))))
358      (message "Activating %s for Calc Embedded mode...done" (buffer-name)))      (message "Activating %s for Calc Embedded mode...done" (buffer-name)))
359    (calc-embedded-active-state t)    (calc-embedded-active-state t))
 )  
360    
361  (defun calc-plain-buffer-only ()  (defun calc-plain-buffer-only ()
362    (if (memq major-mode '(calc-mode calc-trail-mode calc-edit-mode))    (if (memq major-mode '(calc-mode calc-trail-mode calc-edit-mode))
363        (error "This command should be used in a normal editing buffer"))        (error "This command should be used in a normal editing buffer")))
 )  
364    
365  (defun calc-embedded-active-state (state)  (defun calc-embedded-active-state (state)
366    (or (assq 'calc-embedded-all-active minor-mode-alist)    (or (assq 'calc-embedded-all-active minor-mode-alist)
# Line 382  This is not required to be present for u Line 374  This is not required to be present for u
374    (and (eq state 'more) calc-embedded-all-active (setq state t))    (and (eq state 'more) calc-embedded-all-active (setq state t))
375    (setq calc-embedded-all-active (eq state t)    (setq calc-embedded-all-active (eq state t)
376          calc-embedded-some-active (not (memq state '(nil t))))          calc-embedded-some-active (not (memq state '(nil t))))
377    (set-buffer-modified-p (buffer-modified-p))    (set-buffer-modified-p (buffer-modified-p)))
 )  
378    
379    
380  (defun calc-embedded-original-buffer (switch &optional info)  (defun calc-embedded-original-buffer (switch &optional info)
# Line 392  This is not required to be present for u Line 383  This is not required to be present for u
383        (progn        (progn
384          (error "Calc embedded mode: Original buffer has been killed")))          (error "Calc embedded mode: Original buffer has been killed")))
385    (if switch    (if switch
386        (set-buffer (aref info 0)))        (set-buffer (aref info 0))))
 )  
387    
388  (defun calc-embedded-word ()  (defun calc-embedded-word ()
389    (interactive)    (interactive)
390    (calc-embedded '(4))    (calc-embedded '(4)))
 )  
391    
392  (defun calc-embedded-mark-formula (&optional body-only)  (defun calc-embedded-mark-formula (&optional body-only)
393    "Put point at the beginning of this Calc formula, mark at the end.    "Put point at the beginning of this Calc formula, mark at the end.
# Line 411  With any prefix argument, marks only the Line 400  With any prefix argument, marks only the
400      (save-excursion      (save-excursion
401        (calc-embedded-find-bounds body-only))        (calc-embedded-find-bounds body-only))
402      (push-mark (if body-only bot outer-bot) t)      (push-mark (if body-only bot outer-bot) t)
403      (goto-char (if body-only top outer-top)))      (goto-char (if body-only top outer-top))))
 )  
404    
405  (defun calc-embedded-find-bounds (&optional plain)  (defun calc-embedded-find-bounds (&optional plain)
406    ;; (while (and (bolp) (eq (following-char) ?\n))    ;; (while (and (bolp) (eq (following-char) ?\n))
# Line 453  With any prefix argument, marks only the Line 441  With any prefix argument, marks only the
441      (or (eolp)      (or (eolp)
442          (while (eq (preceding-char) ?\ )          (while (eq (preceding-char) ?\ )
443            (backward-char 1)))            (backward-char 1)))
444      (setq bot (point)))      (setq bot (point))))
 )  
445    
446  (defun calc-embedded-kill-formula ()  (defun calc-embedded-kill-formula ()
447    "Kill the formula surrounding point.    "Kill the formula surrounding point.
# Line 466  The command \\[yank] can retrieve it fro Line 453  The command \\[yank] can retrieve it fro
453         (calc-embedded nil))         (calc-embedded nil))
454    (calc-embedded-mark-formula)    (calc-embedded-mark-formula)
455    (kill-region (point) (mark))    (kill-region (point) (mark))
456    (pop-mark)    (pop-mark))
 )  
457    
458  (defun calc-embedded-copy-formula-as-kill ()  (defun calc-embedded-copy-formula-as-kill ()
459    "Save the formula surrounding point as if killed, but don't kill it."    "Save the formula surrounding point as if killed, but don't kill it."
# Line 475  The command \\[yank] can retrieve it fro Line 461  The command \\[yank] can retrieve it fro
461    (save-excursion    (save-excursion
462      (calc-embedded-mark-formula)      (calc-embedded-mark-formula)
463      (copy-region-as-kill (point) (mark))      (copy-region-as-kill (point) (mark))
464      (pop-mark))      (pop-mark)))
 )  
465    
466  (defun calc-embedded-duplicate ()  (defun calc-embedded-duplicate ()
467    (interactive)    (interactive)
# Line 499  The command \\[yank] can retrieve it fro Line 484  The command \\[yank] can retrieve it fro
484        (calc-embedded (+ new-top (- top outer-top))        (calc-embedded (+ new-top (- top outer-top))
485                       (+ new-top (- bot outer-top))                       (+ new-top (- bot outer-top))
486                       new-top                       new-top
487                       (+ new-top (- outer-bot outer-top)))))                       (+ new-top (- outer-bot outer-top))))))
 )  
488    
489  (defun calc-embedded-next (arg)  (defun calc-embedded-next (arg)
490    (interactive "P")    (interactive "P")
# Line 527  The command \\[yank] can retrieve it fro Line 511  The command \\[yank] can retrieve it fro
511               (setq p (cdr p)))               (setq p (cdr p)))
512             (while (> (setq arg (1- arg)) 0)             (while (> (setq arg (1- arg)) 0)
513               (setq p (if p (cdr p) (cdr active))))               (setq p (if p (cdr p) (cdr active))))
514             (goto-char (aref (car (or p active)) 2)))))             (goto-char (aref (car (or p active)) 2))))))
 )  
515    
516  (defun calc-embedded-previous (arg)  (defun calc-embedded-previous (arg)
517    (interactive "p")    (interactive "p")
518    (calc-embedded-next (- (prefix-numeric-value arg)))    (calc-embedded-next (- (prefix-numeric-value arg))))
 )  
519    
520  (defun calc-embedded-new-formula ()  (defun calc-embedded-new-formula ()
521    (interactive)    (interactive)
# Line 560  The command \\[yank] can retrieve it fro Line 542  The command \\[yank] can retrieve it fro
542      (setq outer-bot (point))      (setq outer-bot (point))
543      (goto-char top)      (goto-char top)
544      (let ((calc-embedded-quiet 'x))      (let ((calc-embedded-quiet 'x))
545        (calc-embedded top bot outer-top outer-bot)))        (calc-embedded top bot outer-top outer-bot))))
 )  
546    
547  (defun calc-embedded-forget ()  (defun calc-embedded-forget ()
548    (interactive)    (interactive)
549    (setq calc-embedded-active (delq (assq (current-buffer) calc-embedded-active)    (setq calc-embedded-active (delq (assq (current-buffer) calc-embedded-active)
550                                     calc-embedded-active))                                     calc-embedded-active))
551    (calc-embedded-active-state nil)    (calc-embedded-active-state nil))
 )  
552    
553    
554  (defun calc-embedded-set-modes (gmodes modes local-modes &optional temp)  (defun calc-embedded-set-modes (gmodes modes local-modes &optional temp)
# Line 630  The command \\[yank] can retrieve it fro Line 610  The command \\[yank] can retrieve it fro
610                                                  (car calc-float-format))                                                  (car calc-float-format))
611                                                0))                                                0))
612             (calc-refresh)))             (calc-refresh)))
613      changed)      changed))
 )  
614    
615  (defun calc-embedded-language ()  (defun calc-embedded-language ()
616    (if calc-language-option    (if calc-language-option
617        (list calc-language calc-language-option)        (list calc-language calc-language-option)
618      calc-language)      calc-language))
 )  
619    
620  (defun calc-embedded-set-language (lang)  (defun calc-embedded-set-language (lang)
621    (let ((option nil))    (let ((option nil))
# Line 646  The command \\[yank] can retrieve it fro Line 624  The command \\[yank] can retrieve it fro
624                lang (car lang)))                lang (car lang)))
625      (or (and (eq lang calc-language)      (or (and (eq lang calc-language)
626               (equal option calc-language-option))               (equal option calc-language-option))
627          (calc-set-language lang option t)))          (calc-set-language lang option t))))
 )  
628    
629  (defun calc-embedded-justify ()  (defun calc-embedded-justify ()
630    (if calc-display-origin    (if calc-display-origin
631        (list calc-display-just calc-display-origin)        (list calc-display-just calc-display-origin)
632      calc-display-just)      calc-display-just))
 )  
633    
634  (defun calc-embedded-set-justify (just)  (defun calc-embedded-set-justify (just)
635    (if (consp just)    (if (consp just)
636        (setq calc-display-origin (nth 1 just)        (setq calc-display-origin (nth 1 just)
637              calc-display-just (car just))              calc-display-just (car just))
638      (setq calc-display-just just      (setq calc-display-just just
639            calc-display-origin nil))            calc-display-origin nil)))
 )  
640    
641    
642  (defun calc-find-globals ()  (defun calc-find-globals ()
# Line 686  The command \\[yank] can retrieve it fro Line 661  The command \\[yank] can retrieve it fro
661                                                (match-end 2)))))                                                (match-end 2)))))
662                                   modes)))))                                   modes)))))
663      (setq calc-embedded-globals (cons t modes))      (setq calc-embedded-globals (cons t modes))
664      (goto-char save-pt))      (goto-char save-pt)))
 )  
665    
666  (defun calc-embedded-find-modes ()  (defun calc-embedded-find-modes ()
667    (let ((case-fold-search nil)    (let ((case-fold-search nil)
# Line 736  The command \\[yank] can retrieve it fro Line 710  The command \\[yank] can retrieve it fro
710                 (setq no-defaults nil)))                 (setq no-defaults nil)))
711        (backward-char 6))        (backward-char 6))
712      (goto-char save-pt)      (goto-char save-pt)
713      (list modes emodes pmodes))      (list modes emodes pmodes)))
 )  
714    
715    
716  (defun calc-embedded-make-info (point cbuf fresh &optional  (defun calc-embedded-make-info (point cbuf fresh &optional
# Line 851  The command \\[yank] can retrieve it fro Line 824  The command \\[yank] can retrieve it fro
824          (progn          (progn
825            (setcdr found (cons info (cdr found)))            (setcdr found (cons info (cdr found)))
826            (calc-embedded-active-state 'more)))            (calc-embedded-active-state 'more)))
827      info)      info))
 )  
828    
829  (defun calc-embedded-find-vars (x)  (defun calc-embedded-find-vars (x)
830    (cond ((Math-primp x)    (cond ((Math-primp x)
# Line 870  The command \\[yank] can retrieve it fro Line 842  The command \\[yank] can retrieve it fro
842                (not (assoc x vars-used))                (not (assoc x vars-used))
843                (setq vars-used (cons (list x) vars-used)))                (setq vars-used (cons (list x) vars-used)))
844           (while (setq x (cdr x))           (while (setq x (cdr x))
845             (calc-embedded-find-vars (car x)))))             (calc-embedded-find-vars (car x))))))
 )  
846    
847    
848  (defun calc-embedded-evaluate-expr (x)  (defun calc-embedded-evaluate-expr (x)
# Line 891  The command \\[yank] can retrieve it fro Line 862  The command \\[yank] can retrieve it fro
862                (calc-embedded-eval-get-var (car (car vars-used)) active)                (calc-embedded-eval-get-var (car (car vars-used)) active)
863                (setq vars-used (cdr vars-used))))                (setq vars-used (cdr vars-used))))
864            (calc-embedded-subst x))            (calc-embedded-subst x))
865        (calc-normalize (math-evaluate-expr-rec x))))        (calc-normalize (math-evaluate-expr-rec x)))))
 )  
866    
867  (defun calc-embedded-subst (x)  (defun calc-embedded-subst (x)
868    (if (and (eq (car-safe x) 'calcFunc-evalto) (cdr x))    (if (and (eq (car-safe x) 'calcFunc-evalto) (cdr x))
# Line 904  The command \\[yank] can retrieve it fro Line 874  The command \\[yank] can retrieve it fro
874          (list 'calcFunc-assign          (list 'calcFunc-assign
875                (nth 1 x)                (nth 1 x)
876                (calc-embedded-subst (nth 2 x)))                (calc-embedded-subst (nth 2 x)))
877        (calc-normalize (math-evaluate-expr-rec (math-multi-subst-rec x)))))        (calc-normalize (math-evaluate-expr-rec (math-multi-subst-rec x))))))
 )  
878    
879  (defun calc-embedded-eval-get-var (var base)  (defun calc-embedded-eval-get-var (var base)
880    (let ((entry base)    (let ((entry base)
# Line 934  The command \\[yank] can retrieve it fro Line 903  The command \\[yank] can retrieve it fro
903                      (setq val (nth 2 val)))                      (setq val (nth 2 val)))
904                  (setq args (cons (cons var val) args)))                  (setq args (cons (cons var val) args)))
905              (calc-embedded-activate)              (calc-embedded-activate)
906              (calc-embedded-eval-get-var var base)))))              (calc-embedded-eval-get-var var base))))))
 )  
907    
908    
909  (defun calc-embedded-update (info which need-eval need-display  (defun calc-embedded-update (info which need-eval need-display
# Line 1027  The command \\[yank] can retrieve it fro Line 995  The command \\[yank] can retrieve it fro
995                     (calc-embedded-set-justify (cdr (car prev-modes)))))                     (calc-embedded-set-justify (cdr (car prev-modes)))))
996                (t                (t
997                 (set (car (car prev-modes)) (cdr (car prev-modes)))))                 (set (car (car prev-modes)) (cdr (car prev-modes)))))
998          (setq prev-modes (cdr prev-modes)))))          (setq prev-modes (cdr prev-modes))))))
 )  
999    
1000    
1001    
# Line 1063  The command \\[yank] can retrieve it fro Line 1030  The command \\[yank] can retrieve it fro
1030              (forward-line vert))              (forward-line vert))
1031          (forward-char (min horiz          (forward-char (min horiz
1032                             (- (point-max) (point)))))                             (- (point-max) (point)))))
1033      (calc-select-buffer))      (calc-select-buffer)))
 )  
1034  (setq calc-embedded-no-reselect nil)  (setq calc-embedded-no-reselect nil)
1035    
1036  (defun calc-embedded-finish-command ()  (defun calc-embedded-finish-command ()
# Line 1095  The command \\[yank] can retrieve it fro Line 1061  The command \\[yank] can retrieve it fro
1061            (if (> vert 0)            (if (> vert 0)
1062                (forward-line vert))                (forward-line vert))
1063            (forward-char (max horiz 0))            (forward-char (max horiz 0))
1064            (set-buffer buf))))            (set-buffer buf)))))
 )  
1065    
1066  (defun calc-embedded-stack-change ()  (defun calc-embedded-stack-change ()
1067    (or calc-executing-macro    (or calc-executing-macro
# Line 1128  The command \\[yank] can retrieve it fro Line 1093  The command \\[yank] can retrieve it fro
1093                            pos (1+ pos))))))                            pos (1+ pos))))))
1094            (calc-embedded-original-buffer t)            (calc-embedded-original-buffer t)
1095            (aset info 8 (car entry))            (aset info 8 (car entry))
1096            (calc-embedded-update info 13 nil t str entry old-val))))            (calc-embedded-update info 13 nil t str entry old-val)))))
 )  
1097    
1098  (defun calc-embedded-mode-line-change ()  (defun calc-embedded-mode-line-change ()
1099    (let ((str mode-line-buffer-identification))    (let ((str mode-line-buffer-identification))
1100      (save-excursion      (save-excursion
1101        (calc-embedded-original-buffer t)        (calc-embedded-original-buffer t)
1102        (setq mode-line-buffer-identification str)        (setq mode-line-buffer-identification str)
1103        (set-buffer-modified-p (buffer-modified-p))))        (set-buffer-modified-p (buffer-modified-p)))))
 )  
1104    
1105  (defun calc-embedded-modes-change (vars)  (defun calc-embedded-modes-change (vars)
1106    (if (eq (car vars) 'calc-language) (setq vars '(the-language)))    (if (eq (car vars) 'calc-language) (setq vars '(the-language)))
# Line 1203  The command \\[yank] can retrieve it fro Line 1166  The command \\[yank] can retrieve it fro
1166                         (prin1-to-string (car values)) "]"                         (prin1-to-string (car values)) "]"
1167                         calc-embedded-close-mode))))                         calc-embedded-close-mode))))
1168                (setq vars (cdr vars)                (setq vars (cdr vars)
1169                      values (cdr values)))))))                      values (cdr values))))))))
 )  
1170    
1171  (defun calc-embedded-var-change (var &optional buf)  (defun calc-embedded-var-change (var &optional buf)
1172    (if (symbolp var)    (if (symbolp var)
# Line 1247  The command \\[yank] can retrieve it fro Line 1209  The command \\[yank] can retrieve it fro
1209                       "(Tried to recompute but formula was changed or missing.)"))))                       "(Tried to recompute but formula was changed or missing.)"))))
1210              (setq p (cdr p))))              (setq p (cdr p))))
1211          (setq bp (if buf nil (cdr bp))))          (setq bp (if buf nil (cdr bp))))
1212        (or first calc-embedded-quiet (message ""))))        (or first calc-embedded-quiet (message "")))))
 )  
   
1213    
1214    ;;; calc-embed.el ends here
1215    
1216    
1217    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26