From: Lars Ingebrigtsen <larsi@gnus.org>
To: Boruch Baum <boruch_baum@gmx.com>
Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
Subject: Re: 26.1: calc-mode header line [PATCH]
Date: Mon, 07 Sep 2020 17:00:29 +0200 [thread overview]
Message-ID: <87sgbt7hte.fsf@gnus.org> (raw)
In-Reply-To: <20200906184529.srcmx42ircaeueqv@E15-2016.optimum.net> (Boruch Baum's message of "Sun, 6 Sep 2020 14:45:30 -0400")
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
next prev parent reply other threads:[~2020-09-07 15:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-31 18:44 26.1: calc-mode header line [PATCH] Boruch Baum
2020-09-05 6:57 ` Eli Zaretskii
2020-09-06 2:35 ` Boruch Baum
2020-09-06 14:17 ` Eli Zaretskii
2020-09-06 18:45 ` Boruch Baum
2020-09-07 15:00 ` Lars Ingebrigtsen [this message]
2020-09-07 18:01 ` Boruch Baum
2020-09-07 20:24 ` Lars Ingebrigtsen
2020-09-07 21:11 ` Boruch Baum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sgbt7hte.fsf@gnus.org \
--to=larsi@gnus.org \
--cc=boruch_baum@gmx.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).