]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calccomp.el
Merge from origin/emacs-25
[gnu-emacs] / lisp / calc / calccomp.el
index 73e745bcf75cc28c5cb219bc6128f12c216d97d9..a36e9e17f27bfbe539ab3d8233b34ec960aea5cd 100644 (file)
@@ -1,9 +1,8 @@
 ;;; calccomp.el --- composition functions for Calc
 
-;; Copyright (C) 1990-1993, 2001-201 Free Software Foundation, Inc.
+;; Copyright (C) 1990-1993, 2001-2016 Free Software Foundation, Inc.
 
 ;; Author: David Gillespie <daveg@synaptics.com>
-;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
 
 ;; This file is part of GNU Emacs.
 
           (setq sn (math-to-underscores sn)))
       sn)))
 
-(defun math-compose-expr (a prec)
-  (let ((calc-multiplication-has-precedence nil)
+;;; Give multiplication precedence when composing to avoid
+;;; writing a*(b c) instead of a b c
+(defun math-compose-expr (a prec &optional div)
+  (let ((calc-multiplication-has-precedence t)
         (math-compose-level (1+ math-compose-level))
         (math-expr-opers (math-expr-ops))
         spfn)
                    (or (= (length a) 3) (eq (car a) 'calcFunc-if))
                    (/= (nth 3 op) -1))
               (cond
-               ((> prec (or (nth 4 op) (min (nth 2 op) (nth 3 op))))
+               ((or
+                  (> prec (or (nth 4 op) (min (nth 2 op) (nth 3 op))))
+                  (and div (eq (car a) '*)))
                 (if (and (memq calc-language '(tex latex))
                          (not (math-tex-expr-is-flat a)))
                     (if (eq (car-safe a) '/)
                                      nil)
                                  math-compose-level))
                        (lhs (math-compose-expr (nth 1 a) (nth 2 op)))
-                       (rhs (math-compose-expr (nth 2 a) (nth 3 op))))
+                       (rhs (math-compose-expr (nth 2 a) (nth 3 op) (eq (nth 1 op) '/))))
                   (and (equal (car op) "^")
                        (eq (math-comp-first-char lhs) ?-)
                        (setq lhs (list 'horiz "(" lhs ")")))
 
 (provide 'calccomp)
 
-;; Local variables:
-;; coding: utf-8
-;; End:
-
 ;;; calccomp.el ends here