Is there some extension that can make calc autocomplete units while value entered as algebraic input? e.g.

' 1 kn<tab>

should be completed to "1 knot".

  • I very much doubt it, but it's an interesting idea, and, probably not too difficult to implement...
    – wvxvw
    Oct 23, 2015 at 9:16
  • @gordon-quad I have never used calc for stuff that would need units. Can you update the question with an example where you would want the auto-completion to happen? Oct 23, 2015 at 12:57
  • well, as I understnand units are just variables, so I can reformulate question "Is there autocompletion for variable names?" Oct 23, 2015 at 15:00
  • Perhaps, abbrev or yas-snippet work fine. I personally (and frequently) use yas-snippet to write elements into 3x3 matrices. (if it's in the calc-edit with '`)
    – Garid
    Mar 16, 2023 at 19:13

2 Answers 2


Most unit descriptions in calc are usually very short. You will find them when typing u v. In my opinion a completion is here unnecessary, just type a ' (e. g. after typing a number) and specify your unit together with the quantity in algebraic mode.

  • 1
    I want to convert database which is provided with "units" calculator so there can be quite long names, like 'solarmass' or 'solarluminosity' Oct 23, 2015 at 14:58
  • @gordon-quad: I don't understand your use case. Could you please show this "database"? Oct 24, 2015 at 16:54
  • no problem. Here is url of calculator: gnu.org/software/units/units.html here is example of database: github.com/ryantenney/gnu-units/blob/master/units.dat Convertion of this db to calc units is matter of simple sed script (maybe throwing away some invalid for ecalc stuff like unicode units or functions) and as you can see it has pretty long unit names and constants. Oct 24, 2015 at 17:47

This is Emacs. So the answer to such questions is almost always "yes".

The extension (not as a package but as code):

(require 'calc)
(require 'calc-aent)
(require 'calc-units)

(defun calc-do-alg-entry-completion (fun &rest args)
  "Call `calc-do-alg-entry' as FUN with ARGS.
Wrapp FUN with `minibuffer-completion-table' bound
to a completion table of calc-units and variables."
  ;; make sure that newly introduced units
  ;; and variables are completed:
  (let ((minibuffer-completion-table
       (lambda (unit)
         (setq unit (symbol-name (car unit))))
      (let (ret)
         (lambda (var)
           (let ((var-name (symbol-name var)))
         (when (string-match "\\`var-\\(.*\\)\\'" var-name)
           (push (match-string 1 var-name) ret))))
    (apply fun args)))

(defun calc-aent-complete-word ()
  "Complete word at point with entries from `minibuffer-completion-table'."
  (when-let ((word-bounds (bounds-of-thing-at-point 'word)))
    (completion-in-region (car word-bounds) (cdr word-bounds) minibuffer-completion-table)))

(define-key calc-alg-ent-map "\C-i" #'calc-aent-complete-word)

(advice-add 'calc-do-alg-entry :around #'calc-do-alg-entry-completion)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.