]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calccomp.el
Update copyright year to 2015
[gnu-emacs] / lisp / calc / calccomp.el
index 6923cd7693a2b3c6fb0cefccf3760932730f6761..a3432c14b151bbf5a363f2a433cccf7938f63af5 100644 (file)
@@ -1,7 +1,6 @@
 ;;; calccomp.el --- composition functions for Calc
 
-;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004, 2005,
-;;   2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 1990-1993, 2001-2015 Free Software Foundation, Inc.
 
 ;; Author: David Gillespie <daveg@synaptics.com>
 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
           (setq sn (math-to-underscores sn)))
       sn)))
 
-(defun math-compose-expr (a prec)
-  (let ((math-compose-level (1+ math-compose-level))
+;;; 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)
     (cond
                    (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 ")")))
                 (let ((prefix "") mrg wid)
                   (setq mrg (aref math-comp-buf-margin i))
                   (if (> mrg 12)  ; indenting too far, go back to far left
-                      (let ((j i) (new (if calc-line-numbering 5 1)))
-                        '(while (<= j math-comp-level)
-                          (aset math-comp-buf-margin j
-                                (+ (aref math-comp-buf-margin j) (- new mrg)))
-                          (setq j (1+ j)))
-                        (setq mrg new)))
+                      (setq mrg (if calc-line-numbering 5 1)))
                   (setq wid (+ (length str) math-comp-margin))
                   (and (> (length str) 0) (= (aref str 0) ? )
                        (> (length math-comp-buf) 0)
 ;; coding: utf-8
 ;; End:
 
-;; arch-tag: 7c45d10a-a286-4dab-af49-7ae8989fbf78
 ;;; calccomp.el ends here