1 ;;; calc-sel.el --- data selection functions for Calc
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
5 ;; Author: David Gillespie <daveg@synaptics.com>
6 ;; Maintainer: Colin Walters <walters@debian.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY. No author or distributor
12 ;; accepts responsibility to anyone for the consequences of using it
13 ;; or for whether it serves any particular purpose or works at all,
14 ;; unless he says so in writing. Refer to the GNU Emacs General Public
15 ;; License for full details.
17 ;; Everyone is granted permission to copy, modify and redistribute
18 ;; GNU Emacs, but only under the conditions described in the
19 ;; GNU Emacs General Public License. A copy of this license is
20 ;; supposed to have been given to you along with GNU Emacs so you
21 ;; can know your rights and responsibilities. It should be in a
22 ;; file named COPYING. Among other things, the copyright notice
23 ;; and this notice must be preserved on all copies.
29 ;; This file is autoloaded from calc-ext.el.
34 (defun calc-Need-calc-sel () nil
)
37 ;;; Selection commands.
39 (defvar calc-keep-selection t
)
41 (defun calc-select-here (num &optional once keep
)
44 (calc-prepare-selection)
45 (let ((found (calc-find-selected-part))
46 (entry calc-selection-cache-entry
))
47 (or (and keep
(nth 2 entry
))
50 (setq calc-keep-selection nil
)
51 (message "(Selection will apply to next command only)")))
52 (calc-change-current-selection
54 (if (and num
(> (setq num
(prefix-numeric-value num
)) 0))
56 (while (and (>= (setq num
(1- num
)) 0)
57 (not (eq found
(car entry
))))
58 (setq found
(calc-find-assoc-parent-formula
61 (calc-grow-assoc-formula (car entry
) found
))
64 (defun calc-select-once (num)
66 (calc-select-here num t
))
68 (defun calc-select-here-maybe (num)
70 (calc-select-here num nil t
))
72 (defun calc-select-once-maybe (num)
74 (calc-select-here num t t
))
76 (defun calc-select-additional ()
79 (let (calc-keep-selection)
80 (calc-prepare-selection))
81 (let ((found (calc-find-selected-part))
82 (entry calc-selection-cache-entry
))
83 (calc-change-current-selection
85 (let ((sel (nth 2 entry
)))
88 (while (not (or (eq sel
(car entry
))
89 (calc-find-sub-formula sel found
)))
90 (setq sel
(calc-find-assoc-parent-formula
93 (calc-grow-assoc-formula (car entry
) found
)))
96 (defun calc-select-more (num)
99 (calc-prepare-selection)
100 (let ((entry calc-selection-cache-entry
))
102 (let ((sel (nth 2 entry
)))
103 (while (and (not (eq sel
(car entry
)))
104 (>= (setq num
(1- (prefix-numeric-value num
))) 0))
105 (setq sel
(calc-find-assoc-parent-formula (car entry
) sel
)))
106 (calc-change-current-selection sel
))
107 (calc-select-here num
)))))
109 (defun calc-select-less (num)
112 (calc-prepare-selection)
113 (let ((found (calc-find-selected-part))
114 (entry calc-selection-cache-entry
))
115 (calc-change-current-selection
117 (let ((sel (nth 2 entry
))
121 (>= (setq num
(1- num
)) 0))
123 index
(calc-find-sub-formula sel found
))
124 (and (setq sel
(and index
(nth index old
)))
125 calc-assoc-selections
126 (setq op
(assq (car-safe sel
) calc-assoc-ops
))
127 (memq (car old
) (nth index op
))
128 (setq num
(1+ num
))))
131 (defun calc-select-part (num)
133 (or num
(setq num
(- last-command-char ?
0)))
135 (calc-prepare-selection)
136 (let ((sel (calc-find-nth-part (or (nth 2 calc-selection-cache-entry
)
137 (car calc-selection-cache-entry
))
140 (calc-change-current-selection sel
)
141 (error "%d is not a valid sub-formula index" num
)))))
143 (defun calc-find-nth-part (expr num
)
144 (if (and calc-assoc-selections
145 (assq (car-safe expr
) calc-assoc-ops
))
147 (calc-find-nth-part-rec expr
))
148 (if (eq (car-safe expr
) 'intv
)
149 (and (>= num
1) (<= num
2) (nth (1+ num
) expr
))
150 (and (not (Math-primp expr
)) (>= num
1) (< num
(length expr
))
153 (defun calc-find-nth-part-rec (expr) ; uses num, op
154 (or (if (and (setq op
(assq (car-safe (nth 1 expr
)) calc-assoc-ops
))
155 (memq (car expr
) (nth 1 op
)))
156 (calc-find-nth-part-rec (nth 1 expr
))
157 (and (= (setq num
(1- num
)) 0)
159 (if (and (setq op
(assq (car-safe (nth 2 expr
)) calc-assoc-ops
))
160 (memq (car expr
) (nth 2 op
)))
161 (calc-find-nth-part-rec (nth 2 expr
))
162 (and (= (setq num
(1- num
)) 0)
165 (defun calc-select-next (num)
168 (calc-select-previous (- num
))
170 (calc-prepare-selection)
171 (let* ((entry calc-selection-cache-entry
)
175 (while (>= (setq num
(1- num
)) 0)
176 (let* ((parent (calc-find-parent-formula (car entry
) sel
))
179 (and (eq p t
) (setq p nil
))
180 (while (and (setq p
(cdr p
))
181 (not (eq (car p
) sel
))))
183 (setq sel
(or (and calc-assoc-selections
184 (setq op
(assq (car-safe (nth 1 p
))
186 (memq (car parent
) (nth 2 op
))
189 (if (and calc-assoc-selections
190 (setq op
(assq (car-safe parent
) calc-assoc-ops
))
191 (consp (setq p
(calc-find-parent-formula
192 (car entry
) parent
)))
193 (eq (nth 1 p
) parent
)
194 (memq (car p
) (nth 1 op
)))
196 (error "No \"next\" sub-formula")))))
197 (calc-change-current-selection sel
))
198 (if (Math-primp (car entry
))
199 (calc-change-current-selection (car entry
))
200 (calc-select-part num
)))))))
202 (defun calc-select-previous (num)
205 (calc-select-next (- num
))
207 (calc-prepare-selection)
208 (let* ((entry calc-selection-cache-entry
)
212 (while (>= (setq num
(1- num
)) 0)
213 (let* ((parent (calc-find-parent-formula (car entry
) sel
))
214 (p (cdr-safe parent
))
217 (if (eq (car-safe parent
) 'intv
) (setq p
(cdr p
)))
218 (while (and (not (eq (car p
) sel
))
222 (setq sel
(or (and calc-assoc-selections
223 (setq op
(assq (car-safe prev
)
225 (memq (car parent
) (nth 1 op
))
228 (if (and calc-assoc-selections
229 (setq op
(assq (car-safe parent
) calc-assoc-ops
))
230 (consp (setq p
(calc-find-parent-formula
231 (car entry
) parent
)))
232 (eq (nth 2 p
) parent
)
233 (memq (car p
) (nth 2 op
)))
235 (error "No \"previous\" sub-formula")))))
236 (calc-change-current-selection sel
))
237 (if (Math-primp (car entry
))
238 (calc-change-current-selection (car entry
))
239 (let ((len (if (and calc-assoc-selections
240 (assq (car (car entry
)) calc-assoc-ops
))
242 (calc-find-nth-part-rec (car entry
))
244 (length (car entry
)))))
245 (calc-select-part (- len num
)))))))))
247 (defun calc-find-parent-formula (expr part
)
248 (cond ((eq expr part
) t
)
249 ((Math-primp expr
) nil
)
252 (while (and (setq p
(cdr p
))
253 (not (setq res
(calc-find-parent-formula
256 (if (eq res t
) expr res
))))))
259 (defun calc-find-assoc-parent-formula (expr part
)
260 (calc-grow-assoc-formula expr
(calc-find-parent-formula expr part
)))
262 (defun calc-grow-assoc-formula (expr part
)
263 (if calc-assoc-selections
264 (let ((op (assq (car-safe part
) calc-assoc-ops
)))
267 (while (and (consp (setq new
(calc-find-parent-formula
270 (nth (calc-find-sub-formula new part
) op
)))
275 (defun calc-find-sub-formula (expr part
)
276 (cond ((eq expr part
) t
)
277 ((Math-primp expr
) nil
)
280 (while (and (setq expr
(cdr expr
))
281 (not (calc-find-sub-formula (car expr
) part
)))
285 (defun calc-unselect (num)
288 (calc-prepare-selection num
)
289 (calc-change-current-selection nil
)))
291 (defun calc-clear-selections ()
294 (let ((limit (calc-stack-size))
297 (if (calc-top n
'sel
)
299 (calc-prepare-selection n
)
300 (calc-change-current-selection nil
)))
302 (calc-clear-command-flag 'position-point
)))
304 (defun calc-show-selections (arg)
307 (calc-preserve-point)
308 (setq calc-show-selections
(if arg
309 (> (prefix-numeric-value arg
) 0)
310 (not calc-show-selections
)))
311 (let ((p calc-stack
))
313 (or (null (nth 2 (car p
)))
314 (equal (car p
) calc-selection-cache-entry
)))
317 (let ((calc-selection-cache-default-entry
318 calc-selection-cache-entry
))
320 (and calc-selection-cache-entry
321 (let ((sel (nth 2 calc-selection-cache-entry
)))
322 (setcar (nthcdr 2 calc-selection-cache-entry
) nil
)
323 (calc-change-current-selection sel
)))))
324 (message (if calc-show-selections
325 "Displaying only selected part of formulas"
326 "Displaying all but selected part of formulas"))))
328 (defun calc-preserve-point ()
329 (or (looking-at "\\.\n+\\'")
331 (setq calc-final-point-line
(+ (count-lines (point-min) (point))
333 calc-final-point-column
(current-column))
334 (calc-set-command-flag 'position-point
))))
336 (defun calc-enable-selections (arg)
339 (calc-preserve-point)
340 (setq calc-use-selections
(if arg
341 (> (prefix-numeric-value arg
) 0)
342 (not calc-use-selections
)))
343 (calc-set-command-flag 'renum-stack
)
344 (message (if calc-use-selections
345 "Commands operate only on selected sub-formulas"
346 "Selections of sub-formulas have no effect"))))
348 (defun calc-break-selections (arg)
351 (calc-preserve-point)
352 (setq calc-assoc-selections
(if arg
353 (<= (prefix-numeric-value arg
) 0)
354 (not calc-assoc-selections
)))
355 (message (if calc-assoc-selections
356 "Selection treats a+b+c as a sum of three terms"
357 "Selection treats a+b+c as (a+b)+c"))))
359 (defvar calc-selection-cache-entry nil
)
360 (defun calc-prepare-selection (&optional num
)
361 (or num
(setq num
(calc-locate-cursor-element (point))))
362 (setq calc-selection-true-num num
363 calc-keep-selection t
)
364 (or (> num
0) (setq num
1))
365 ;; (if (or (< num 1) (> num (calc-stack-size)))
366 ;; (error "Cursor must be positioned on a stack element"))
367 (let* ((entry (calc-top num
'entry
))
369 (or (equal entry calc-selection-cache-entry
)
371 (setcar entry
(calc-encase-atoms (car entry
)))
372 (setq calc-selection-cache-entry entry
373 calc-selection-cache-num num
374 calc-selection-cache-comp
375 (let ((math-comp-tagged t
))
376 (math-compose-expr (car entry
) 0))
377 calc-selection-cache-offset
378 (+ (car (math-stack-value-offset calc-selection-cache-comp
))
379 (length calc-left-label
)
380 (if calc-line-numbering
4 0))))))
381 (calc-preserve-point))
383 ;;; The following ensures that no two subformulas will be "eq" to each other!
384 (defun calc-encase-atoms (x)
385 (if (or (not (consp x
))
386 (equal x
'(float 0 0)))
388 (calc-encase-atoms-rec x
)
391 (defun calc-encase-atoms-rec (x)
394 (if (eq (car x
) 'intv
)
396 (while (setq x
(cdr x
))
397 (if (or (not (consp (car x
)))
398 (equal (car x
) '(float 0 0)))
399 (setcar x
(list 'cplx
(car x
) 0))
400 (calc-encase-atoms-rec (car x
)))))))
402 (defun calc-find-selected-part ()
403 (let* ((math-comp-sel-hpos (- (current-column) calc-selection-cache-offset
))
407 (math-comp-sel-vpos (save-excursion
409 (let ((line (point)))
410 (calc-cursor-stack-index
411 calc-selection-cache-num
)
413 (while (< (point) line
)
415 (setq spaces
(+ spaces
416 (current-indentation))
418 (- lcount
(math-comp-ascent
419 calc-selection-cache-comp
) -
1))))
420 (math-comp-sel-cpos (- (point) toppt calc-selection-cache-offset
422 (math-comp-sel-tag nil
))
423 (and (>= math-comp-sel-hpos
0)
424 (> calc-selection-true-num
0)
425 (math-composition-to-string calc-selection-cache-comp
1000000))
426 (nth 1 math-comp-sel-tag
)))
428 (defun calc-change-current-selection (sub-expr)
429 (or (eq sub-expr
(nth 2 calc-selection-cache-entry
))
430 (let ((calc-prepared-composition calc-selection-cache-comp
)
431 (buffer-read-only nil
)
433 (calc-set-command-flag 'renum-stack
)
434 (setcar (nthcdr 2 calc-selection-cache-entry
) sub-expr
)
435 (calc-cursor-stack-index calc-selection-cache-num
)
437 (calc-cursor-stack-index (1- calc-selection-cache-num
))
438 (delete-region top
(point))
439 (let ((calc-selection-cache-default-entry calc-selection-cache-entry
))
440 (insert (math-format-stack-value calc-selection-cache-entry
)
443 (defun calc-top-selected (&optional n m
)
444 (and calc-any-selections
449 (calc-check-stack (+ n m -
1))
450 (let ((top (nthcdr (+ m calc-stack-top -
1) calc-stack
))
452 (while (>= (setq n
(1- n
)) 0)
453 (if (nth 2 (car top
))
454 (setq sel
(if sel t
(nth 2 (car top
)))))
455 (setq top
(cdr top
)))
458 (defun calc-replace-sub-formula (expr old new
)
459 (setq new
(calc-encase-atoms new
))
460 (calc-replace-sub-formula-rec expr
))
462 (defun calc-replace-sub-formula-rec (expr)
463 (cond ((eq expr old
) new
)
464 ((Math-primp expr
) expr
)
467 (mapcar 'calc-replace-sub-formula-rec
(cdr expr
))))))
469 (defun calc-sel-error ()
470 (error "Illegal operation on sub-formulas"))
472 (defun calc-replace-selections (n vals m
)
473 (if (calc-top-selected n m
)
474 (let ((num (length vals
)))
475 (calc-preserve-point)
478 (let* ((old (calc-top-list n m
'entry
))
483 (if (nth 2 (car old
))
484 (setq val
(calc-encase-atoms (car vals
))
485 new
(cons (calc-replace-sub-formula (car (car old
))
490 (setq new
(cons (car vals
) new
)
492 (setq vals
(cdr vals
)
494 (calc-pop-stack n m t
)
495 (calc-push-list (nreverse new
)
496 m
(and calc-keep-selection
(nreverse sel
)))))
498 (let* ((old (calc-top-list n m
'entry
))
500 (while (and old
(not (nth 2 (car old
))))
501 (setq old
(cdr old
)))
503 (while (and (setq more
(cdr more
)) (not (nth 2 (car more
)))))
506 (calc-pop-stack n m t
)
508 (let ((val (calc-encase-atoms (car vals
))))
509 (calc-push-list (list (calc-replace-sub-formula
513 m
(and calc-keep-selection
(list val
))))
514 (calc-push-list vals
))))
515 (t (calc-sel-error))))
516 (calc-pop-stack n m t
)
517 (calc-push-list vals m
)))
519 (defun calc-delete-selection (n)
520 (let ((entry (calc-top n
'entry
)))
522 (if (eq (nth 2 entry
) (car entry
))
524 (calc-pop-stack 1 n t
)
525 (calc-push-list '(0) n
))
526 (let ((parent (calc-find-parent-formula (car entry
) (nth 2 entry
)))
528 (calc-preserve-point)
529 (calc-pop-stack 1 n t
)
530 (cond ((or (memq (car parent
) '(* / %
))
531 (and (eq (car parent
) '^
)
532 (eq (nth 2 parent
) (nth 2 entry
))))
534 ((memq (car parent
) '(vec calcFunc-min calcFunc-max
)))
535 ((and (assq (car parent
) calc-tweak-eqn-table
)
536 (= (length parent
) 3))
542 (calc-push-list (list
544 (calc-replace-sub-formula
547 (if (eq (nth 2 entry
) (nth 1 parent
))
552 (calc-push-list (list
554 (calc-replace-sub-formula (car entry
)
559 (calc-push-list (list
561 (calc-replace-sub-formula (car entry
)
567 (calc-pop-stack 1 n t
))))
569 (defun calc-roll-down-with-selections (n m
)
570 (let ((vals (append (calc-top-list m
1)
571 (calc-top-list (- n m
) (1+ m
))))
572 (sels (append (calc-top-list m
1 'sel
)
573 (calc-top-list (- n m
) (1+ m
) 'sel
))))
574 (calc-pop-push-list n vals
1 sels
)))
576 (defun calc-roll-up-with-selections (n m
)
577 (let ((vals (append (calc-top-list (- n m
) 1)
578 (calc-top-list m
(- n m -
1))))
579 (sels (append (calc-top-list (- n m
) 1 'sel
)
580 (calc-top-list m
(- n m -
1) 'sel
))))
581 (calc-pop-push-list n vals
1 sels
)))
583 (defun calc-auto-selection (entry)
586 (and (boundp 'reselect
) (setq reselect nil
))
587 (calc-prepare-selection)
588 (calc-grow-assoc-formula (car entry
) (calc-find-selected-part)))))
590 (defun calc-copy-selection ()
593 (calc-preserve-point)
594 (let* ((num (max 1 (calc-locate-cursor-element (point))))
595 (entry (calc-top num
'entry
)))
596 (calc-push (or (calc-auto-selection entry
) (car entry
))))))
598 (defun calc-del-selection ()
601 (calc-preserve-point)
602 (let* ((num (max 1 (calc-locate-cursor-element (point))))
603 (entry (calc-top num
'entry
))
604 (sel (calc-auto-selection entry
)))
605 (setcar (nthcdr 2 entry
) (and (not (eq sel
(car entry
))) sel
))
606 (calc-delete-selection num
))))
608 (defun calc-enter-selection ()
611 (calc-preserve-point)
612 (let* ((num (max 1 (calc-locate-cursor-element (point))))
613 (reselect calc-keep-selection
)
614 (entry (calc-top num
'entry
))
616 (sel (or (calc-auto-selection entry
) expr
))
618 (let ((calc-dollar-values (list sel
))
619 (calc-dollar-used 0))
620 (setq alg
(calc-do-alg-entry "" "Replace selection with: "))
623 (setq alg
(calc-encase-atoms (car alg
)))
624 (calc-pop-push-record-list 1 "repl"
625 (list (calc-replace-sub-formula
628 (list (and reselect alg
))))))
629 (calc-handle-whys))))
631 (defun calc-edit-selection ()
634 (calc-preserve-point)
635 (let* ((num (max 1 (calc-locate-cursor-element (point))))
636 (reselect calc-keep-selection
)
637 (entry (calc-top num
'entry
))
639 (sel (or (calc-auto-selection entry
) expr
))
641 (let ((str (math-showing-full-precision
642 (math-format-nice-expr sel
(frame-width)))))
643 (calc-edit-mode (list 'calc-finish-selection-edit
644 num
(list 'quote sel
) reselect
))
646 (calc-show-edit-buffer))
648 (defun calc-finish-selection-edit (num sel reselect
)
649 (let ((buf (current-buffer))
650 (str (buffer-substring (point) (point-max)))
652 (switch-to-buffer calc-original-buffer
)
653 (let ((val (math-read-expr str
)))
654 (if (eq (car-safe val
) 'error
)
656 (switch-to-buffer buf
)
657 (goto-char (+ start
(nth 1 val
)))
658 (error (nth 2 val
))))
660 (calc-preserve-point)
662 (calc-trail-display 1 t
))
663 (setq val
(calc-encase-atoms (calc-normalize val
)))
664 (let ((expr (calc-top num
'full
)))
665 (if (calc-find-sub-formula expr sel
)
666 (calc-pop-push-record-list 1 "edit"
667 (list (calc-replace-sub-formula
670 (list (and reselect val
)))
672 (error "Original selection has been lost")))))))
674 (defun calc-sel-evaluate (arg)
677 (calc-preserve-point)
678 (let* ((num (max 1 (calc-locate-cursor-element (point))))
679 (reselect calc-keep-selection
)
680 (entry (calc-top num
'entry
))
681 (sel (or (calc-auto-selection entry
) (car entry
))))
682 (calc-with-default-simplification
683 (let ((math-simplify-only nil
))
684 (calc-modify-simplify-mode arg
)
685 (let ((val (calc-encase-atoms (calc-normalize sel
))))
686 (calc-pop-push-record-list 1 "jsmp"
687 (list (calc-replace-sub-formula
688 (car entry
) sel val
))
690 (list (and reselect val
))))))
691 (calc-handle-whys))))
693 (defun calc-sel-expand-formula (arg)
696 (calc-preserve-point)
697 (let* ((num (max 1 (calc-locate-cursor-element (point))))
698 (reselect calc-keep-selection
)
699 (entry (calc-top num
'entry
))
700 (sel (or (calc-auto-selection entry
) (car entry
))))
701 (calc-with-default-simplification
702 (let ((math-simplify-only nil
))
703 (calc-modify-simplify-mode arg
)
704 (let* ((math-expand-formulas (> arg
0))
705 (val (calc-normalize sel
))
708 (setq top
(math-expand-formula val
))
709 (setq val
(calc-normalize top
)))
710 (setq val
(calc-encase-atoms val
))
711 (calc-pop-push-record-list 1 "jexf"
712 (list (calc-replace-sub-formula
713 (car entry
) sel val
))
715 (list (and reselect val
))))))
716 (calc-handle-whys))))
718 (defun calc-sel-mult-both-sides (no-simp &optional divide
)
721 (calc-preserve-point)
722 (let* ((num (max 1 (calc-locate-cursor-element (point))))
723 (reselect calc-keep-selection
)
724 (entry (calc-top num
'entry
))
726 (sel (or (calc-auto-selection entry
) expr
))
727 (func (car-safe sel
))
729 (setq alg
(calc-with-default-simplification
730 (car (calc-do-alg-entry ""
732 "Divide both sides by: "
733 "Multiply both sides by: ")))))
736 (if (and (or (eq func
'/)
737 (assq func calc-tweak-eqn-table
))
740 (or (memq func
'(/ calcFunc-eq calcFunc-neq
))
741 (if (math-known-nonposp alg
)
743 (setq func
(nth 1 (assq func
744 calc-tweak-eqn-table
)))
745 (or (math-known-negp alg
)
746 (message "Assuming this factor is nonzero")))
747 (or (math-known-posp alg
)
748 (if (math-known-nonnegp alg
)
749 (message "Assuming this factor is nonzero")
750 (message "Assuming this factor is positive")))))
751 (setq lhs
(list (if divide
'/ '*) (nth 1 sel
) alg
)
752 rhs
(list (if divide
'/ '*) (nth 2 sel
) alg
))
755 (setq lhs
(math-simplify lhs
)
756 rhs
(math-simplify rhs
))
758 (or (Math-equal (nth 1 sel
) 1)
759 (Math-equal (nth 1 sel
) -
1)
760 (and (memq (car-safe (nth 2 sel
)) '(+ -
))
761 (memq (car-safe alg
) '(+ -
))))
762 (setq rhs
(math-expand-term rhs
)))))
763 (setq alg
(calc-encase-atoms
764 (calc-normalize (list func lhs rhs
)))))
765 (setq rhs
(list (if divide
'* '/) sel alg
))
767 (setq rhs
(math-simplify rhs
)))
768 (setq alg
(calc-encase-atoms
769 (calc-normalize (if divide
771 (list '* alg rhs
))))))
772 (calc-pop-push-record-list 1 (if divide
"div" "mult")
773 (list (calc-replace-sub-formula
776 (list (and reselect alg
)))))
777 (calc-handle-whys))))
779 (defun calc-sel-div-both-sides (no-simp)
781 (calc-sel-mult-both-sides no-simp t
))
783 (defun calc-sel-add-both-sides (no-simp &optional subtract
)
786 (calc-preserve-point)
787 (let* ((num (max 1 (calc-locate-cursor-element (point))))
788 (reselect calc-keep-selection
)
789 (entry (calc-top num
'entry
))
791 (sel (or (calc-auto-selection entry
) expr
))
792 (func (car-safe sel
))
794 (setq alg
(calc-with-default-simplification
795 (car (calc-do-alg-entry ""
797 "Subtract from both sides: "
798 "Add to both sides: ")))))
801 (if (and (assq func calc-tweak-eqn-table
)
804 (setq lhs
(list (if subtract
'-
'+) (nth 1 sel
) alg
)
805 rhs
(list (if subtract
'-
'+) (nth 2 sel
) alg
))
807 (setq lhs
(math-simplify lhs
)
808 rhs
(math-simplify rhs
)))
809 (setq alg
(calc-encase-atoms
810 (calc-normalize (list func lhs rhs
)))))
811 (setq rhs
(list (if subtract
'+ '-
) sel alg
))
813 (setq rhs
(math-simplify rhs
)))
814 (setq alg
(calc-encase-atoms
815 (calc-normalize (list (if subtract
'-
'+) alg rhs
)))))
816 (calc-pop-push-record-list 1 (if subtract
"sub" "add")
817 (list (calc-replace-sub-formula
820 (list (and reselect alg
)))))
821 (calc-handle-whys))))
823 (defun calc-sel-sub-both-sides (no-simp)
825 (calc-sel-add-both-sides no-simp t
))
827 ;;; calc-sel.el ends here