view lisp/calc/calc-stuff.el @ 110523:a5ad4f188e19

Synch Semantic to CEDET 1.0. Move CEDET ChangeLog entries to new file lisp/cedet/ChangeLog. * semantic.el (semantic-version): Update to 2.0. (semantic-mode-map): Add "," and "m" bindings. (navigate-menu): Update. * semantic/symref.el (semantic-symref-calculate-rootdir): New function. (semantic-symref-detect-symref-tool): Use it. * semantic/symref/grep.el (semantic-symref-grep-shell): New var. (semantic-symref-perform-search): Use it. Calculate root dir with semantic-symref-calculate-rootdir. (semantic-symref-derive-find-filepatterns): Improve error message. * semantic/symref/list.el (semantic-symref-results-mode-map): New bindings. (semantic-symref-auto-expand-results): New option. (semantic-symref-results-dump): Obey auto-expand. (semantic-symref-list-expand-all, semantic-symref-regexp) (semantic-symref-list-contract-all) (semantic-symref-list-map-open-hits) (semantic-symref-list-update-open-hits) (semantic-symref-list-create-macro-on-open-hit) (semantic-symref-list-call-macro-on-open-hits): New functions. (semantic-symref-list-menu-entries) (semantic-symref-list-menu): New vars. (semantic-symref-list-map-open-hits): Move cursor to beginning of match before calling the mapped function. * semantic/doc.el (semantic-documentation-comment-preceeding-tag): Do nothing if the mode doesn't provide comment-start-skip. * semantic/scope.el (semantic-analyze-scope-nested-tags-default): Strip duplicates. (semantic-analyze-scoped-inherited-tag-map): Take the tag we are looking for as part of the scoped tags list. * semantic/html.el (semantic-default-html-setup): Add senator-step-at-tag-classes. * semantic/decorate/include.el (semantic-decoration-on-unknown-includes): Change light bgcolor. (semantic-decoration-on-includes-highlight-default): Check that the include tag has a postion. * semantic/complete.el (semantic-collector-local-members): (semantic-complete-read-tag-local-members) (semantic-complete-jump-local-members): New class and functions. (semantic-complete-self-insert): Save excursion before completing. * semantic/analyze/complete.el (semantic-analyze-possible-completions-default): If no completions are found, return the raw by-name-only completion list. Add FLAGS arguments. Add support for 'no-tc (type constraint) and 'no-unique, or no stripping duplicates. (semantic-analyze-possible-completions-default): Add FLAGS arg. * semantic/util-modes.el (semantic-stickyfunc-show-only-functions-p): New option. (semantic-stickyfunc-fetch-stickyline): Don't show stickytext for the very first line in a buffer. * semantic/util.el (semantic-hack-search) (semantic-recursive-find-nonterminal-by-name) (semantic-current-tag-interactive): Deleted. (semantic-describe-buffer): Fix expand-nonterminal. Add lex-syntax-mods, type relation separator char, and command separation char. (semantic-sanity-check): Only message if called interactively. * semantic/tag.el (semantic-tag-deep-copy-one-tag): Copy the :filename property and the tag position. * semantic/lex-spp.el (semantic-lex-spp-lex-text-string): Add recursion limit. * semantic/imenu.el (semantic-imenu-bucketize-type-members): Make this buffer local, not the obsoleted variable. * semantic/idle.el: Add breadcrumbs support. (semantic-idle-summary-current-symbol-info-default) (semantic-idle-tag-highlight) (semantic-idle-completion-list-default): Use semanticdb-without-unloaded-file-searches for speed, and to conform to the controls that specify if the idle timer is supposed to be parsing unparsed includes. (semantic-idle-symbol-highlight-face) (semantic-idle-symbol-maybe-highlight): Rename from *-summary-*. Callers changed. (semantic-idle-work-parse-neighboring-files-flag): Default to nil. (semantic-idle-work-update-headers-flag): New var. (semantic-idle-work-for-one-buffer): Use it. (semantic-idle-local-symbol-highlight): Rename from semantic-idle-tag-highlight. (semantic-idle-truncate-long-summaries): New option. * semantic/ia.el (semantic-ia-cache) (semantic-ia-get-completions): Deleted. Callers changed. (semantic-ia-show-variants): New command. (semantic-ia-show-doc): If doc is empty, don't make a temp buffer. (semantic-ia-show-summary): If there isn't anything to show, say so. * semantic/grammar.el (semantic-grammar-create-package): Save the buffer even in batch mode. * semantic/fw.el (semanticdb-without-unloaded-file-searches): New macro. * semantic/dep.el (semantic-dependency-find-file-on-path): Fix case dereferencing ede-object when it is a list. * semantic/db-typecache.el (semanticdb-expand-nested-tag) (semanticdb-typecache-faux-namespace): New functions. (semanticdb-typecache-file-tags) (semanticdb-typecache-merge-streams): Use them. (semanticdb-typecache-file-tags): When deriving tags from a file, give the mode a chance to monkey with the tag copy. (semanticdb-typecache-find-default): Wrap find in save-excursion. (semanticdb-typecache-find-by-name-helper): Merge found names down. * semantic/db-global.el (semanticdb-enable-gnu-global-in-buffer): Don't show messages if GNU Global is not available and we don't want to throw an error. * semantic/db-find.el (semanticdb-find-result-nth-in-buffer): When trying to normalize the tag to a buffer, don't error if set-buffer method doesn't exist. * semantic/db-file.el (semanticdb-save-db): Simplify msg. * semantic/db.el (semanticdb-refresh-table): If forcing a refresh on a file not in a buffer, use semantic-find-file-noselect and delete the buffer after use. (semanticdb-current-database-list): When calculating root via hooks, force it through true-filename and skip the list of possible roots. * semantic/ctxt.el (semantic-ctxt-imported-packages): New. * semantic/analyze/debug.el (semantic-analyzer-debug-insert-tag): Reset standard output to current buffer. (semantic-analyzer-debug-global-symbol) (semantic-analyzer-debug-missing-innertype): Change "prefix" to "symbol" in messages. * semantic/analyze/refs.el: (semantic-analyze-refs-impl) (semantic-analyze-refs-proto): When calculating value, make sure the found tag is 'similar' to the originating tag. (semantic--analyze-refs-find-tags-with-parent): Attempt to identify matches via imported symbols of parents. (semantic--analyze-refs-full-lookup-with-parents): Do a deep search during the brute search. * semantic/analyze.el (semantic-analyze-find-tag-sequence-default): Be robust to calculated scopes being nil. * semantic/bovine/c.el (semantic-c-describe-environment): Add project macro symbol array. (semantic-c-parse-lexical-token): Add recursion limit. (semantic-ctxt-imported-packages, semanticdb-expand-nested-tag): New overrides. (semantic-expand-c-tag-namelist): Split a full type from a typedef out to its own tag. (semantic-expand-c-tag-namelist): Do not split out a typedef'd inline type if it is an anonymous type. (semantic-c-reconstitute-token): Use the optional initializers as a clue that some function is probably a constructor. When defining the type of these constructors, split the parent name, and use only the class part, if applicable. * semantic/bovine/c-by.el: * semantic/wisent/python-wy.el: Regenerate.
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 18 Sep 2010 22:49:54 -0400
parents 1d1d5d9bd884
children 376148b31b5e
line wrap: on
line source

;;; calc-stuff.el --- miscellaneous functions for Calc

;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
;;   2005, 2006, 2007, 2008, 2009, 2010 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.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;;; Code:

;; This file is autoloaded from calc-ext.el.

(require 'calc-ext)
(require 'calc-macs)

(defun calc-num-prefix (n)
  "Use the number at the top of stack as the numeric prefix for the next command.
With a prefix, push that prefix as a number onto the stack."
  (interactive "P")
  (calc-wrapper
   (if n
       (calc-enter-result 0 "" (prefix-numeric-value n))
     (let ((num (calc-top 1)))
       (if (math-messy-integerp num)
	   (setq num (math-trunc num)))
       (or (integerp num)
	   (error "Argument must be a small integer"))
       (calc-pop-stack 1)
       (setq prefix-arg num)
       (message "%d-" num)))))    ; a (lame) simulation of the real thing...


(defun calc-more-recursion-depth (n)
  (interactive "P")
  (calc-wrapper
   (if (calc-is-inverse)
       (calc-less-recursion-depth n)
     (let ((n (if n (prefix-numeric-value n) 2)))
       (if (> n 1)
	   (setq max-specpdl-size (* max-specpdl-size n)
		 max-lisp-eval-depth (* max-lisp-eval-depth n))))
     (message "max-lisp-eval-depth is now %d" max-lisp-eval-depth))))

(defun calc-less-recursion-depth (n)
  (interactive "P")
  (let ((n (if n (prefix-numeric-value n) 2)))
    (if (> n 1)
	(setq max-specpdl-size
	      (max (/ max-specpdl-size n) 600)
	      max-lisp-eval-depth
	      (max (/ max-lisp-eval-depth n) 200))))
  (message "max-lisp-eval-depth is now %d" max-lisp-eval-depth))


(defvar calc-which-why nil)
(defvar calc-last-why-command nil)
(defun calc-explain-why (why &optional more)
  (if (eq (car why) '*)
      (setq why (cdr why)))
  (let* ((pred (car why))
	 (arg (nth 1 why))
	 (msg (cond ((not pred) "Wrong type of argument")
		    ((stringp pred) pred)
		    ((eq pred 'integerp) "Integer expected")
		    ((eq pred 'natnump)
		     (if (and arg (Math-objvecp arg) (not (Math-integerp arg)))
			 "Integer expected"
		       "Nonnegative integer expected"))
		    ((eq pred 'posintp)
		     (if (and arg (Math-objvecp arg) (not (Math-integerp arg)))
			 "Integer expected"
		       "Positive integer expected"))
		    ((eq pred 'fixnump)
		     (if (and arg (Math-integerp arg))
			 "Small integer expected"
		       "Integer expected"))
		    ((eq pred 'fixnatnump)
		     (if (and arg (Math-natnump arg))
			 "Small integer expected"
		       (if (and arg (Math-objvecp arg)
				(not (Math-integerp arg)))
			   "Integer expected"
			 "Nonnegative integer expected")))
		    ((eq pred 'fixposintp)
		     (if (and arg (Math-integerp arg) (Math-posp arg))
			 "Small integer expected"
		       (if (and arg (Math-objvecp arg)
				(not (Math-integerp arg)))
			   "Integer expected"
			 "Positive integer expected")))
		    ((eq pred 'posp) "Positive number expected")
		    ((eq pred 'negp) "Negative number expected")
		    ((eq pred 'nonzerop) "Nonzero number expected")
		    ((eq pred 'realp) "Real number expected")
		    ((eq pred 'anglep) "Real number expected")
		    ((eq pred 'hmsp) "HMS form expected")
		    ((eq pred 'datep)
		     (if (and arg (Math-objectp arg)
			      (not (Math-realp arg)))
			 "Real number or date form expected"
		       "Date form expected"))
		    ((eq pred 'numberp) "Number expected")
		    ((eq pred 'scalarp) "Number expected")
		    ((eq pred 'vectorp) "Vector or matrix expected")
		    ((eq pred 'numvecp) "Number or vector expected")
		    ((eq pred 'matrixp) "Matrix expected")
		    ((eq pred 'square-matrixp)
		     (if (and arg (math-matrixp arg))
			 "Square matrix expected"
		       "Matrix expected"))
		    ((eq pred 'objectp) "Number expected")
		    ((eq pred 'constp) "Constant expected")
		    ((eq pred 'range) "Argument out of range")
		    (t (format "%s expected" pred))))
	 (punc ": ")
	 (calc-can-abbrev-vectors t))
    (while (setq why (cdr why))
      (and (car why)
	   (setq msg (concat msg punc (if (stringp (car why))
					  (car why)
					(math-format-flat-expr (car why) 0)))
		 punc ", ")))
    (message "%s%s" msg (if more "  [w=more]" ""))))

(defun calc-why ()
  (interactive)
  (if (not (eq this-command last-command))
      (if (eq last-command calc-last-why-command)
	  (setq calc-which-why (cdr calc-why))
	(setq calc-which-why calc-why)))
  (if calc-which-why
      (progn
	(calc-explain-why (car calc-which-why) (cdr calc-which-why))
	(setq calc-which-why (cdr calc-which-why)))
    (if calc-why
	(progn
	  (message "(No further explanations available)")
	  (setq calc-which-why calc-why))
      (message "No explanations available"))))

;; The following caches are declared in other files, but are
;; reset here.
(defvar math-lud-cache) ; calc-mtx.el
(defvar math-log2-cache) ; calc-bin.el
(defvar math-radix-digits-cache) ; calc-bin.el
(defvar math-radix-float-cache-tag) ; calc-bin.el
(defvar math-random-cache) ; calc-comb.el
(defvar math-max-digits-cache) ; calc-bin.el
(defvar math-integral-cache) ; calcalg2.el
(defvar math-units-table) ; calc-units.el
(defvar math-decls-cache-tag) ; calc-arith.el
(defvar math-format-date-cache) ; calc-forms.el
(defvar math-holidays-cache-tag) ; calc-forms.el

(defun calc-flush-caches (&optional inhibit-msg)
  (interactive "P")
  (calc-wrapper
   (setq math-lud-cache nil
	 math-log2-cache nil
	 math-radix-digits-cache nil
	 math-radix-float-cache-tag nil
	 math-random-cache nil
	 math-max-digits-cache nil
	 math-integral-cache nil
	 math-units-table nil
	 math-decls-cache-tag nil
	 math-eval-rules-cache-tag t
	 math-format-date-cache nil
	 math-holidays-cache-tag t)
   (mapc (function (lambda (x) (set x -100))) math-cache-list)
   (unless inhibit-msg
     (message "All internal calculator caches have been reset"))))


;;; Conversions.

(defun calc-clean (n)
  (interactive "P")
  (calc-slow-wrapper
   (calc-with-default-simplification
    (let ((func (if (calc-is-hyperbolic) 'calcFunc-clean 'calcFunc-pclean)))
      (calc-enter-result 1 "cln"
			 (if n
			     (let ((n (prefix-numeric-value n)))
			       (list func
				     (calc-top-n 1)
				     (if (<= n 0)
					 (+ n calc-internal-prec)
				       n)))
			   (list func (calc-top-n 1))))))))

(defun calc-clean-num (num)
  (interactive "P")
  (calc-clean (- (if num
		     (prefix-numeric-value num)
		   (if (and (>= last-command-event ?0)
			    (<= last-command-event ?9))
		       (- last-command-event ?0)
		     (error "Number required"))))))


(defvar math-chopping-small nil)
(defun calcFunc-clean (a &optional prec)   ; [X X S] [Public]
  (if prec
      (cond ((Math-messy-integerp prec)
	     (calcFunc-clean a (math-trunc prec)))
	    ((or (not (integerp prec))
		 (< prec 3))
	     (calc-record-why "*Precision must be an integer 3 or above")
	     (list 'calcFunc-clean a prec))
	    ((not (Math-objvecp a))
	     (list 'calcFunc-clean a prec))
	    (t (let ((calc-internal-prec prec)
		     (math-chopping-small t))
		 (calcFunc-clean (math-normalize a)))))
    (cond ((eq (car-safe a) 'polar)
	   (let ((theta (math-mod (nth 2 a)
				  (if (eq calc-angle-mode 'rad)
				      (math-two-pi)
				    360))))
	     (math-neg
	      (math-neg
	       (math-normalize
		(list 'polar
		      (calcFunc-clean (nth 1 a))
		      (calcFunc-clean theta)))))))
	  ((memq (car-safe a) '(vec date hms))
	   (cons (car a) (mapcar 'calcFunc-clean (cdr a))))
	  ((memq (car-safe a) '(cplx mod sdev intv))
	   (math-normalize (cons (car a) (mapcar 'calcFunc-clean (cdr a)))))
	  ((eq (car-safe a) 'float)
	   (if math-chopping-small
	       (if (or (> (nth 2 a) (- calc-internal-prec))
		       (Math-lessp (- calc-internal-prec) (calcFunc-xpon a)))
		   (if (and (math-num-integerp a)
			    (math-lessp (calcFunc-xpon a) calc-internal-prec))
		       (math-trunc a)
		     a)
		 0)
	     a))
	  ((Math-objectp a) a)
	  ((math-infinitep a) a)
	  (t (list 'calcFunc-clean a)))))

(defun calcFunc-pclean (a &optional prec)
  (math-map-over-constants (function (lambda (x) (calcFunc-clean x prec)))
			   a))

(defun calcFunc-pfloat (a)
  (math-map-over-constants 'math-float a))

(defun calcFunc-pfrac (a &optional tol)
  (math-map-over-constants (function (lambda (x) (calcFunc-frac x tol)))
			   a))

;; The variable math-moc-func is local to math-map-over-constants,
;; but is used by math-map-over-constants-rec, which is called by
;; math-map-over-constants.
(defvar math-moc-func)

(defun math-map-over-constants (math-moc-func expr)
  (math-map-over-constants-rec expr))

(defun math-map-over-constants-rec (expr)
  (cond ((or (Math-primp expr)
	     (memq (car expr) '(intv sdev)))
	 (or (and (Math-objectp expr)
		  (funcall math-moc-func expr))
	     expr))
	((and (memq (car expr) '(^ calcFunc-subscr))
	      (eq math-moc-func 'math-float)
	      (= (length expr) 3)
	      (Math-integerp (nth 2 expr)))
	 (list (car expr)
	       (math-map-over-constants-rec (nth 1 expr))
	       (nth 2 expr)))
	(t (cons (car expr) (mapcar 'math-map-over-constants-rec (cdr expr))))))

(provide 'calc-stuff)

;; arch-tag: 789332ef-a178-49d3-8fb7-5d7ed7e21f56
;;; calc-stuff.el ends here