└── calc-transient.el /calc-transient.el: -------------------------------------------------------------------------------- 1 | (require 'calc) 2 | (require 'transient) 3 | ;; http://0x0.st/o-cL.png 4 | 5 | ;; calc-mode-map 6 | ;; calc-alg-map 7 | ;; calc-help-map 8 | ;; calc-mode-map 9 | ;; calc-digit-map 10 | ;; calc-alg-esc-map 11 | ;; calc-dispatch-map 12 | ;; calc-trail-mode-map 13 | ;; calc-fancy-prefix-map 14 | 15 | (transient-define-infix calc-transient-inverse () 16 | :key "I" 17 | :class transient-lisp-variable 18 | :prompt "Inverse.." 19 | :variable calc-option-flag 20 | :reader (lambda (&rest args) (interactive) 21 | (setq calc-option-flag (not calc-option-flag)))) 22 | 23 | (transient-define-infix calc-transient-hyperbolic () 24 | :key "H" 25 | :class transient-lisp-variable 26 | :prompt "Hyperbolic.." 27 | :variable calc-hyperbolic-flag 28 | :reader (lambda (&rest args) (interactive) 29 | (setq calc-hyperbolic-flag (not calc-hyperbolic-flag)))) 30 | 31 | ;; TODO Handle calc-total-algebraic-mode 32 | (transient-define-prefix calc-transient-modes () 33 | "Transient for calc modes" 34 | [["Input" 35 | ("a" "part algebraic" calc-algebraic-mode :transient t) 36 | ("t" "full algebraic" calc-total-algebraic-mode :transient t) 37 | ("S" "ignore case" calc-shift-prefix :transient t) 38 | 39 | "Calculation" 40 | ("s" "assume symb" calc-symbolic-mode :transient t) 41 | ;; ("\emt" 'calc-total-algebraic-mode) 42 | ;; ("\em\et" 'calc-total-algebraic-mode) 43 | ("v" "assume matrix" calc-matrix-mode :transient t) 44 | ("C" "auto-recompute" calc-auto-recompute :transient t) 45 | ("M" "recurse depth" calc-more-recursion-depth :transient t)] 46 | 47 | ["Simplify?" 48 | ("O" "no" calc-no-simplify-mode :transient t) 49 | ("N" "numbers only" calc-num-simplify-mode :transient t) 50 | ("I" "basic" calc-basic-simplify-mode :transient t) 51 | ("D" "default" calc-default-simplify-mode :transient t) 52 | ("B" "binary" calc-bin-simplify-mode :transient t) 53 | ("A" "standard" calc-alg-simplify-mode :transient t) 54 | ("E" "extended" calc-ext-simplify-mode :transient t) 55 | ("U" "units" calc-units-simplify-mode :transient t)] 56 | 57 | ["Display" 58 | ("f" "frac/float" calc-frac-mode :transient t) 59 | ("i" "infinities" calc-infinite-mode :transient t) 60 | ("w" "working" calc-working :transient t) 61 | ("p" "polar/rect" calc-polar-mode :transient t) 62 | 63 | "Angles" 64 | ("d" "degrees" calc-degrees-mode :transient t) 65 | ("r" "radians" calc-radians-mode :transient t) 66 | ("h" "deg-min-secs" calc-hms-mode :transient t)] 67 | 68 | ["State" 69 | ("m" "save" calc-save-modes :transient t) 70 | ("g" "load" calc-get-modes :transient t) 71 | ("x" "eager-load" calc-always-load-extensions :transient t) 72 | ("X" "load all" calc-load-everything :transient t) 73 | ("F" "Settings file" calc-settings-file-name :transient t) 74 | ("e" "save when embed" calc-embedded-preserve-modes 75 | :transient t 76 | :if (lambda () calc-embedded-info)) 77 | ("R" "record" calc-mode-record-mode :transient t)]]) 78 | 79 | 80 | 81 | (transient-define-prefix calc-transient () 82 | "Transient for calc." 83 | [:class transient-subgroups 84 | [:class transient-row 85 | ("x" "Find command" calc-execute-extended-command) 86 | ("t" "Trail" calc-transient-trail) 87 | ("j" "Select" calc-transient-select) 88 | ("i" "Info" calc-info) 89 | ("h" "Help..." calc-transient-help)] 90 | [:class transient-columns 91 | [("I" "Inverse.." calc-inverse) 92 | ("H" "Hyperbolic.." calc-hyperbolic)] 93 | [("U" "Undo" calc-undo) 94 | ("D" "ReDo" calc-redo)] 95 | [("d" "Display" calc-transient-display) 96 | ("s" "Store" calc-transient-store)] 97 | [("m" "Modes" calc-transient-modes) 98 | ("c" "Convert" calc-transient-convert)]]] 99 | 100 | [["Operate" 101 | ("S" "Sin" calc-sin) 102 | ("C" "Cos" calc-cos) 103 | ("T" "Tan" calc-tan) 104 | ("E" "Exp" calc-exp) 105 | ("L" "Ln" calc-ln) 106 | ("B" "Log" calc-log)] 107 | 108 | ["" 109 | ("N" "Eval num" calc-eval-num) 110 | ("n" "Negate" calc-change-sign) 111 | ("&" "Invert" calc-inv) 112 | ("F" "⌊Floor⌋" calc-floor) 113 | ("R" "Round" calc-round) 114 | ("A" "| Abs |" calc-abs)] 115 | 116 | ["" 117 | ("f" "functions" calc-transient-functions) 118 | ("J" "Conj⋆" calc-conj) 119 | ("%" "Modulo" calc-mod) 120 | ("!" "Factorial" calc-factorial) 121 | ("|" "Concat" calc-concat)] 122 | 123 | ["Commands" 124 | ("a" "Algebra" calc-transient-alg) 125 | ("b" "Binary/Business" calc-transient-binary/business) 126 | ("k" "Statistics" calc-transient-statistics) 127 | ("v" "Arrays" calc-transient-vector) 128 | ("u" "Units" calc-transient-units)] 129 | 130 | ["" 131 | ("t" "Time" calc-transient-trail) 132 | ("g" "Graphing" calc-transient-grahpics) 133 | ("p" "Precision" calc-precision) 134 | ("y" "Yank" calc-yank) 135 | ("w" "Why" calc-why) 136 | ("Z" "User" calc-transient-user)]]) 137 | 138 | 139 | (transient-define-prefix calc-transient-statistics () []) 140 | (transient-define-prefix calc-transient-binary/business () []) 141 | (transient-define-prefix calc-transient-convert () []) 142 | (transient-define-prefix calc-transient-store () []) 143 | (transient-define-prefix calc-transient-arrays () []) 144 | (transient-define-prefix calc-transient-functions () []) 145 | (transient-define-prefix calc-transient-grahpics () []) 146 | (transient-define-prefix calc-transient-help () []) 147 | (transient-define-prefix calc-transient-select () []) 148 | (transient-define-prefix calc-transient-user () []) 149 | 150 | ;; (setq calc-transient-alg-entries 151 | ;; (let ((entries-alist)) 152 | ;; (cl-loop for (key cmd heading) in calc-transient-alg-map 153 | ;; do 154 | ;; (let ((entry (alist-get heading entries-alist 155 | ;; nil nil 'equal))) 156 | ;; (setf (alist-get heading entries-alist nil nil 'equal) 157 | ;; (cons (list (substring key 1) 158 | ;; (substring (symbol-name cmd) 5) 159 | ;; cmd) 160 | ;; entry)) 161 | ;; (message "%s" key)) 162 | ;; finally return entries-alist))) 163 | 164 | ;; (defmacro calc-transient--make-prefix (prefix-name) 165 | ;; `(transient-define-prefix ,(intern (concat "calc-transient-" prefix-name)) 166 | ;; "calc transient" 167 | ;; [ 168 | ;; ,@(cl-loop for (heading . entries) in 169 | ;; (symbol-value (intern (concat "calc-transient-" prefix-name "-entries"))) 170 | ;; collect `[ ,heading ,@entries ]) 171 | ;; ])) 172 | 173 | ;; (calc-transient--make-prefix "alg") 174 | 175 | (transient-define-prefix calc-transient-alg () "calc transient" 176 | 177 | [:class transient-row 178 | ("M-x" "find command" calc-execute-extended-command) 179 | ("M-i" "open info" calc-info ) 180 | ("r" "rewrite" calc-rewrite)] 181 | [["Manipulate" 182 | ("b" "substitute" calc-substitute) 183 | ("s" "simplify" calc-simplify) 184 | ("e" "simplify-extended" calc-simplify-extended) 185 | ("c" "collect" calc-collect) 186 | ("f" "factor" calc-factor) 187 | ("x" "expand" calc-expand) 188 | ("A" "abs" calc-abs :level 5) 189 | ("v" "alg-evaluate" calc-alg-evaluate :level 5) 190 | ("n" "normalize-rat" calc-normalize-rat) 191 | ("a" "apart" calc-apart) 192 | ("/" "poly-div-rem" calc-poly-div-rem) 193 | ("%" "poly-rem" calc-poly-rem) 194 | ("\\" "poly-div" calc-poly-div) 195 | ("g" "poly-gcd" calc-poly-gcd) 196 | ] 197 | ["Calculus" 198 | ("d" "derivative" calc-derivative) 199 | ("i" "integral (symb)" calc-integral) 200 | ("I" "integral (numb)" calc-num-integral) 201 | ("t" "taylor" calc-taylor) 202 | 203 | "Solve" 204 | ("S" "solve (symb)" calc-solve-for) 205 | ("R" "solve (numb)" calc-find-root) 206 | ("P" "solve (poly)" calc-poly-roots) 207 | ("X" "maximize" calc-find-maximum) 208 | ("N" "minimize" calc-find-minimum) 209 | ("\"" "expand-formula" calc-expand-formula)] 210 | ["Map" 211 | ("+" " sum" calc-summation) 212 | ("-" "±sum" calc-alt-summation) 213 | ("*" "prod" calc-product) 214 | ("M" "map-equation" calc-map-equation) 215 | ("m" "match" calc-match) 216 | ("T" "tabulate" calc-tabulate) 217 | "Logical" 218 | (":" "if" calc-logical-if) 219 | ("!" "not" calc-logical-not) 220 | ("|" "or" calc-logical-or) 221 | ("&" "and" calc-logical-and)] 222 | ["Relation" 223 | ("{" "∈?" calc-in-set) 224 | (">" ">" calc-greater-than) 225 | ("<" "<" calc-less-than) 226 | ("]" "≥" calc-greater-equal) 227 | ("[" "≤" calc-less-equal) 228 | ("#" "≠" calc-not-equal-to) 229 | ("=" "=" calc-equal-to) 230 | ("." "remove =" calc-remove-equal) 231 | ("_" "subscript" calc-subscript) 232 | "Curve Fit" 233 | ("F" "curve-fit" calc-curve-fit) 234 | ("p" "poly-interp" calc-poly-interp)] 235 | ]) 236 | 237 | 238 | ;; TODO: Enable digits and minus as prefix-arguments in this (and other) 239 | ;; transients 240 | ;; TODO: Add I | and H | and I v h and H v t and H v k and H v h, I v s 241 | ;; H v l, I V S, I V G, H V H, H v e, b u, b p, bo, ba, bd, bx, bn 242 | ;; I v R, I v U, H v R, H v U 243 | (transient-define-prefix calc-transient-vector () 244 | "A transient for vector arithmetic in calc." 245 | 246 | [:class transient-row 247 | ("M-x" "find command" calc-execute-extended-command) 248 | ("M-i" "open info" calc-info ) 249 | ("r" "rewrite" calc-rewrite)] 250 | 251 | [["Stack" 252 | ("p" "pack" calc-pack) 253 | ("u" "unpack" calc-unpack) 254 | ("M-u" "unpackt" (lambda () (interactive) (calcFunc-unpackt)) :level 5) 255 | ("|" "concat" calc-concat) 256 | ("k" "kons" calc-cons) 257 | "Extract" 258 | ("r" "row" calc-mrow) 259 | ("c" "col" calc-mcol) 260 | ("h" "head" calc-head) 261 | ("M-t" "tail" calc-tail) 262 | ("_" "subscript" calc-subscript) 263 | ("s" "subvec" calc-subvector)] 264 | ["As Vector" 265 | ("l" "length" calc-vlength) 266 | ("f" "find" calc-vector-find) 267 | ("S" "sort" calc-sort) 268 | ("v" "reverse" calc-reverse-vector) 269 | ("m" "mask" calc-mask-vector) 270 | ("e" "expand" calc-expand-vector) 271 | "Build" 272 | ("b" "build" calc-build-vector) 273 | ("x" "indexed" calc-index) 274 | ("d" "diag" calc-diag) 275 | ("i" "identity" calc-ident)] 276 | 277 | ["As Matrix" 278 | ("t" "transpose" calc-transpose) 279 | ("&" "inverse" calc-inv) 280 | ("D" "determinant" calc-mdet) 281 | ("T" "trace" calc-mtrace) 282 | ("J" "conj trans" calc-conj-transpose) 283 | ("L" "LU factor" calc-mlud) 284 | ("a" "reshape" calc-arrange-vector) 285 | "Multiply" 286 | ("C" "cross prod" calc-cross) 287 | ("K" "kron prod" calc-kron) 288 | ("O" "outer prod" calc-outer-product) 289 | ("I" "inner prod" calc-inner-product)] 290 | 291 | ["As Set" 292 | ("+" "dedupe" calc-remove-duplicates) 293 | ("V" "union" calc-set-union) 294 | ("^" "intersect" calc-set-intersect) 295 | ("-" "difference" calc-set-difference) 296 | ("X" "XOR" calc-set-xor) 297 | ("~" "complement" calc-set-complement) 298 | ("F" "floor" calc-set-floor) 299 | ("E" "enumerate" calc-set-enumerate) 300 | (":" "to span" calc-set-span) 301 | ("#" "cardinality" calc-set-cardinality)] 302 | 303 | ["Norm" 304 | ("A" "frob norm" calc-abs) 305 | ("n" "row norm" calc-rnorm) 306 | ("N" "col norm" calc-cnorm) 307 | "Introspect" 308 | ("G" "grade" calc-grade) 309 | ("H" "histogram" calc-histogram) 310 | "Map/Reduce" 311 | ("A" "apply" calc-apply) 312 | ("M" "map.." calc-transient-vector-map) 313 | ("R" "reduce.." calc-transient-vector-reduce) 314 | ("U" "accumulate" calc-accumulate) 315 | ] 316 | 317 | ]) 318 | 319 | (transient-define-prefix calc-transient-vector-map () 320 | "Transient for mapping operations in calc" 321 | [("RET" "map" calc-map) 322 | ("_" "map by row" (lambda () (interactive) (calcFunc-mapr))) 323 | (":" "map by col" (lambda () (interactive) (calcFunc-mapc)))]) 324 | 325 | (transient-define-prefix calc-transient-vector-reduce () 326 | "Transient for reducing operations in calc" 327 | [("RET" "reduce" calc-reduce) 328 | ("_" "reduce each rows" (lambda () (interactive) (calcFunc-reducea))) 329 | (":" "reduce each cols" (lambda () (interactive) (calcFunc-reduced))) 330 | ("=" "reduce with rows" (lambda () (interactive) (calcFunc-reducer))) 331 | ("|" "reduce with cols" (lambda () (interactive) (calcFunc-reducec)))]) 332 | 333 | ;; TODO add calc-quick-units support for u-1 through u-0 334 | ;; TODO logarithmic units (info "(calc) Logarithmic Units") 335 | ;; TODO calc-vector-mean-error 'I u M' 336 | (transient-define-prefix calc-transient-units () 337 | "A transient for unit calculations in calc." 338 | [:class transient-row 339 | ("M-x" "find command" calc-execute-extended-command) 340 | ("M-i" "open info" calc-info ) 341 | ("r" "rewrite" calc-rewrite)] 342 | [:class transient-row 343 | ("I" "error.." calc-inverse) 344 | ("H" "median.." calc-hyperbolic)] 345 | [["Units" 346 | ("s" "simplify" calc-simplify-units) 347 | ("u" "convert" calc-convert-units) 348 | ("n" "convert exact" calc-convert-exact-units) 349 | ("b" "convert base" calc-base-units) 350 | ("t" "temperature" calc-convert-temperature) 351 | ("r" "remove units" calc-remove-units) 352 | ("x" "extract units" calc-extract-units)] 353 | ["" 354 | ("a" "autoranges" calc-autorange-units :transient t) 355 | ("v" "goto table" calc-enter-units-table) 356 | ("V" "view table" calc-view-units-table :transient t) 357 | ("g" "definition" calc-get-unit-definition) 358 | ("e" "explain" calc-explain-units) 359 | ("d" "define" calc-define-unit) 360 | ("u" "undefine" calc-undefine-unit) 361 | ("p" "permanent" calc-permanent-units)] 362 | ["Statistics" 363 | ("M" "arth mean" calc-vector-mean) 364 | ("G" "geom mean" calc-vector-geometric-mean) 365 | ("R" "rms" calc-vector-rms) 366 | ("S" "stdev" calc-vector-sdev) 367 | ("C" "covariance" calc-vector-covariance)] 368 | ["" 369 | ("#" "count" calc-vector-count) 370 | ("+" "∑ sum" calc-vector-sum) 371 | ("*" "∏ prod" calc-vector-product) 372 | ("X" "maximum" calc-vector-max) 373 | ("N" "minimum" calc-vector-min) 374 | ("F" "flatten" (lambda () (interactive) 375 | (calcFunc-vflat)))]]) 376 | 377 | (transient-define-prefix calc-transient-display () 378 | "A transient for display specification in calc." 379 | [:class transient-row 380 | ("M-x" "find command" calc-execute-extended-command) 381 | ("M-i" "open info" calc-info ) 382 | ("r" "rewrite" calc-rewrite)] 383 | [["Radix" 384 | ("r" "set" calc-radix) 385 | ("0" "decimal" calc-decimal-radix) 386 | ("2" "binary" calc-binary-radix) 387 | ("6" "hex" calc-hex-radix) 388 | ("8" "octal" calc-octal-radix) 389 | ("z" "leading zeros" calc-leading-zeros) 390 | "Group..." 391 | ("g" "group?" calc-group-digits) 392 | ("," "group char" calc-group-char) 393 | ("." "point char" calc-point-char)] 394 | ["Floating pt" 395 | ("n" "normal" calc-normal-notation) 396 | ("f" "fixed pt" calc-fix-notation) 397 | ("s" "scientific" calc-sci-notation) 398 | ("e" "engineering" calc-eng-notation) 399 | "Complex" 400 | ("i" "i notation" calc-i-notation) 401 | ("j" "j notation" calc-j-notation) 402 | ] 403 | [("o" "fraction char" calc-over-notation) 404 | ] 405 | ] 406 | ) 407 | 408 | (transient-define-prefix calc-transient-trail () 409 | "A transient for time and trail calculations in calc." 410 | [:class transient-row 411 | ("M-x" "find command" calc-execute-extended-command) 412 | ("M-i" "open info" calc-info ) 413 | ("r" "rewrite" calc-rewrite)] 414 | ["Convert Date" 415 | ("D" "to number" calc-date) 416 | ("J" "to Julian" calc-julian) 417 | ("U" "to Unix time" calc-unix-time) 418 | ("C" "to time zone" calc-convert-time-zones)] 419 | [["Insert Date" 420 | ("N" "Now" calc-now) 421 | ("Y" "Year" calc-new-year) 422 | ("M" "Month" calc-new-month) 423 | ("W" "Week" calc-new-week)] 424 | ["Extract Date" 425 | ("P" "part (with M-)" calc-date-part) 426 | "Manipulate Date" 427 | ("I" "Increment month" calc-inc-month) 428 | ("+" "Add business days" calc-business-days-plus) 429 | ("-" "Sub business days" calc-business-days-minus)] 430 | ]) 431 | 432 | 433 | (defvar calc-transient-mode-map 434 | (let ((map (make-sparse-keymap))) 435 | (define-key map "u" #'calc-transient-units) 436 | (define-key map "v" #'calc-transient-vector) 437 | (define-key map "a" #'calc-transient-alg) 438 | (define-key map (kbd "SPC") #'calc-transient) 439 | (define-key map (kbd "?") #'calc-transient) 440 | (define-key map (kbd "m") #'calc-transient-modes) 441 | map)) 442 | 443 | (define-minor-mode calc-transient-mode 444 | "Transient based UI for calc." 445 | :lighter nil 446 | :global nil 447 | (if calc-transient-mode 448 | (progn (unless (eq major-mode 'calc-mode) 449 | (user-err "Not in calc-mode!"))))) 450 | --------------------------------------------------------------------------------