comparison lisp/calc/calc-prog.el @ 105022:af84e9739140

(arglist): Define for compiler. Delete trailing whitespace.
author Glenn Morris <rgm@gnu.org>
date Tue, 15 Sep 2009 02:35:22 +0000
parents 14b421290b2f
children b78ceb253d15
comparison
equal deleted inserted replaced
105021:c1a58b7ba6a3 105022:af84e9739140
197 (unless keyname 197 (unless keyname
198 (setq keyname (format "%05d" (abs (% (random) 10000))))) 198 (setq keyname (format "%05d" (abs (% (random) 10000)))))
199 (while 199 (while
200 (progn 200 (progn
201 (setq cmd-base-default (concat "User-" keyname)) 201 (setq cmd-base-default (concat "User-" keyname))
202 (setq cmd (completing-read 202 (setq cmd (completing-read
203 (concat "Define M-x command name (default calc-" 203 (concat "Define M-x command name (default calc-"
204 cmd-base-default 204 cmd-base-default
205 "): ") 205 "): ")
206 obarray 'commandp nil 206 obarray 'commandp nil
207 (if (and odef (symbolp (cdr odef))) 207 (if (and odef (symbolp (cdr odef)))
222 (concat "Replace previous definition for " 222 (concat "Replace previous definition for "
223 (symbol-name cmd) "? ") 223 (symbol-name cmd) "? ")
224 "That name conflicts with a built-in Emacs function. Replace this function? ")))))) 224 "That name conflicts with a built-in Emacs function. Replace this function? "))))))
225 (while 225 (while
226 (progn 226 (progn
227 (setq cmd-base-default 227 (setq cmd-base-default
228 (if cmd-base 228 (if cmd-base
229 (if (string-match 229 (if (string-match
230 "\\`User-.+" cmd-base) 230 "\\`User-.+" cmd-base)
231 (concat 231 (concat
232 "User" 232 "User"
233 (substring cmd-base 5)) 233 (substring cmd-base 5))
234 cmd-base) 234 cmd-base)
235 (concat "User" keyname))) 235 (concat "User" keyname)))
236 (setq func 236 (setq func
237 (concat "calcFunc-" 237 (concat "calcFunc-"
238 (completing-read 238 (completing-read
239 (concat "Define algebraic function name (default " 239 (concat "Define algebraic function name (default "
240 cmd-base-default "): ") 240 cmd-base-default "): ")
241 (mapcar (lambda (x) (substring x 9)) 241 (mapcar (lambda (x) (substring x 9))
242 (all-completions "calcFunc-" 242 (all-completions "calcFunc-"
243 obarray)) 243 obarray))
244 (lambda (x) 244 (lambda (x)
245 (fboundp 245 (fboundp
246 (intern (concat "calcFunc-" x)))) 246 (intern (concat "calcFunc-" x))))
247 nil))) 247 nil)))
248 (setq func 248 (setq func
249 (if (string-equal func "calcFunc-") 249 (if (string-equal func "calcFunc-")
250 (intern (concat "calcFunc-" cmd-base-default)) 250 (intern (concat "calcFunc-" cmd-base-default))
268 268
269 (if is-lambda 269 (if is-lambda
270 (setq calc-user-formula-alist arglist) 270 (setq calc-user-formula-alist arglist)
271 (while 271 (while
272 (progn 272 (progn
273 (setq calc-user-formula-alist 273 (setq calc-user-formula-alist
274 (read-from-minibuffer "Function argument list: " 274 (read-from-minibuffer "Function argument list: "
275 (if arglist 275 (if arglist
276 (prin1-to-string arglist) 276 (prin1-to-string arglist)
277 "()") 277 "()")
278 minibuffer-local-map 278 minibuffer-local-map
282 "Okay for arguments that don't appear in formula to be ignored? ")))))) 282 "Okay for arguments that don't appear in formula to be ignored? "))))))
283 (setq is-symb (and calc-user-formula-alist 283 (setq is-symb (and calc-user-formula-alist
284 func 284 func
285 (y-or-n-p 285 (y-or-n-p
286 "Leave it symbolic for non-constant arguments? "))) 286 "Leave it symbolic for non-constant arguments? ")))
287 (setq calc-user-formula-alist 287 (setq calc-user-formula-alist
288 (mapcar (function (lambda (x) 288 (mapcar (function (lambda (x)
289 (or (cdr (assq x '((nil . arg-nil) 289 (or (cdr (assq x '((nil . arg-nil)
290 (t . arg-t)))) 290 (t . arg-t))))
291 x))) calc-user-formula-alist)) 291 x))) calc-user-formula-alist))
292 (if cmd 292 (if cmd
326 (if old 326 (if old
327 (setcdr old cmd) 327 (setcdr old cmd)
328 (setcdr kmap (cons (cons key cmd) (cdr kmap))))))) 328 (setcdr kmap (cons (cons key cmd) (cdr kmap)))))))
329 (message ""))) 329 (message "")))
330 330
331 (defvar arglist) ; dynamically bound in all callers
331 (defun calc-default-formula-arglist (form) 332 (defun calc-default-formula-arglist (form)
332 (if (consp form) 333 (if (consp form)
333 (if (eq (car form) 'var) 334 (if (eq (car form) 'var)
334 (if (or (memq (nth 1 form) arglist) 335 (if (or (memq (nth 1 form) arglist)
335 (math-const-var form)) 336 (math-const-var form))
380 (interactive) 381 (interactive)
381 (calc-wrapper 382 (calc-wrapper
382 (if (eq calc-language 'unform) 383 (if (eq calc-language 'unform)
383 (error "Can't define formats for unformatted mode")) 384 (error "Can't define formats for unformatted mode"))
384 (let* ((comp (calc-top 1)) 385 (let* ((comp (calc-top 1))
385 (func (intern 386 (func (intern
386 (concat "calcFunc-" 387 (concat "calcFunc-"
387 (completing-read "Define format for which function: " 388 (completing-read "Define format for which function: "
388 (mapcar (lambda (x) (substring x 9)) 389 (mapcar (lambda (x) (substring x 9))
389 (all-completions "calcFunc-" 390 (all-completions "calcFunc-"
390 obarray)) 391 obarray))
391 (lambda (x) 392 (lambda (x)
392 (fboundp 393 (fboundp
393 (intern (concat "calcFunc-" x)))))))) 394 (intern (concat "calcFunc-" x))))))))
394 (comps (get func 'math-compose-forms)) 395 (comps (get func 'math-compose-forms))
395 entry entry2 396 entry entry2
396 (arglist nil) 397 (arglist nil)
397 (calc-user-formula-alist nil)) 398 (calc-user-formula-alist nil))
400 (put func 'math-compose-forms (delq entry comps))) 401 (put func 'math-compose-forms (delq entry comps)))
401 (calc-default-formula-arglist comp) 402 (calc-default-formula-arglist comp)
402 (setq arglist (sort arglist 'string-lessp)) 403 (setq arglist (sort arglist 'string-lessp))
403 (while 404 (while
404 (progn 405 (progn
405 (setq calc-user-formula-alist 406 (setq calc-user-formula-alist
406 (read-from-minibuffer "Composition argument list: " 407 (read-from-minibuffer "Composition argument list: "
407 (if arglist 408 (if arglist
408 (prin1-to-string arglist) 409 (prin1-to-string arglist)
409 "()") 410 "()")
410 minibuffer-local-map 411 minibuffer-local-map
415 (or (setq entry (assq calc-language comps)) 416 (or (setq entry (assq calc-language comps))
416 (put func 'math-compose-forms 417 (put func 'math-compose-forms
417 (cons (setq entry (list calc-language)) comps))) 418 (cons (setq entry (list calc-language)) comps)))
418 (or (setq entry2 (assq (length calc-user-formula-alist) (cdr entry))) 419 (or (setq entry2 (assq (length calc-user-formula-alist) (cdr entry)))
419 (setcdr entry 420 (setcdr entry
420 (cons (setq entry2 421 (cons (setq entry2
421 (list (length calc-user-formula-alist))) (cdr entry)))) 422 (list (length calc-user-formula-alist))) (cdr entry))))
422 (setcdr entry2 423 (setcdr entry2
423 (list 'lambda calc-user-formula-alist (calc-fix-user-formula comp)))) 424 (list 'lambda calc-user-formula-alist (calc-fix-user-formula comp))))
424 (calc-pop-stack 1) 425 (calc-pop-stack 1)
425 (calc-do-refresh)))) 426 (calc-do-refresh))))
426 427
427 428
501 (setq calc-user-parse-tables 502 (setq calc-user-parse-tables
502 (delq entry calc-user-parse-tables))))) 503 (delq entry calc-user-parse-tables)))))
503 (switch-to-buffer calc-original-buffer)) 504 (switch-to-buffer calc-original-buffer))
504 505
505 ;; The variable calc-lang is local to calc-write-parse-table, but is 506 ;; The variable calc-lang is local to calc-write-parse-table, but is
506 ;; used by calc-write-parse-table-part which is called by 507 ;; used by calc-write-parse-table-part which is called by
507 ;; calc-write-parse-table. The variable is also local to 508 ;; calc-write-parse-table. The variable is also local to
508 ;; calc-read-parse-table, but is used by calc-fix-token-name which 509 ;; calc-read-parse-table, but is used by calc-fix-token-name which
509 ;; is called (indirectly) by calc-read-parse-table. 510 ;; is called (indirectly) by calc-read-parse-table.
510 (defvar calc-lang) 511 (defvar calc-lang)
511 512
512 (defun calc-write-parse-table (tab calc-lang) 513 (defun calc-write-parse-table (tab calc-lang)
689 (and (consp cmd) 690 (and (consp cmd)
690 (eq (car-safe (nth 3 cmd)) 'calc-execute-kbd-macro))) 691 (eq (car-safe (nth 3 cmd)) 'calc-execute-kbd-macro)))
691 (let* ((mac (elt (nth 1 (nth 3 cmd)) 1)) 692 (let* ((mac (elt (nth 1 (nth 3 cmd)) 1))
692 (str (edmacro-format-keys mac t)) 693 (str (edmacro-format-keys mac t))
693 (kys (nth 3 (nth 3 cmd)))) 694 (kys (nth 3 (nth 3 cmd))))
694 (calc-edit-mode 695 (calc-edit-mode
695 (list 'calc-edit-macro-finish-edit cmdname kys) 696 (list 'calc-edit-macro-finish-edit cmdname kys)
696 t (format (concat 697 t (format (concat
697 "Editing keyboard macro (%s, bound to %s).\n" 698 "Editing keyboard macro (%s, bound to %s).\n"
698 "Original keys: %s \n") 699 "Original keys: %s \n")
699 cmdname kys (elt (nth 1 (nth 3 cmd)) 0))) 700 cmdname kys (elt (nth 1 (nth 3 cmd)) 0)))
700 (insert str "\n") 701 (insert str "\n")
701 (calc-edit-format-macro-buffer) 702 (calc-edit-format-macro-buffer)
702 (calc-show-edit-buffer))) 703 (calc-show-edit-buffer)))
708 (intcmd (symbol-name (cdr def))) 709 (intcmd (symbol-name (cdr def)))
709 (algcmd (if func (substring (symbol-name func) 9) ""))) 710 (algcmd (if func (substring (symbol-name func) 9) "")))
710 (if (and defn (calc-valid-formula-func func)) 711 (if (and defn (calc-valid-formula-func func))
711 (let ((niceexpr (math-format-nice-expr defn (frame-width)))) 712 (let ((niceexpr (math-format-nice-expr defn (frame-width))))
712 (calc-wrapper 713 (calc-wrapper
713 (calc-edit-mode 714 (calc-edit-mode
714 (list 'calc-finish-formula-edit (list 'quote func)) 715 (list 'calc-finish-formula-edit (list 'quote func))
715 nil 716 nil
716 (format (concat 717 (format (concat
717 "Editing formula (%s, %s, bound to %s).\n" 718 "Editing formula (%s, %s, bound to %s).\n"
718 "Original formula: %s\n") 719 "Original formula: %s\n")
790 (kill-line 1) 791 (kill-line 1)
791 (setq curline (calc-edit-macro-command))) 792 (setq curline (calc-edit-macro-command)))
792 (when match 793 (when match
793 (kill-line 1) 794 (kill-line 1)
794 (setq line (concat line (substring curline 0 match)))) 795 (setq line (concat line (substring curline 0 match))))
795 (setq line (replace-regexp-in-string "SPC" " SPC " 796 (setq line (replace-regexp-in-string "SPC" " SPC "
796 (replace-regexp-in-string " " "" line))) 797 (replace-regexp-in-string " " "" line)))
797 (insert line "\t\t\t") 798 (insert line "\t\t\t")
798 (if (> (current-column) 24) 799 (if (> (current-column) 24)
799 (delete-char -1)) 800 (delete-char -1))
800 (insert ";; " type "\n") 801 (insert ";; " type "\n")
815 (not (string-equal "RET" curline)) 816 (not (string-equal "RET" curline))
816 (not (setq match (string-match "<return>" curline)))) 817 (not (setq match (string-match "<return>" curline))))
817 (setq line (concat line curline)) 818 (setq line (concat line curline))
818 (kill-line 1) 819 (kill-line 1)
819 (setq curline (calc-edit-macro-command))) 820 (setq curline (calc-edit-macro-command)))
820 (when match 821 (when match
821 (kill-line 1) 822 (kill-line 1)
822 (setq line (concat line (substring curline 0 match)))) 823 (setq line (concat line (substring curline 0 match))))
823 (setq line (replace-regexp-in-string " " "" line)) 824 (setq line (replace-regexp-in-string " " "" line))
824 (insert cmdbeg " " line "\t\t\t") 825 (insert cmdbeg " " line "\t\t\t")
825 (if (> (current-column) 24) 826 (if (> (current-column) 24)
842 (not (string-equal "RET" curline)) 843 (not (string-equal "RET" curline))
843 (not (setq match (string-match "<return>" curline)))) 844 (not (setq match (string-match "<return>" curline))))
844 (setq line (concat line curline)) 845 (setq line (concat line curline))
845 (kill-line 1) 846 (kill-line 1)
846 (setq curline (calc-edit-macro-command))) 847 (setq curline (calc-edit-macro-command)))
847 (when match 848 (when match
848 (kill-line 1) 849 (kill-line 1)
849 (setq line (concat line (substring curline 0 match)))) 850 (setq line (concat line (substring curline 0 match))))
850 (setq line (replace-regexp-in-string " " "" line)) 851 (setq line (replace-regexp-in-string " " "" line))
851 (insert line "\t\t\t") 852 (insert line "\t\t\t")
852 (if (> (current-column) 24) 853 (if (> (current-column) 24)
1017 (format "Record in %s the algebraic function: " 1018 (format "Record in %s the algebraic function: "
1018 calc-settings-file) 1019 calc-settings-file)
1019 (mapcar (lambda (x) (substring x 9)) 1020 (mapcar (lambda (x) (substring x 9))
1020 (all-completions "calcFunc-" 1021 (all-completions "calcFunc-"
1021 obarray)) 1022 obarray))
1022 (lambda (x) 1023 (lambda (x)
1023 (fboundp 1024 (fboundp
1024 (intern (concat "calcFunc-" x)))) 1025 (intern (concat "calcFunc-" x))))
1025 t))))) 1026 t)))))
1026 (and (eq key ?\M-x) 1027 (and (eq key ?\M-x)
1027 (cons nil 1028 (cons nil
1028 (intern (completing-read 1029 (intern (completing-read