From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Boruch Baum Newsgroups: gmane.emacs.bugs Subject: bug#43295: 26.1: calc-mode header line [UPDATED PATCH] Date: Wed, 9 Sep 2020 14:31:27 -0400 Message-ID: <20200909183127.oi3uhf6hmcswfkns@E15-2016.optimum.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="w2dkibdgue2bouxa" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1050"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: NeoMutt/20180716 To: 43295@debbugs.gnu.org, larsi@gnus.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 09 20:32:34 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kG4tW-0000BF-6j for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 09 Sep 2020 20:32:34 +0200 Original-Received: from localhost ([::1]:34350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kG4tT-0000xO-D1 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 09 Sep 2020 14:32:31 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kG4t0-0000vm-5V for bug-gnu-emacs@gnu.org; Wed, 09 Sep 2020 14:32:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51273) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kG4sz-000605-Sk for bug-gnu-emacs@gnu.org; Wed, 09 Sep 2020 14:32:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kG4sz-0004Yw-QK for bug-gnu-emacs@gnu.org; Wed, 09 Sep 2020 14:32:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Boruch Baum Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 09 Sep 2020 18:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 43295 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: Emacs Bug Reporting , Lars Ingebrigtsen Original-Received: via spool by submit@debbugs.gnu.org id=B.159967630017502 (code B ref -1); Wed, 09 Sep 2020 18:32:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 9 Sep 2020 18:31:40 +0000 Original-Received: from localhost ([127.0.0.1]:34584 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kG4sd-0004YD-GL for submit@debbugs.gnu.org; Wed, 09 Sep 2020 14:31:39 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:56448) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kG4sc-0004Y6-0L for submit@debbugs.gnu.org; Wed, 09 Sep 2020 14:31:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53302) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kG4sa-0000by-Lo for bug-gnu-emacs@gnu.org; Wed, 09 Sep 2020 14:31:37 -0400 Original-Received: from mout.gmx.net ([212.227.15.15]:50977) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kG4sW-0005xV-Is; Wed, 09 Sep 2020 14:31:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1599676290; bh=6sAdttMjrYd1mFayt+aYbFkcG9NpSrVLBcG7RTy4e/U=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject; b=jo4UFHMpGmimSPUwv0ZoVVARkjmwztYldTh+1qg39U9bX4zyZo0unh4zJeS7pT/df Y6krYR4odp42PZZyJcjFKXsk55CwVh+cK7jhMmc41EtBnqQBV0/yyXrTBCSz+5IeC2 2AoKJMzCmLnsiUCG6PAWJexRIz4uL1o++sFaW27s= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from E15-2016.optimum.net ([72.89.170.172]) by mail.gmx.com (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1N6sn7-1kbSUo3Wdb-018KTy; Wed, 09 Sep 2020 20:31:30 +0200 Content-Disposition: inline X-Provags-ID: V03:K1:C3Z9KrkUkldJ5WMRO7WvkGdvORnS2gtOURXYlMZUYl1IKRAFhA3 1DHdRpzQpBo7y+f69NYKuaP0VqmTvQnFWDlhmwstbpL5aAeT4UhS3EI8p6/Z7h/JBPtQYm9 znRhFXFhKC2cqrlyBqjg/eAnocUAcB/fXyVjqGe7GG0CoG7JQCLlqh2aH856efj9IGJ37Ik Nh1WhmBLPnur8UdMGDEJQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:H4QSbhG3gZ8=:NpphSbt/nVPDeDd/ryYCF3 6BfyKu/o6ok50oQw26dzJfMQo9111SEXdhCRyN1fmDsNsMadpmlNJqRpuDWUX8w5oA1qEWVYx jRZGYq8/h82Yd9xFXohMlUECSKV1N9GByu946rxvTc1ce0l0EyrYiuko7kBS0sz7ZAB6SPgjc OkiT3IYny4ufJ+WqIuGUFmBwzw7xZFXflSN7Jo5lJ6nnjKZkCJSRb+c8GD04yYmSAHyNrzF6V +bHxdl+OUfWHIdWSz239QXLkawd0EYoGoXqOO0m7/pipiSG58Ck6e41XIV35gmzakpnmfxMEO Fq9wF3Cvx3/tv/A3XL3zuS0YOp0QePRRh6rvhEs6WpZYK5rEQscZ6z3JlPKE9bmJvPceSXekc FfVyItA2gICx7jysNdklzHrzmCgT/Z25UPGS9tHAG5mGqSgX3IdxMsad5lnuwi/gHyWHTAjPQ A0SoOvw5NrUvWvs8UGoCrLHb8ARp3SL5MbTx+GZJbNEGuKLLVoT1zJHIQDK6ITRZ6khi1ouVt VDejUC2STjwdECRhbOmrwIBdmpZ1RpAG1WfdP7+NpqwhpOwhRjPItwZEjMfzQo66zg8MQ64lj 3y3hODpIvVsZ8uUBVqWcHZC6CFkuFDE50TQeyl5wSplG2q+ah1yfGZ6NrefenJLEmDpR1Wiyb VdS/mfNDZWBqAODxq6LDWKWacHALCXMIyHyB2dex/0FMNVWvFb0MXvthgNf0aWTulw43jQcat 18LcHF28qZ+PJE4hwckIl+YBQRMxuq0hdK5EzIWSBnSzf9JRVjapZG+mQ+uDEB6zblisNA8o Received-SPF: pass client-ip=212.227.15.15; envelope-from=boruch_baum@gmx.com; helo=mout.gmx.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/09 13:38:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:187691 Archived-At: --w2dkibdgue2bouxa Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable This is summary of related mail on emacs-devel (an updated patch is attach= ed): On 2020-08-31 14:44, Boruch Baum wrote: > Back in version 21, emacs introduced a static 'header-line' that could > be inserted at the top of any buffer. Calc mode is one emacs package > that does not use it and could benefit from it, so the attached patch > offers that feature. The main benefit is that the 'calc trail' buffer > (what some greybeards from the mechanical age would remember as the > 'tape reel') no longer has its title line scroll off the visible > window. The patch also includes: > > 1) Width-sensitive text for the header line, so that it is readable for > very narrow windows, and scales to very wide windows. > > 2) Display of the 'calc trail' buffer when invoking calc from a frame > that is split vertically (C-x 3, M-x split-window-right). > > 3) My version of emacs includes a unicode character at 'C-x 8 > POCKET CALCULATOR', that I did not include in the header line as the > mode's icon, but that could be done. > > The patch was diff'ed against the version of emacs that I have: the > latest-and-greatest that debian is distributing ... v26.1 On 2020-09-07 14:01, Boruch Baum wrote: > First, congratulations on assuming your new responsibilities. > > On 2020-09-07 17:00, Lars Ingebrigtsen wrote: > > The patch doesn't apply to Emacs 28, so I've respun it (included below= ). > > Oops. I didn't think there would be a difference. I'm using emacs 26.1 > in debian and I didn't download the v28 calc.el > > > 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. =2D- hkp://keys.gnupg.net CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0 --w2dkibdgue2bouxa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="calc.patch" Content-Transfer-Encoding: quoted-printable =2D-- calc.el 2020-08-30 15:03:07.563840474 -0400 +++ calc-new.el 2020-09-09 14:12:01.949816446 -0400 @@ -1396,6 +1396,31 @@ (set-keymap-parent map calc-mode-map) map)) +(defun calc--header-line (long short width &optional fudge) + "Return a Calc header line appropriate for the buffer width. + +This is an internal function for `calc-mode'. + +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 'wiindow-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 (/ (- width factor) 2)) + (fill (make-string size ?-)) + (pre (replace-regexp-in-string ".$" " " fill)) + (post (replace-regexp-in-string "^." " " fill))) + (concat pre (if (=3D factor len-long) long short) post)))) + (define-derived-mode calc-trail-mode fundamental-mode "Calc Trail" "Calc Trail mode. This mode is used by the *Calc Trail* buffer, which records all results @@ -1410,21 +1435,27 @@ (setq buffer-read-only t) (make-local-variable 'overlay-arrow-position) (make-local-variable 'overlay-arrow-string) - (when (=3D (buffer-size) 0) + (if (and (not calc-show-banner) + (=3D (buffer-size) 0)) (let ((buffer-read-only nil)) - (insert (propertize "Emacs Calculator Trail\n" 'face 'italic))))) + (insert (propertize "Emacs Calculator Trail\n" 'face 'italic))) + (calc--header-line "Emacs Calculator Trail" "Calc Trail" + (/ (window-width) 3) -3))) (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 + (calc--header-line "Emacs Calculator Mode" "Emacs Calc" + (/ (* (window-width) 2) 3) 1) (setq max-lisp-eval-depth (max max-lisp-eval-depth 1000)) (when calc-always-load-extensions (require 'calc-ext)) (when calc-language (require 'calc-ext) - (calc-set-language calc-language calc-language-option t))) + (calc-set-language calc-language calc-language-option t)))) ;;;###autoload (defun calc (&optional arg full-display interactive) @@ -1465,7 +1496,6 @@ (pop-to-buffer (current-buffer))))))) (with-current-buffer (calc-trail-buffer) (and calc-display-trail - (=3D (window-width) (frame-width)) (calc-trail-display 1 t))) (message "Welcome to the GNU Emacs Calculator! Press `?' or `h' fo= r help, `q' to quit") (run-hooks 'calc-start-hook) @@ -2000,13 +2030,8 @@ (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) @@ -2091,7 +2116,6 @@ (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) @@ -2159,10 +2183,8 @@ (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)) @@ -2176,7 +2198,7 @@ (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) --w2dkibdgue2bouxa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="NEWS.patch" Content-Transfer-Encoding: quoted-printable =2D-- NEWS 2020-09-05 22:28:48.607653342 -0400 +++ NEWS.new 2020-09-06 14:37:38.286349012 -0400 @@ -921,6 +921,14 @@ Likewise, point isn't moved to the end of the string before inserting digits. +--- +*** Buffer headings have been changed. +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. + ** term-mode --- --w2dkibdgue2bouxa--