Mercurial > emacs
comparison lisp/calc/calc-embed.el @ 41047:73f364fd8aaa
Style cleanup; don't put closing parens on their
own line, add "foo.el ends here" to each file, and update
copyright date.
author | Colin Walters <walters@gnu.org> |
---|---|
date | Wed, 14 Nov 2001 09:09:09 +0000 |
parents | 5a413baa253c |
children | fcd507927105 |
comparison
equal
deleted
inserted
replaced
41046:14b73d89514a | 41047:73f364fd8aaa |
---|---|
33 (interactive "P") | 33 (interactive "P") |
34 (calc-wrapper | 34 (calc-wrapper |
35 (calc-set-command-flag 'renum-stack) | 35 (calc-set-command-flag 'renum-stack) |
36 (message (if (calc-change-mode 'calc-show-plain n nil t) | 36 (message (if (calc-change-mode 'calc-show-plain n nil t) |
37 "Including \"plain\" formulas in Calc Embedded mode." | 37 "Including \"plain\" formulas in Calc Embedded mode." |
38 "Omitting \"plain\" formulas in Calc Embedded mode."))) | 38 "Omitting \"plain\" formulas in Calc Embedded mode.")))) |
39 ) | |
40 | 39 |
41 | 40 |
42 | 41 |
43 | 42 |
44 ;;; Things to do for Embedded Mode: | 43 ;;; Things to do for Embedded Mode: |
249 (or (eq calc-embedded-quiet t) | 248 (or (eq calc-embedded-quiet t) |
250 (message "Embedded Calc mode enabled. %s to return to normal." | 249 (message "Embedded Calc mode enabled. %s to return to normal." |
251 (if calc-embedded-quiet | 250 (if calc-embedded-quiet |
252 "Type `M-# x'" | 251 "Type `M-# x'" |
253 "Give this command again"))))) | 252 "Give this command again"))))) |
254 (scroll-down 0) ; fix a bug which occurs when truncate-lines is changed. | 253 (scroll-down 0)) ; fix a bug which occurs when truncate-lines is changed. |
255 ) | |
256 (setq calc-embedded-quiet nil) | 254 (setq calc-embedded-quiet nil) |
257 | 255 |
258 | 256 |
259 (defun calc-embedded-select (arg) | 257 (defun calc-embedded-select (arg) |
260 (interactive "P") | 258 (interactive "P") |
265 (and calc-embedded-info | 263 (and calc-embedded-info |
266 (or (eq (car-safe (aref calc-embedded-info 8)) 'calcFunc-assign) | 264 (or (eq (car-safe (aref calc-embedded-info 8)) 'calcFunc-assign) |
267 (and (eq (car-safe (aref calc-embedded-info 8)) 'calcFunc-evalto) | 265 (and (eq (car-safe (aref calc-embedded-info 8)) 'calcFunc-evalto) |
268 (eq (car-safe (nth 1 (aref calc-embedded-info 8))) | 266 (eq (car-safe (nth 1 (aref calc-embedded-info 8))) |
269 'calcFunc-assign))) | 267 'calcFunc-assign))) |
270 (calc-select-part 2)) | 268 (calc-select-part 2))) |
271 ) | |
272 | 269 |
273 | 270 |
274 (defun calc-embedded-update-formula (arg) | 271 (defun calc-embedded-update-formula (arg) |
275 (interactive "P") | 272 (interactive "P") |
276 (if arg | 273 (if arg |
292 (pt (- opt (aref info 4)))) | 289 (pt (- opt (aref info 4)))) |
293 (or (eq (car-safe (aref info 8)) 'error) | 290 (or (eq (car-safe (aref info 8)) 'error) |
294 (progn | 291 (progn |
295 (save-excursion | 292 (save-excursion |
296 (calc-embedded-update info 14 'eval t)) | 293 (calc-embedded-update info 14 'eval t)) |
297 (goto-char (+ (aref info 4) pt))))))) | 294 (goto-char (+ (aref info 4) pt)))))))) |
298 ) | |
299 | 295 |
300 | 296 |
301 (defun calc-embedded-edit (arg) | 297 (defun calc-embedded-edit (arg) |
302 (interactive "P") | 298 (interactive "P") |
303 (let ((info (calc-embedded-make-info (point) nil t arg)) | 299 (let ((info (calc-embedded-make-info (point) nil t arg)) |
309 (calc-wrapper | 305 (calc-wrapper |
310 (setq str (math-showing-full-precision | 306 (setq str (math-showing-full-precision |
311 (math-format-nice-expr (aref info 8) (frame-width)))) | 307 (math-format-nice-expr (aref info 8) (frame-width)))) |
312 (calc-edit-mode (list 'calc-embedded-finish-edit info)) | 308 (calc-edit-mode (list 'calc-embedded-finish-edit info)) |
313 (insert str "\n"))) | 309 (insert str "\n"))) |
314 (calc-show-edit-buffer) | 310 (calc-show-edit-buffer)) |
315 ) | |
316 | 311 |
317 (defun calc-embedded-finish-edit (info) | 312 (defun calc-embedded-finish-edit (info) |
318 (let ((buf (current-buffer)) | 313 (let ((buf (current-buffer)) |
319 (str (buffer-substring (point) (point-max))) | 314 (str (buffer-substring (point) (point-max))) |
320 (start (point)) | 315 (start (point)) |
330 (switch-to-buffer buf) | 325 (switch-to-buffer buf) |
331 (goto-char (+ start (nth 1 val))) | 326 (goto-char (+ start (nth 1 val))) |
332 (error (nth 2 val)))) | 327 (error (nth 2 val)))) |
333 (calc-embedded-original-buffer t info) | 328 (calc-embedded-original-buffer t info) |
334 (aset info 8 val) | 329 (aset info 8 val) |
335 (calc-embedded-update info 14 t t))) | 330 (calc-embedded-update info 14 t t)))) |
336 ) | |
337 | 331 |
338 (defun calc-do-embedded-activate (arg cbuf) | 332 (defun calc-do-embedded-activate (arg cbuf) |
339 (calc-plain-buffer-only) | 333 (calc-plain-buffer-only) |
340 (if arg | 334 (if arg |
341 (calc-embedded-forget)) | 335 (calc-embedded-forget)) |
360 (goto-char (match-end 1))) | 354 (goto-char (match-end 1))) |
361 (setq info (calc-embedded-make-info (point) cbuf nil)) | 355 (setq info (calc-embedded-make-info (point) cbuf nil)) |
362 (or (eq (car-safe (aref info 8)) 'error) | 356 (or (eq (car-safe (aref info 8)) 'error) |
363 (goto-char (aref info 5)))))) | 357 (goto-char (aref info 5)))))) |
364 (message "Activating %s for Calc Embedded mode...done" (buffer-name))) | 358 (message "Activating %s for Calc Embedded mode...done" (buffer-name))) |
365 (calc-embedded-active-state t) | 359 (calc-embedded-active-state t)) |
366 ) | |
367 | 360 |
368 (defun calc-plain-buffer-only () | 361 (defun calc-plain-buffer-only () |
369 (if (memq major-mode '(calc-mode calc-trail-mode calc-edit-mode)) | 362 (if (memq major-mode '(calc-mode calc-trail-mode calc-edit-mode)) |
370 (error "This command should be used in a normal editing buffer")) | 363 (error "This command should be used in a normal editing buffer"))) |
371 ) | |
372 | 364 |
373 (defun calc-embedded-active-state (state) | 365 (defun calc-embedded-active-state (state) |
374 (or (assq 'calc-embedded-all-active minor-mode-alist) | 366 (or (assq 'calc-embedded-all-active minor-mode-alist) |
375 (setq minor-mode-alist | 367 (setq minor-mode-alist |
376 (cons '(calc-embedded-all-active " Active") | 368 (cons '(calc-embedded-all-active " Active") |
380 (or (cdr active) | 372 (or (cdr active) |
381 (setq state nil))) | 373 (setq state nil))) |
382 (and (eq state 'more) calc-embedded-all-active (setq state t)) | 374 (and (eq state 'more) calc-embedded-all-active (setq state t)) |
383 (setq calc-embedded-all-active (eq state t) | 375 (setq calc-embedded-all-active (eq state t) |
384 calc-embedded-some-active (not (memq state '(nil t)))) | 376 calc-embedded-some-active (not (memq state '(nil t)))) |
385 (set-buffer-modified-p (buffer-modified-p)) | 377 (set-buffer-modified-p (buffer-modified-p))) |
386 ) | |
387 | 378 |
388 | 379 |
389 (defun calc-embedded-original-buffer (switch &optional info) | 380 (defun calc-embedded-original-buffer (switch &optional info) |
390 (or info (setq info calc-embedded-info)) | 381 (or info (setq info calc-embedded-info)) |
391 (or (buffer-name (aref info 0)) | 382 (or (buffer-name (aref info 0)) |
392 (progn | 383 (progn |
393 (error "Calc embedded mode: Original buffer has been killed"))) | 384 (error "Calc embedded mode: Original buffer has been killed"))) |
394 (if switch | 385 (if switch |
395 (set-buffer (aref info 0))) | 386 (set-buffer (aref info 0)))) |
396 ) | |
397 | 387 |
398 (defun calc-embedded-word () | 388 (defun calc-embedded-word () |
399 (interactive) | 389 (interactive) |
400 (calc-embedded '(4)) | 390 (calc-embedded '(4))) |
401 ) | |
402 | 391 |
403 (defun calc-embedded-mark-formula (&optional body-only) | 392 (defun calc-embedded-mark-formula (&optional body-only) |
404 "Put point at the beginning of this Calc formula, mark at the end. | 393 "Put point at the beginning of this Calc formula, mark at the end. |
405 This normally marks the whole formula, including surrounding delimiters. | 394 This normally marks the whole formula, including surrounding delimiters. |
406 With any prefix argument, marks only the formula itself." | 395 With any prefix argument, marks only the formula itself." |
409 (error "This command should be used in a normal editing buffer")) | 398 (error "This command should be used in a normal editing buffer")) |
410 (let (top bot outer-top outer-bot) | 399 (let (top bot outer-top outer-bot) |
411 (save-excursion | 400 (save-excursion |
412 (calc-embedded-find-bounds body-only)) | 401 (calc-embedded-find-bounds body-only)) |
413 (push-mark (if body-only bot outer-bot) t) | 402 (push-mark (if body-only bot outer-bot) t) |
414 (goto-char (if body-only top outer-top))) | 403 (goto-char (if body-only top outer-top)))) |
415 ) | |
416 | 404 |
417 (defun calc-embedded-find-bounds (&optional plain) | 405 (defun calc-embedded-find-bounds (&optional plain) |
418 ;; (while (and (bolp) (eq (following-char) ?\n)) | 406 ;; (while (and (bolp) (eq (following-char) ?\n)) |
419 ;; (forward-char 1)) | 407 ;; (forward-char 1)) |
420 (and (eolp) (bolp) (not (eq (char-after (- (point) 2)) ?\n)) | 408 (and (eolp) (bolp) (not (eq (char-after (- (point) 2)) ?\n)) |
451 (if (eq (preceding-char) ?\n) | 439 (if (eq (preceding-char) ?\n) |
452 (backward-char 1)) | 440 (backward-char 1)) |
453 (or (eolp) | 441 (or (eolp) |
454 (while (eq (preceding-char) ?\ ) | 442 (while (eq (preceding-char) ?\ ) |
455 (backward-char 1))) | 443 (backward-char 1))) |
456 (setq bot (point))) | 444 (setq bot (point)))) |
457 ) | |
458 | 445 |
459 (defun calc-embedded-kill-formula () | 446 (defun calc-embedded-kill-formula () |
460 "Kill the formula surrounding point. | 447 "Kill the formula surrounding point. |
461 If Calc Embedded mode was active, this deactivates it. | 448 If Calc Embedded mode was active, this deactivates it. |
462 The formula (including its surrounding delimiters) is saved in the kill ring. | 449 The formula (including its surrounding delimiters) is saved in the kill ring. |
464 (interactive) | 451 (interactive) |
465 (and calc-embedded-info | 452 (and calc-embedded-info |
466 (calc-embedded nil)) | 453 (calc-embedded nil)) |
467 (calc-embedded-mark-formula) | 454 (calc-embedded-mark-formula) |
468 (kill-region (point) (mark)) | 455 (kill-region (point) (mark)) |
469 (pop-mark) | 456 (pop-mark)) |
470 ) | |
471 | 457 |
472 (defun calc-embedded-copy-formula-as-kill () | 458 (defun calc-embedded-copy-formula-as-kill () |
473 "Save the formula surrounding point as if killed, but don't kill it." | 459 "Save the formula surrounding point as if killed, but don't kill it." |
474 (interactive) | 460 (interactive) |
475 (save-excursion | 461 (save-excursion |
476 (calc-embedded-mark-formula) | 462 (calc-embedded-mark-formula) |
477 (copy-region-as-kill (point) (mark)) | 463 (copy-region-as-kill (point) (mark)) |
478 (pop-mark)) | 464 (pop-mark))) |
479 ) | |
480 | 465 |
481 (defun calc-embedded-duplicate () | 466 (defun calc-embedded-duplicate () |
482 (interactive) | 467 (interactive) |
483 (let ((already calc-embedded-info) | 468 (let ((already calc-embedded-info) |
484 top bot outer-top outer-bot new-top) | 469 top bot outer-top outer-bot new-top) |
497 (goto-char (+ new-top (- top outer-top))) | 482 (goto-char (+ new-top (- top outer-top))) |
498 (let ((calc-embedded-quiet (if already t 'x))) | 483 (let ((calc-embedded-quiet (if already t 'x))) |
499 (calc-embedded (+ new-top (- top outer-top)) | 484 (calc-embedded (+ new-top (- top outer-top)) |
500 (+ new-top (- bot outer-top)) | 485 (+ new-top (- bot outer-top)) |
501 new-top | 486 new-top |
502 (+ new-top (- outer-bot outer-top))))) | 487 (+ new-top (- outer-bot outer-top)))))) |
503 ) | |
504 | 488 |
505 (defun calc-embedded-next (arg) | 489 (defun calc-embedded-next (arg) |
506 (interactive "P") | 490 (interactive "P") |
507 (setq arg (prefix-numeric-value arg)) | 491 (setq arg (prefix-numeric-value arg)) |
508 (let* ((active (cdr (assq (current-buffer) calc-embedded-active))) | 492 (let* ((active (cdr (assq (current-buffer) calc-embedded-active))) |
525 (setq arg (1+ (% (1- arg) num))) | 509 (setq arg (1+ (% (1- arg) num))) |
526 (while (and p (>= (point) (aref (car p) 2))) | 510 (while (and p (>= (point) (aref (car p) 2))) |
527 (setq p (cdr p))) | 511 (setq p (cdr p))) |
528 (while (> (setq arg (1- arg)) 0) | 512 (while (> (setq arg (1- arg)) 0) |
529 (setq p (if p (cdr p) (cdr active)))) | 513 (setq p (if p (cdr p) (cdr active)))) |
530 (goto-char (aref (car (or p active)) 2))))) | 514 (goto-char (aref (car (or p active)) 2)))))) |
531 ) | |
532 | 515 |
533 (defun calc-embedded-previous (arg) | 516 (defun calc-embedded-previous (arg) |
534 (interactive "p") | 517 (interactive "p") |
535 (calc-embedded-next (- (prefix-numeric-value arg))) | 518 (calc-embedded-next (- (prefix-numeric-value arg)))) |
536 ) | |
537 | 519 |
538 (defun calc-embedded-new-formula () | 520 (defun calc-embedded-new-formula () |
539 (interactive) | 521 (interactive) |
540 (and (eq major-mode 'calc-mode) | 522 (and (eq major-mode 'calc-mode) |
541 (error "This command should be used in a normal editing buffer")) | 523 (error "This command should be used in a normal editing buffer")) |
558 (string-match "\n\\'" calc-embedded-close-new-formula)) | 540 (string-match "\n\\'" calc-embedded-close-new-formula)) |
559 (delete-char 1)) | 541 (delete-char 1)) |
560 (setq outer-bot (point)) | 542 (setq outer-bot (point)) |
561 (goto-char top) | 543 (goto-char top) |
562 (let ((calc-embedded-quiet 'x)) | 544 (let ((calc-embedded-quiet 'x)) |
563 (calc-embedded top bot outer-top outer-bot))) | 545 (calc-embedded top bot outer-top outer-bot)))) |
564 ) | |
565 | 546 |
566 (defun calc-embedded-forget () | 547 (defun calc-embedded-forget () |
567 (interactive) | 548 (interactive) |
568 (setq calc-embedded-active (delq (assq (current-buffer) calc-embedded-active) | 549 (setq calc-embedded-active (delq (assq (current-buffer) calc-embedded-active) |
569 calc-embedded-active)) | 550 calc-embedded-active)) |
570 (calc-embedded-active-state nil) | 551 (calc-embedded-active-state nil)) |
571 ) | |
572 | 552 |
573 | 553 |
574 (defun calc-embedded-set-modes (gmodes modes local-modes &optional temp) | 554 (defun calc-embedded-set-modes (gmodes modes local-modes &optional temp) |
575 (let ((the-language (calc-embedded-language)) | 555 (let ((the-language (calc-embedded-language)) |
576 (the-display-just (calc-embedded-justify)) | 556 (the-display-just (calc-embedded-justify)) |
628 'fix) | 608 'fix) |
629 'float | 609 'float |
630 (car calc-float-format)) | 610 (car calc-float-format)) |
631 0)) | 611 0)) |
632 (calc-refresh))) | 612 (calc-refresh))) |
633 changed) | 613 changed)) |
634 ) | |
635 | 614 |
636 (defun calc-embedded-language () | 615 (defun calc-embedded-language () |
637 (if calc-language-option | 616 (if calc-language-option |
638 (list calc-language calc-language-option) | 617 (list calc-language calc-language-option) |
639 calc-language) | 618 calc-language)) |
640 ) | |
641 | 619 |
642 (defun calc-embedded-set-language (lang) | 620 (defun calc-embedded-set-language (lang) |
643 (let ((option nil)) | 621 (let ((option nil)) |
644 (if (consp lang) | 622 (if (consp lang) |
645 (setq option (nth 1 lang) | 623 (setq option (nth 1 lang) |
646 lang (car lang))) | 624 lang (car lang))) |
647 (or (and (eq lang calc-language) | 625 (or (and (eq lang calc-language) |
648 (equal option calc-language-option)) | 626 (equal option calc-language-option)) |
649 (calc-set-language lang option t))) | 627 (calc-set-language lang option t)))) |
650 ) | |
651 | 628 |
652 (defun calc-embedded-justify () | 629 (defun calc-embedded-justify () |
653 (if calc-display-origin | 630 (if calc-display-origin |
654 (list calc-display-just calc-display-origin) | 631 (list calc-display-just calc-display-origin) |
655 calc-display-just) | 632 calc-display-just)) |
656 ) | |
657 | 633 |
658 (defun calc-embedded-set-justify (just) | 634 (defun calc-embedded-set-justify (just) |
659 (if (consp just) | 635 (if (consp just) |
660 (setq calc-display-origin (nth 1 just) | 636 (setq calc-display-origin (nth 1 just) |
661 calc-display-just (car just)) | 637 calc-display-just (car just)) |
662 (setq calc-display-just just | 638 (setq calc-display-just just |
663 calc-display-origin nil)) | 639 calc-display-origin nil))) |
664 ) | |
665 | 640 |
666 | 641 |
667 (defun calc-find-globals () | 642 (defun calc-find-globals () |
668 (interactive) | 643 (interactive) |
669 (and (eq major-mode 'calc-mode) | 644 (and (eq major-mode 'calc-mode) |
684 (buffer-substring | 659 (buffer-substring |
685 (match-beginning 2) | 660 (match-beginning 2) |
686 (match-end 2))))) | 661 (match-end 2))))) |
687 modes))))) | 662 modes))))) |
688 (setq calc-embedded-globals (cons t modes)) | 663 (setq calc-embedded-globals (cons t modes)) |
689 (goto-char save-pt)) | 664 (goto-char save-pt))) |
690 ) | |
691 | 665 |
692 (defun calc-embedded-find-modes () | 666 (defun calc-embedded-find-modes () |
693 (let ((case-fold-search nil) | 667 (let ((case-fold-search nil) |
694 (save-pt (point)) | 668 (save-pt (point)) |
695 (no-defaults t) | 669 (no-defaults t) |
734 emodes)))) | 708 emodes)))) |
735 (and (looking-at "defaults]") | 709 (and (looking-at "defaults]") |
736 (setq no-defaults nil))) | 710 (setq no-defaults nil))) |
737 (backward-char 6)) | 711 (backward-char 6)) |
738 (goto-char save-pt) | 712 (goto-char save-pt) |
739 (list modes emodes pmodes)) | 713 (list modes emodes pmodes))) |
740 ) | |
741 | 714 |
742 | 715 |
743 (defun calc-embedded-make-info (point cbuf fresh &optional | 716 (defun calc-embedded-make-info (point cbuf fresh &optional |
744 top bot outer-top outer-bot) | 717 top bot outer-top outer-bot) |
745 (let* ((bufentry (assq (current-buffer) calc-embedded-active)) | 718 (let* ((bufentry (assq (current-buffer) calc-embedded-active)) |
849 (aset info 11 nil)))) | 822 (aset info 11 nil)))) |
850 (if new-info | 823 (if new-info |
851 (progn | 824 (progn |
852 (setcdr found (cons info (cdr found))) | 825 (setcdr found (cons info (cdr found))) |
853 (calc-embedded-active-state 'more))) | 826 (calc-embedded-active-state 'more))) |
854 info) | 827 info)) |
855 ) | |
856 | 828 |
857 (defun calc-embedded-find-vars (x) | 829 (defun calc-embedded-find-vars (x) |
858 (cond ((Math-primp x) | 830 (cond ((Math-primp x) |
859 (and (eq (car-safe x) 'var) | 831 (and (eq (car-safe x) 'var) |
860 (not (assoc x vars-used)) | 832 (not (assoc x vars-used)) |
868 (eq (car-safe (nth 1 x)) 'var) | 840 (eq (car-safe (nth 1 x)) 'var) |
869 (Math-primp (nth 2 x)) | 841 (Math-primp (nth 2 x)) |
870 (not (assoc x vars-used)) | 842 (not (assoc x vars-used)) |
871 (setq vars-used (cons (list x) vars-used))) | 843 (setq vars-used (cons (list x) vars-used))) |
872 (while (setq x (cdr x)) | 844 (while (setq x (cdr x)) |
873 (calc-embedded-find-vars (car x))))) | 845 (calc-embedded-find-vars (car x)))))) |
874 ) | |
875 | 846 |
876 | 847 |
877 (defun calc-embedded-evaluate-expr (x) | 848 (defun calc-embedded-evaluate-expr (x) |
878 (let ((vars-used (aref calc-embedded-info 10))) | 849 (let ((vars-used (aref calc-embedded-info 10))) |
879 (or vars-used (calc-embedded-find-vars x)) | 850 (or vars-used (calc-embedded-find-vars x)) |
889 calc-embedded-active)))) | 860 calc-embedded-active)))) |
890 (while vars-used | 861 (while vars-used |
891 (calc-embedded-eval-get-var (car (car vars-used)) active) | 862 (calc-embedded-eval-get-var (car (car vars-used)) active) |
892 (setq vars-used (cdr vars-used)))) | 863 (setq vars-used (cdr vars-used)))) |
893 (calc-embedded-subst x)) | 864 (calc-embedded-subst x)) |
894 (calc-normalize (math-evaluate-expr-rec x)))) | 865 (calc-normalize (math-evaluate-expr-rec x))))) |
895 ) | |
896 | 866 |
897 (defun calc-embedded-subst (x) | 867 (defun calc-embedded-subst (x) |
898 (if (and (eq (car-safe x) 'calcFunc-evalto) (cdr x)) | 868 (if (and (eq (car-safe x) 'calcFunc-evalto) (cdr x)) |
899 (let ((rhs (calc-embedded-subst (nth 1 x)))) | 869 (let ((rhs (calc-embedded-subst (nth 1 x)))) |
900 (list 'calcFunc-evalto | 870 (list 'calcFunc-evalto |
902 (if (eq (car-safe rhs) 'calcFunc-assign) (nth 2 rhs) rhs))) | 872 (if (eq (car-safe rhs) 'calcFunc-assign) (nth 2 rhs) rhs))) |
903 (if (and (eq (car-safe x) 'calcFunc-assign) (= (length x) 3)) | 873 (if (and (eq (car-safe x) 'calcFunc-assign) (= (length x) 3)) |
904 (list 'calcFunc-assign | 874 (list 'calcFunc-assign |
905 (nth 1 x) | 875 (nth 1 x) |
906 (calc-embedded-subst (nth 2 x))) | 876 (calc-embedded-subst (nth 2 x))) |
907 (calc-normalize (math-evaluate-expr-rec (math-multi-subst-rec x))))) | 877 (calc-normalize (math-evaluate-expr-rec (math-multi-subst-rec x)))))) |
908 ) | |
909 | 878 |
910 (defun calc-embedded-eval-get-var (var base) | 879 (defun calc-embedded-eval-get-var (var base) |
911 (let ((entry base) | 880 (let ((entry base) |
912 (point (aref calc-embedded-info 2)) | 881 (point (aref calc-embedded-info 2)) |
913 (last nil) | 882 (last nil) |
932 (setq val (nth 2 val))) | 901 (setq val (nth 2 val))) |
933 (if (eq (car-safe val) 'calcFunc-assign) | 902 (if (eq (car-safe val) 'calcFunc-assign) |
934 (setq val (nth 2 val))) | 903 (setq val (nth 2 val))) |
935 (setq args (cons (cons var val) args))) | 904 (setq args (cons (cons var val) args))) |
936 (calc-embedded-activate) | 905 (calc-embedded-activate) |
937 (calc-embedded-eval-get-var var base))))) | 906 (calc-embedded-eval-get-var var base)))))) |
938 ) | |
939 | 907 |
940 | 908 |
941 (defun calc-embedded-update (info which need-eval need-display | 909 (defun calc-embedded-update (info which need-eval need-display |
942 &optional str entry old-val) | 910 &optional str entry old-val) |
943 (let* ((prev-modes nil) | 911 (let* ((prev-modes nil) |
1025 ((eq (car (car prev-modes)) 'the-display-just) | 993 ((eq (car (car prev-modes)) 'the-display-just) |
1026 (if need-display | 994 (if need-display |
1027 (calc-embedded-set-justify (cdr (car prev-modes))))) | 995 (calc-embedded-set-justify (cdr (car prev-modes))))) |
1028 (t | 996 (t |
1029 (set (car (car prev-modes)) (cdr (car prev-modes))))) | 997 (set (car (car prev-modes)) (cdr (car prev-modes))))) |
1030 (setq prev-modes (cdr prev-modes))))) | 998 (setq prev-modes (cdr prev-modes)))))) |
1031 ) | |
1032 | 999 |
1033 | 1000 |
1034 | 1001 |
1035 | 1002 |
1036 ;;; These are hooks called by the main part of Calc. | 1003 ;;; These are hooks called by the main part of Calc. |
1061 (setq horiz (+ horiz 4))) | 1028 (setq horiz (+ horiz 4))) |
1062 (if (> vert 0) | 1029 (if (> vert 0) |
1063 (forward-line vert)) | 1030 (forward-line vert)) |
1064 (forward-char (min horiz | 1031 (forward-char (min horiz |
1065 (- (point-max) (point))))) | 1032 (- (point-max) (point))))) |
1066 (calc-select-buffer)) | 1033 (calc-select-buffer))) |
1067 ) | |
1068 (setq calc-embedded-no-reselect nil) | 1034 (setq calc-embedded-no-reselect nil) |
1069 | 1035 |
1070 (defun calc-embedded-finish-command () | 1036 (defun calc-embedded-finish-command () |
1071 (let ((buf (current-buffer)) | 1037 (let ((buf (current-buffer)) |
1072 horiz vert) | 1038 horiz vert) |
1093 (set-buffer (aref calc-embedded-info 0)) | 1059 (set-buffer (aref calc-embedded-info 0)) |
1094 (goto-char (aref calc-embedded-info 2)) | 1060 (goto-char (aref calc-embedded-info 2)) |
1095 (if (> vert 0) | 1061 (if (> vert 0) |
1096 (forward-line vert)) | 1062 (forward-line vert)) |
1097 (forward-char (max horiz 0)) | 1063 (forward-char (max horiz 0)) |
1098 (set-buffer buf)))) | 1064 (set-buffer buf))))) |
1099 ) | |
1100 | 1065 |
1101 (defun calc-embedded-stack-change () | 1066 (defun calc-embedded-stack-change () |
1102 (or calc-executing-macro | 1067 (or calc-executing-macro |
1103 (save-excursion | 1068 (save-excursion |
1104 (set-buffer (aref calc-embedded-info 1)) | 1069 (set-buffer (aref calc-embedded-info 1)) |
1126 (setq str (concat (substring str 0 (1+ pos)) | 1091 (setq str (concat (substring str 0 (1+ pos)) |
1127 (substring str (+ pos 5))) | 1092 (substring str (+ pos 5))) |
1128 pos (1+ pos)))))) | 1093 pos (1+ pos)))))) |
1129 (calc-embedded-original-buffer t) | 1094 (calc-embedded-original-buffer t) |
1130 (aset info 8 (car entry)) | 1095 (aset info 8 (car entry)) |
1131 (calc-embedded-update info 13 nil t str entry old-val)))) | 1096 (calc-embedded-update info 13 nil t str entry old-val))))) |
1132 ) | |
1133 | 1097 |
1134 (defun calc-embedded-mode-line-change () | 1098 (defun calc-embedded-mode-line-change () |
1135 (let ((str mode-line-buffer-identification)) | 1099 (let ((str mode-line-buffer-identification)) |
1136 (save-excursion | 1100 (save-excursion |
1137 (calc-embedded-original-buffer t) | 1101 (calc-embedded-original-buffer t) |
1138 (setq mode-line-buffer-identification str) | 1102 (setq mode-line-buffer-identification str) |
1139 (set-buffer-modified-p (buffer-modified-p)))) | 1103 (set-buffer-modified-p (buffer-modified-p))))) |
1140 ) | |
1141 | 1104 |
1142 (defun calc-embedded-modes-change (vars) | 1105 (defun calc-embedded-modes-change (vars) |
1143 (if (eq (car vars) 'calc-language) (setq vars '(the-language))) | 1106 (if (eq (car vars) 'calc-language) (setq vars '(the-language))) |
1144 (if (eq (car vars) 'calc-display-just) (setq vars '(the-display-just))) | 1107 (if (eq (car vars) 'calc-display-just) (setq vars '(the-display-just))) |
1145 (while (and vars | 1108 (while (and vars |
1201 calc-embedded-open-mode | 1164 calc-embedded-open-mode |
1202 "[" header " " mname ": " | 1165 "[" header " " mname ": " |
1203 (prin1-to-string (car values)) "]" | 1166 (prin1-to-string (car values)) "]" |
1204 calc-embedded-close-mode)))) | 1167 calc-embedded-close-mode)))) |
1205 (setq vars (cdr vars) | 1168 (setq vars (cdr vars) |
1206 values (cdr values))))))) | 1169 values (cdr values)))))))) |
1207 ) | |
1208 | 1170 |
1209 (defun calc-embedded-var-change (var &optional buf) | 1171 (defun calc-embedded-var-change (var &optional buf) |
1210 (if (symbolp var) | 1172 (if (symbolp var) |
1211 (setq var (list 'var | 1173 (setq var (list 'var |
1212 (if (string-match "\\`var-.+\\'" | 1174 (if (string-match "\\`var-.+\\'" |
1245 (setcdr (car bp) (delq (car p) (cdr (car bp)))) | 1207 (setcdr (car bp) (delq (car p) (cdr (car bp)))) |
1246 (message | 1208 (message |
1247 "(Tried to recompute but formula was changed or missing.)")))) | 1209 "(Tried to recompute but formula was changed or missing.)")))) |
1248 (setq p (cdr p)))) | 1210 (setq p (cdr p)))) |
1249 (setq bp (if buf nil (cdr bp)))) | 1211 (setq bp (if buf nil (cdr bp)))) |
1250 (or first calc-embedded-quiet (message "")))) | 1212 (or first calc-embedded-quiet (message ""))))) |
1251 ) | 1213 |
1252 | 1214 ;;; calc-embed.el ends here |
1253 | 1215 |
1254 | 1216 |
1255 | 1217 |
1256 |