[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 26.1: calc-mode header line [PATCH]
From: |
Lars Ingebrigtsen |
Subject: |
Re: 26.1: calc-mode header line [PATCH] |
Date: |
Mon, 07 Sep 2020 17:00:29 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Boruch Baum <boruch_baum@gmx.com> writes:
> +The *Calc* and *Calc Trail* buffers now use 'header-line-format' to
> +present a persistent buffer header line, and they are sized based upon
> +the window width upon launch. The header-line for the *Calc Trail*
> +buffer is no longer part of the buffer's text and no longer scrolls
> +off the visible display, unless on sets 'calc-show-banner' to NIL.
The patch doesn't apply to Emacs 28, so I've respun it (included below).
The result looks nice, but one comment:
+ (setq header-line-format
+ (let* ((fract (/ (* (window-width) 2) 3))
+ (factor (if (> fract 22) 21 10))
+ (size (/ (- fract factor) 2))
+ (fill (make-string size ?-))
+ (pre (replace-regexp-in-string ".$" " " fill))
+ (post (replace-regexp-in-string "^." " " fill)))
+ (concat pre
+ (if (= factor 21) "Emacs Calculator Mode" "Emacs Calc")
+ post))))
This is somewhat inscrutable, and is repeated twice (once for the calc
buffer and once for the trail buffer).
It just centres whatever the string like "--- this ---", so it seems
like it should land in a single function for reuse.
diff --git a/lisp/calc/calc.el b/lisp/calc/calc.el
index fb1287baaa..2688ca14a4 100644
--- a/lisp/calc/calc.el
+++ b/lisp/calc/calc.el
@@ -1396,15 +1396,37 @@ calc-trail-mode
(setq buffer-read-only t)
(make-local-variable 'overlay-arrow-position)
(make-local-variable 'overlay-arrow-string)
- (when (= (buffer-size) 0)
- (let ((inhibit-read-only t))
- (insert (propertize "Emacs Calculator Trail\n" 'face 'italic)))))
+ (if (and (not calc-show-banner)
+ (= (buffer-size) 0))
+ (let ((inhibit-read-only t))
+ (insert (propertize "Emacs Calculator Trail\n" 'face 'italic)))
+ (setq header-line-format
+ (let* ((fract (/ (window-width) 3))
+ (factor (if (> fract 19) 22 10))
+ (size (/ (- fract factor) 2))
+ (fill (make-string size ?-))
+ (pre (replace-regexp-in-string ".$" " " fill))
+ (post (replace-regexp-in-string "^." " " fill)))
+ (concat pre
+ (if (= factor 22) "Emacs Calculator Trail" "Calc Trail")
+ post)))))
(defun calc-create-buffer ()
"Create and initialize a buffer for the Calculator."
(set-buffer (get-buffer-create "*Calculator*"))
(or (derived-mode-p 'calc-mode)
(calc-mode))
+ (when calc-show-banner
+ (setq header-line-format
+ (let* ((fract (/ (* (window-width) 2) 3))
+ (factor (if (> fract 22) 21 10))
+ (size (/ (- fract factor) 2))
+ (fill (make-string size ?-))
+ (pre (replace-regexp-in-string ".$" " " fill))
+ (post (replace-regexp-in-string "^." " " fill)))
+ (concat pre
+ (if (= factor 21) "Emacs Calculator Mode" "Emacs Calc")
+ post))))
(setq max-lisp-eval-depth (max max-lisp-eval-depth 1000))
(when calc-always-load-extensions
(require 'calc-ext))
@@ -1451,7 +1473,6 @@ calc
(pop-to-buffer (current-buffer)))))))
(with-current-buffer (calc-trail-buffer)
(and calc-display-trail
- (= (window-width) (frame-width))
(calc-trail-display 1 t)))
(message "Welcome to the GNU Emacs Calculator! Press `?' or `h' for
help, `q' to quit")
(run-hooks 'calc-start-hook)
@@ -1986,13 +2007,8 @@ calc-refresh
(calc-any-evaltos nil))
(setq calc-any-selections nil)
(erase-buffer)
- (when calc-show-banner
- (insert (propertize "--- Emacs Calculator Mode ---\n"
- 'face 'italic)))
(while thing
(goto-char (point-min))
- (when calc-show-banner
- (forward-line 1))
(insert (math-format-stack-value (car thing)) "\n")
(setq thing (cdr thing)))
(calc-renumber-stack)
@@ -2076,7 +2092,6 @@ calc-trail-buffer
(eq (marker-buffer calc-trail-pointer) calc-trail-buffer))
(with-current-buffer calc-trail-buffer
(goto-char (point-min))
- (forward-line 1)
(setq calc-trail-pointer (point-marker))))
calc-trail-buffer)
@@ -2144,10 +2159,8 @@ calc-trail-here
(if (derived-mode-p 'calc-trail-mode)
(progn
(beginning-of-line)
- (if (bobp)
- (forward-line 1)
(if (eobp)
- (forward-line -1)))
+ (forward-line -1))
(if (or (bobp) (eobp))
(setq overlay-arrow-position nil) ; trail is empty
(set-marker calc-trail-pointer (point) (current-buffer))
@@ -2161,7 +2174,7 @@ calc-trail-here
(if win
(save-excursion
(forward-line (/ (window-height win) 2))
- (forward-line (- 1 (window-height win)))
+ (forward-line (- 2 (window-height win)))
(set-window-start win (point))
(set-window-point win (+ calc-trail-pointer 4))
(set-buffer calc-main-buffer)
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no