Function: calc--header-line

calc--header-line is a byte-compiled function defined in calc.el.gz.

Signature

(calc--header-line LONG SHORT WIDTH &optional FUDGE)

Documentation

Return a Calc header line appropriate for the buffer WIDTH.

LONG is a desired text for a wide window, SHORT is a desired abbreviated text, and width is the buffer width, which will be some fraction of the "parent" window width (At the time of writing, 2/3 for calc, 1/3 for trail). The optional FUDGE is a trial-and-error adjustment number for the edge-cases at the border of the two cases.

Source Code

;; Defined in /usr/src/emacs/lisp/calc/calc.el.gz
(defun calc--header-line (long short width &optional fudge)
  "Return a Calc header line appropriate for the buffer WIDTH.

LONG is a desired text for a wide window, SHORT is a desired
abbreviated text, and width is the buffer width, which will be
some fraction of the \"parent\" window width (At the time of
writing, 2/3 for calc, 1/3 for trail).  The optional FUDGE is a
trial-and-error adjustment number for the edge-cases at the
border of the two cases."
  ;; TODO: This could be called as part of a 'window-resize' hook.
  (setq header-line-format
        (let* ((len-long (length long))
               (len-short (length short))
               (fudge (or fudge 0))
               ;; fudge for trail is: -3 (added to len-long)
               ;; (width  ) for trail
               (factor (if (> width (+ len-long fudge)) len-long len-short))
               (size   (max (/ (- width factor) 2) 0))
               (fill (make-string size ?-))
               (pre  (replace-regexp-in-string ".$" " " fill))
               (post (replace-regexp-in-string "^." " " fill)))
          (concat pre (if (= factor len-long) long short) post))))