From 2667d5c7fbaa3de8103488c7e3779eb768f9d15c Mon Sep 17 00:00:00 2001 From: Jay Belanger Date: Tue, 15 Sep 2015 19:53:06 -0500 Subject: Add new functions for the root mean square of a (Calc) vector * lisp/calc/calc-stats.el (calcFunc-rms, calc-vector-rms): New functions. * lisp/calc/calc-ext.el (calc-init-extensions): Add keybinding for `calc-vector-rms', add autoloads for `calc-vector-rms' and `calcFunc-rms'. * lisp/calc/calc-map.el (calc-u-oper-keys): Add entry for `calcFunc-rms'. * lisp/calc/calc-menu.el (calc-vectors-menu): Add entry for `calc-vector-rms'. * doc/misc/calc.texi (Single-Variable Statistics): Document the rms command. --- lisp/calc/calc-ext.el | 7 ++++--- lisp/calc/calc-map.el | 1 + lisp/calc/calc-menu.el | 7 +++++++ lisp/calc/calc-stat.el | 11 +++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) (limited to 'lisp/calc') diff --git a/lisp/calc/calc-ext.el b/lisp/calc/calc-ext.el index cb6ab6f8ecc..27898fd9c97 100644 --- a/lisp/calc/calc-ext.el +++ b/lisp/calc/calc-ext.el @@ -574,6 +574,7 @@ (define-key calc-mode-map "uG" 'calc-vector-geometric-mean) (define-key calc-mode-map "uM" 'calc-vector-mean) (define-key calc-mode-map "uN" 'calc-vector-min) + (define-key calc-mode-map "uR" 'calc-vector-rms) (define-key calc-mode-map "uS" 'calc-vector-sdev) (define-key calc-mode-map "uU" 'calc-undo) (define-key calc-mode-map "uX" 'calc-vector-max) @@ -932,7 +933,7 @@ calc-preserve-point calc-replace-selections calc-replace-sub-formula calc-roll-down-with-selections calc-roll-up-with-selections calc-sel-error) - ("calc-stat" calc-vector-op calcFunc-agmean + ("calc-stat" calc-vector-op calcFunc-agmean calcFunc-rms calcFunc-vcorr calcFunc-vcount calcFunc-vcov calcFunc-vflat calcFunc-vgmean calcFunc-vhmean calcFunc-vmax calcFunc-vmean calcFunc-vmeane calcFunc-vmedian calcFunc-vmin calcFunc-vpcov @@ -1147,8 +1148,8 @@ calc-vector-covariance calc-vector-geometric-mean calc-vector-harmonic-mean calc-vector-max calc-vector-mean calc-vector-mean-error calc-vector-median calc-vector-min calc-vector-pop-covariance calc-vector-pop-sdev -calc-vector-pop-variance calc-vector-product calc-vector-sdev -calc-vector-sum calc-vector-variance) +calc-vector-pop-variance calc-vector-product calc-vector-rms +calc-vector-sdev calc-vector-sum calc-vector-variance) ("calc-store" calc-assign calc-copy-special-constant calc-copy-variable calc-declare-variable diff --git a/lisp/calc/calc-map.el b/lisp/calc/calc-map.el index 3b5949c274b..d2c9da86a6f 100644 --- a/lisp/calc/calc-map.el +++ b/lisp/calc/calc-map.el @@ -417,6 +417,7 @@ ( ?G 1 calcFunc-vgmean ) ( ?M 1 calcFunc-vmean ) ( ?N 1 calcFunc-vmin ) + ( ?R 1 calcFunc-rms ) ( ?S 1 calcFunc-vsdev ) ( ?X 1 calcFunc-vmax ) ) ( ( ?C 2 calcFunc-vpcov ) diff --git a/lisp/calc/calc-menu.el b/lisp/calc/calc-menu.el index 44086872dd0..8610090c5d1 100644 --- a/lisp/calc/calc-menu.el +++ b/lisp/calc/calc-menu.el @@ -863,6 +863,13 @@ :keys "I u M" :active (>= (calc-stack-size) 1) :help "The average (arithmetic mean) of the data values as an error form"] + ["rms(1:)" + (progn + (require 'calc-stat) + (call-interactively 'calc-vector-rms)) + :keys "u R" + :active (>= (calc-stack-size) 1) + :help "The root mean square of the data values"] ["sdev(1:)" (progn (require 'calc-stat) diff --git a/lisp/calc/calc-stat.el b/lisp/calc/calc-stat.el index cf0b3ea4a12..a797db2e67d 100644 --- a/lisp/calc/calc-stat.el +++ b/lisp/calc/calc-stat.el @@ -71,6 +71,11 @@ (calc-vector-op "meae" 'calcFunc-vmeane arg) (calc-vector-op "mean" 'calcFunc-vmean arg))))) +(defun calc-vector-rms (arg) + (interactive "P") + (calc-slow-wrapper + (calc-vector-op "rms" 'calcFunc-rms arg))) + (defun calc-vector-mean-error (arg) (interactive "P") (calc-invert-func) @@ -318,6 +323,12 @@ suminvsqrwts)) (math-div (calcFunc-reduce '(var add var-add) means) len))))))) +(defun calcFunc-rms (a) + "Return the root-mean-square of the vector A." + (math-sqrt + (calcFunc-vmean + (calcFunc-map '(var abssqr var-abssqr) a)))) + (defun math-fix-int-intv (x) (if (math-floatp x) x -- cgit v1.2.1 From 284c470ef752967fcd8bae6a450dc138462b1e49 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 17 Sep 2015 16:08:20 -0700 Subject: Backslash cleanup in Elisp source files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch should not change behavior. It typically omits backslashes where they are redundant (e.g., in the string literal "^\$"). In a few places, insert backslashes where they make regular expressions clearer: e.g., replace "^\*" (equivalent to "^*") with "^\\*", which has the same effect as a regular expression. Also, use ‘\ %’ instead of ‘\%’ when avoiding confusion with SCCS IDs, and similarly use ‘\ $’ instead of ‘\$’ when avoiding confusion with RCS IDs, as that makes it clearer that the backslash is intended. --- lisp/calc/calc-help.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/calc') diff --git a/lisp/calc/calc-help.el b/lisp/calc/calc-help.el index 444bb5ef920..33cb1c1566c 100644 --- a/lisp/calc/calc-help.el +++ b/lisp/calc/calc-help.el @@ -386,7 +386,7 @@ C-w Describe how there is no warranty for Calc." (interactive) (calc-quit) (view-emacs-news) - (re-search-forward "^\*+ .*\\" nil t)) + (re-search-forward "^\\*+ .*\\" nil t)) (defvar calc-help-long-names '((?b . "binary/business") (?g . "graphics") -- cgit v1.2.1 From fb875ee6ff20034944df04b83a147493db7ddeb3 Mon Sep 17 00:00:00 2001 From: Jay Belanger Date: Thu, 17 Sep 2015 22:22:18 -0500 Subject: Fix the routine for help on Calc's prefixes. * lisp/calc/calc-ext.el (calc-prefix-help-retry): New variable. (calc-do-prefix-help): Use `read-char' to determine the next Calc command. --- lisp/calc/calc-ext.el | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lisp/calc') diff --git a/lisp/calc/calc-ext.el b/lisp/calc/calc-ext.el index 27898fd9c97..adbb20c82f8 100644 --- a/lisp/calc/calc-ext.el +++ b/lisp/calc/calc-ext.el @@ -1293,6 +1293,7 @@ calc-kill calc-kill-region calc-yank)))) (define-key calc-help-map "?" 'calc-help-for-help) (define-key calc-help-map "\C-h" 'calc-help-for-help)) +(defvar calc-prefix-help-retry nil) (defvar calc-prefix-help-phase 0) (defun calc-do-prefix-help (msgs group key) (if calc-full-help-flag @@ -1300,7 +1301,7 @@ calc-kill calc-kill-region calc-yank)))) (if (cdr msgs) (progn (setq calc-prefix-help-phase - (if (eq this-command last-command) + (if calc-prefix-help-retry (% (1+ calc-prefix-help-phase) (1+ (length msgs))) 0)) (let ((msg (nth calc-prefix-help-phase msgs))) @@ -1321,7 +1322,13 @@ calc-kill calc-kill-region calc-yank)))) (message "%s: %s: %c-" group (car msgs) key) (message "%s: (none) %c-" group key)) (message "%s: %s" group (car msgs)))) - (and key (calc-unread-command key)))) + (let* ((chr (read-char)) + (keys (if key (string key chr) (string chr))) + (bnd (local-key-binding keys))) + (setq calc-prefix-help-retry (= chr ??)) + (if bnd + (call-interactively bnd) + (message (concat keys " is undefined")))))) ;;;; Commands. -- cgit v1.2.1 From 404f3aff4f709641b45e5bcd61f91f860426e0cf Mon Sep 17 00:00:00 2001 From: Jay Belanger Date: Sat, 19 Sep 2015 21:44:45 -0500 Subject: * lisp/calc/calc-ext.el (calc-do-prefix-help): Tidy up error message. --- lisp/calc/calc-ext.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lisp/calc') diff --git a/lisp/calc/calc-ext.el b/lisp/calc/calc-ext.el index adbb20c82f8..83722e761b0 100644 --- a/lisp/calc/calc-ext.el +++ b/lisp/calc/calc-ext.el @@ -1323,12 +1323,13 @@ calc-kill calc-kill-region calc-yank)))) (message "%s: (none) %c-" group key)) (message "%s: %s" group (car msgs)))) (let* ((chr (read-char)) - (keys (if key (string key chr) (string chr))) - (bnd (local-key-binding keys))) + (bnd (local-key-binding (if key (string key chr) (string chr))))) (setq calc-prefix-help-retry (= chr ??)) (if bnd (call-interactively bnd) - (message (concat keys " is undefined")))))) + (if key + (message (concat (key-description (vector key chr)) " is undefined")) + (message (concat (key-description (vector chr)) " is undefined"))))))) ;;;; Commands. -- cgit v1.2.1 From ab11a1cf27ebe3791df45cccde3c851affd184dd Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 20 Sep 2015 09:40:35 -0700 Subject: Use %s to format strings instead of splicing them MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If FOO might contain quotes that are part of a file or variable name, the quotes should not be translated when showing FOO’s name in a diagnostic. So, for example, (message (concat (FOO ": bar"))) is not quite right, as it would translate FOO’s quotes. Change it to (message "%s: bar" FOO) instead. * lisp/allout.el (allout-process-exposed): * lisp/calc/calc-ext.el (calc-do-prefix-help): * lisp/calc/calc-store.el (calc-store-into): * lisp/calendar/todo-mode.el (todo-category-completions): * lisp/cedet/semantic/complete.el (semantic-completion-message): * lisp/org/ob-latex.el (convert-pdf): * lisp/org/org-crypt.el (org-crypt-check-auto-save): * lisp/org/ox-latex.el (org-latex-compile): * lisp/org/ox-man.el (org-man-compile): * lisp/org/ox-odt.el (org-odt--export-wrap): * lisp/org/ox-texinfo.el (org-texinfo-compile): * lisp/progmodes/ruby-mode.el (ruby-in-ppss-context-p): * lisp/progmodes/verilog-mode.el (verilog-batch-execute-func) (verilog-signals-combine-bus, verilog-read-defines) (verilog-getopt-file, verilog-expand-dirnames) (verilog-modi-lookup, verilog-modi-modport-lookup-one): * lisp/term/ns-win.el (ns-spi-service-call): Use %s to avoid translating quotes of file names etc. in diagnostics. --- lisp/calc/calc-ext.el | 5 ++--- lisp/calc/calc-store.el | 12 ++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'lisp/calc') diff --git a/lisp/calc/calc-ext.el b/lisp/calc/calc-ext.el index 83722e761b0..933c446875e 100644 --- a/lisp/calc/calc-ext.el +++ b/lisp/calc/calc-ext.el @@ -1327,9 +1327,8 @@ calc-kill calc-kill-region calc-yank)))) (setq calc-prefix-help-retry (= chr ??)) (if bnd (call-interactively bnd) - (if key - (message (concat (key-description (vector key chr)) " is undefined")) - (message (concat (key-description (vector chr)) " is undefined"))))))) + (message "%s is undefined" + (key-description (if key (vector key chr) (vector chr)))))))) ;;;; Commands. diff --git a/lisp/calc/calc-store.el b/lisp/calc/calc-store.el index 3d8c865c7bf..21209c66677 100644 --- a/lisp/calc/calc-store.el +++ b/lisp/calc/calc-store.el @@ -58,8 +58,8 @@ (let ((msg (calc-store-value var (or calc-given-value (calc-top 1)) "" calc-given-value-flag))) - (message (concat "Stored to variable \"%s\"" msg) - (calc-var-name var))))) + (message "Stored to variable \"%s\"%s" + (calc-var-name var) msg)))) (setq var (calc-is-assignments (calc-top 1))) (if var (while var @@ -67,8 +67,8 @@ (calc-store-value (car (car var)) (cdr (car var)) (if (not (cdr var)) "") (if (not (cdr var)) 1)))) - (message (concat "Stored to variable \"%s\"" msg) - (calc-var-name (car (car var))))) + (message "Stored to variable \"%s\"%s" + (calc-var-name (car (car var))) msg)) (setq var (cdr var)))))))) (defun calc-store-plus (&optional var) @@ -422,8 +422,8 @@ (calc-var-name var1))))) (if var2 (let ((msg (calc-store-value var2 value ""))) - (message (concat "Variable \"%s\" copied to \"%s\"" msg) - (calc-var-name var1) (calc-var-name var2)))))))) + (message "Variable \"%s\" copied to \"%s\"%s" + (calc-var-name var1) (calc-var-name var2) msg))))))) (defvar calc-last-edited-variable nil) (defun calc-edit-variable (&optional var) -- cgit v1.2.1