From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: mark M Newsgroups: gmane.emacs.devel Subject: Re: mode-line size and position indicator Date: Thu, 24 Aug 2017 14:02:06 -0700 Message-ID: <1c95c0be-e1c0-4361-a75e-8c659ef3a64e@marks-iPhone-6s-gold> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="599f3ece_74b0dc51_255" X-Trace: blaine.gmane.org 1503608585 10413 195.159.176.226 (24 Aug 2017 21:03:05 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 24 Aug 2017 21:03:05 +0000 (UTC) Cc: Eli Zaretskii , Nick Helm , Emacs developers To: John Yates Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Aug 24 23:02:59 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dkzHE-0002AK-0d for ged-emacs-devel@m.gmane.org; Thu, 24 Aug 2017 23:02:56 +0200 Original-Received: from localhost ([::1]:50499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkzHK-0007oB-TT for ged-emacs-devel@m.gmane.org; Thu, 24 Aug 2017 17:03:02 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkzGZ-0007k9-0O for emacs-devel@gnu.org; Thu, 24 Aug 2017 17:02:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkzGX-0008Ld-Gs for emacs-devel@gnu.org; Thu, 24 Aug 2017 17:02:15 -0400 Original-Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:34039) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dkzGU-0008Iw-Mx; Thu, 24 Aug 2017 17:02:10 -0400 Original-Received: by mail-pg0-x241.google.com with SMTP id 63so899559pgc.1; Thu, 24 Aug 2017 14:02:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:message-id:subject:mime-version; bh=rq/J+KO2zWhElK9rjO2oNfwaF5uzoGmX9Cne3o7k2kw=; b=Xzv6lrJTqiBdymlprtGNR3YJykimZOQrlbxbS1fTVUyiJZ7X640aWzAQjPbF6RJaKH ToW4ofwK5yESNPJMOCNOhiKwY/0OsQ1cCKE8SrygOZla9g/ZXkxaWSK/jG7cE3usf+o1 7qOxmbAjWTOzshZCu6EbB/AhYrxWbWP8oGeOGJFdBUIQTqZh9ys4iBI8031BlndyzOsX uWD6NRDfWd5PK2zNGO+B0/hMnGJI12TA4gPzkYYUggVLHnZd0dP/jCTSweTQhKie2RDT p4qMb32wyuwm6iUu87vq+jAtBS2Sy+UozDsZXzucbPiyYXE746JVYrvY+Dlx/aKgTd5h 5gIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:message-id:subject:mime-version; bh=rq/J+KO2zWhElK9rjO2oNfwaF5uzoGmX9Cne3o7k2kw=; b=Pw3b+GhUxxNEMveTa7G7mKeW/kTnP9IK4Kf9gAZ00fynLKIwLzazZPuFMRFyk+BDG5 Pjswqj0WIcv9uzblx+44D7WUKpORkOD/NG5s0czvbJiEGkbGmfbiwunxmWg+EH5UGZFE Rb1zRt7AxErdoyshBVRpYFKJlB92ORjXjyQMo2nkQJs6xN6Dx9EMDrN9t0PwOss9YwjE eZtCgF81iG3ewU6uB8RKciOmeZjYTizZu6PG+GJMvjjF7cXajWF7E5HRcsIa05kPl4bL e8uRNcWPPSn+fdaua4vqR4VIRwG9sv2XdESlLcRO6e2utiYSlPsRYbfWaJLkL2+QjQkq wc0A== X-Gm-Message-State: AHYfb5jhwu1LiEaL7B7caWMn2ZDFAmdlhz4mv+ZoXev6rgViYmQnZJa1 Kp7AfeMJTtUWlLS1AUU= X-Received: by 10.84.224.203 with SMTP id k11mr8159586pln.231.1503608528146; Thu, 24 Aug 2017 14:02:08 -0700 (PDT) Original-Received: from [2602:304:b198:9460::] ([2602:304:b198:9460:c1cb:fb7:9a12:d44a]) by smtp.gmail.com with ESMTPSA id 66sm8745084pfq.20.2017.08.24.14.02.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Aug 2017 14:02:07 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::241 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:217787 Archived-At: --599f3ece_74b0dc51_255 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Both Aquamacs and Emacs The latest version have started flickering quite a bit on opening any latex document with color or tables or formatting > > On Aug 24, 2017 at 12:26 PM, wrote: > > > > On Thu, Aug 24, 2017 at 12:55 PM, Eli Zaretskii wrote: > > Looks good, although there's a fundamental problem with putting on the > mode line an indicator that must use a significant part of the screen > estate to be useful: the mode line is pretty crowded these days, even > in the default configuration. After a futile effort at IBM to obtain an FSF copyright assignment I have given up and been too lazy to restart the effort with my new employer. Hence my .emacs (https://github.com/jsyjr/MyConfiguration.git ) is in the public domain. A couple months back I posted a mode-line widget that I have been using for some number of years. The relevant code is appended at the end of this message. Notable behavior: * Overlays proportional view of window in buffer onto line/column widget * Supports the same mouse menu behavior as the original widget * Highlights left edge square bracket if BOB is visible * Highlights right edge square bracket if EOB is visible * Hysteresis to minimi ze mode-line jitter This solution does not use any more mode-line real estate than the current line/column widget. . . . > I wonder whether it would have made sense to reuse the code we have > for computing the scroll-bar thumb. I am an inexperienced elisp hacker so I doubt that there is anything particularly useful or novel in my code. As the comments mention I was much inspired by past email discussions. The hardest part I found was the logic corresponding to Eli's scroll-bar thumb logic. I would love it if emacs offered essentially this functionality OOTB. /john ;;{{{ mode-line position-widget ;; Use a fancy widget to display buffer position on the mode line. ;; ------------------------------------------------------------------- ;; ;; Initial inspiration from an email thread between David Engster's and ;; Drew Adams: ;; ;; http://lists.gnu.org/archive/html/emacs-devel/2010-03/msg00523.html ;; http://permalink.gmane.org/gmane.emacs.devel/122038 ;; ;; Further learnings from Lenn art Borgman's sml-modeline.el ;; https://www.emacswiki.org/emacs/sml-modeline.el ;; ;; TODO: Change color if cursor exceeds limit column (defvar buffer-max-column-visited 1 "Accumulate max column visited to prevent mode-line jitter.") (make-variable-buffer-local 'buffer-max-column-visited) (defun my/position-widget () (let* ((c-n-m column-number-mode) (l-n-m line-number-mode) (wbeg (window-start)) (wend (window-end))) (save-restriction (widen) (let* ((eob-line (line-number-at-pos (point-max))) (wbeg-line (line-number-at-pos wbeg)) (wend-line (line-number-at-pos wend)) (widget (concat ;; Leading [ (if (= wbeg-line 1) #("[" 0 1 (face mode-line-highlight-bold)) "[") ;; Body (if (not (or l-n-m c-n-m)) (replace-regexp-in-string "%" "%%" (format-mode-line '(-3 "%P"))) (let* ((wlines (1+ (- wend- line wbeg-line))) (expanded (format-mode-line (concat (cond ((not l-n-m) "") ((> 10 eob-line) "%1l") ((> 100 eob-line) "%2l") ((> 1000 eob-line) "%3l") ((> 10000 eob-line) "%4l") ((> 100000 e ob-line) "%5l") ((> 1000000 eob-line) "%6l") (t "%7l")) (if (and l-n-m c-n-m) #("," 0 1 (face bold)) "") (cond ((not c-n-m) "") (t (let* ((max-col (max (current-column) buffer-max-column-visited)) (field (cond ((> 10 max-col) 3) ((> 100 max-col) 4) ((> 1000 max-col) 5) (t 6))) (cur-col (current-column)) (digits (cond ((> 10 cur-col) 1) ((> 100 cur-col) 2) ((> 1000 cur-col) 3) (t 4)))) (setq buffer-max-column-visited max-col) (substring "%c " 0 (- field digits)))))))) (len (length expanded)) (hilen (max 1 ; at least one column (min len ; no more than full string (round (/ (* wlines len) (float eob-line)))))) (lpad (round (/ (* wbeg-line (- len hilen)) (float (- eob-line wlines -2))))) (rpad (+ lpad hilen))) (put-text-property lpad rpad 'face 'mode-line-highlight expanded) expanded)) ;; Trailing ] (if (= wend-line eob-line) #("]" 0 1 (face mode-line-highlight-bold)) "]")))) (propertize widget 'help-echo "Buffer position widget\nmouse-1: Line and Column Mode Menu" 'mouse-face 'mo de-line-highlight 'local-map '(keymap (mode-line keymap (down-mouse-1 keymap (line-number-mode menu-item "Global Line Number Mode" line-number-mode :help "Toggle line number display" :button (:toggle . line-number-mode)) (column-number-mode menu-item "Global Column Number Mode" column-number-mode :help "Toggle column number display" :button (:toggle . column-number-mode)) "Control Line and Column Display Globally")))))))) (my/custom-set-variables '(mode-line-position '(:eval (my/position-widget)) t) ) ;;}}} > > --599f3ece_74b0dc51_255 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Both Aquamacs and Emac= s The latest version have started flickering quite a bit on opening any l= atex document with color or tables or formatting 


On Aug 24, 2017 at 12:26 PM, <John Yates> wrote:

=
On Thu, Aug 24, 2017 at 12:55 PM, Eli Zaretskii  wrote:
>
> Looks good, although there's a fundamental problem with putting on t=
he
> mode line an indicator that must use a significant part of the scree=
n
> estate to be useful: the mode line is pretty crowded these days, eve=
n
> in the default configuration.

After a futile effort at IBM to obtain an =46S=46 copyright assignment I =
have
given up and been too lazy to restart the effort with my new employer.
Hence my .emacs (https://github.com/jsyjr/MyConfiguration.git ) is in
the public domain.

A couple months back I posted a mode-line widget that I have been
using for some number of years.  The relevant code is appended at
the end of this message.  Notable behavior:

* Overlays proportional view of window in buffer onto line/column widget
* Supports the same mouse menu behavior as the original widget
* Highlights left edge square bracket if BOB is visible
* Highlights right edge square bracket if EOB is visible
* Hysteresis to minimize mode-line jitter

This solution does not use any more mode-line real estate than the
current line/column widget.

. . .
> I wonder whether it would have made sense to reuse the code we have
> for computing the scroll-bar thumb.

I am an inexperienced elisp hacker so I doubt that there is anything
particularly useful or novel in my code.  As the comments mention I
was much inspired by past email discussions.  The hardest part I found
was the logic corresponding to Eli's scroll-bar thumb logic.

I would love it if emacs offered essentially this functionality OOTB.

/john



;;=7B=7B=7B  mode-line position-widget

;; Use a fancy widget to display buffer position on the mode line.
;; -------------------------------------------------------------------
;;
;; Initial inspiration from an email thread between David Engster's and
;; Drew Adams:
;;
;;   http://lists.gnu.org/archive/html/emacs-devel/2010-03/msg00523.html
;;   http://permalink.gmane.org/gmane.emacs.devel/122038
;;
;; =46urther learnings from Lennart Borgman's sml-modeline.el
;;   https://www.emacswiki.org/emacs/sml-modeline.el
;;
;; TODO: Change color if cursor exceeds limit column

(defvar buffer-max-column-visited 1
  =22Accumulate max column visited to prevent mode-line jitter.=22)
(make-variable-buffer-local 'buffer-max-column-visited)

(defun my/position-widget ()
  (let*
      ((c-n-m column-number-mode)
       (l-n-m line-number-mode)
       (wbeg (window-start))
       (wend (window-end)))

    (save-restriction
      (widen)

      (let*
          ((eob-line  (line-number-at-pos (point-max)))
           (wbeg-line (line-number-at-pos wbeg))
           (wend-line (line-number-at-pos wend))

           (widget
            (concat
             ;; Leading =5B
             (if (=3D wbeg-line 1)
                 =23(=22=5B=22 0 1 (face mode-line-highlight-bold))
               =22=5B=22)
             ;; Body
             (if (not (or l-n-m c-n-m))
                 (replace-regexp-in-string =22%=22 =22%%=22 (format-mode-=
line
'(-3 =22%P=22)))
               (let*
                   ((wlines (1+ (- wend-line wbeg-line)))
                    (expanded
                     (format-mode-line
                      (concat
                       (cond
                        ((not l-n-m) =22=22)
                        ((> 10      eob-line) =22%1l=22)
                        ((> 100     eob-line) =22%2l=22)
                        ((> 1000    eob-line) =22%3l=22)
                        ((> 10000   eob-line) =22%4l=22)
                        ((> 100000  eob-line) =22%5l=22)
                        ((> 1000000 eob-line) =22%6l=22)
                        (t                    =22%7l=22))
                       (if (and l-n-m c-n-m) =23(=22,=22 0 1  (face bold)=
) =22=22)
                       (cond
                        ((not c-n-m) =22=22)
                        (t (let*
                               ((max-col (max (current-column)
                                              buffer-max-column-visited))=

                                (field   (cond
                                          ((> 10   max-col) 3)
                                          ((> 100  max-col) 4)
                                          ((> 1000 max-col) 5)
                                          (t                6)))
                                (cur-col (current-column))
                                (digits  (cond
                                          ((> 10   cur-col) 1)
                                          ((> 100  cur-col) 2)
                                          ((> 1000 cur-col) 3)
                                          (t                4))))
                             (setq buffer-max-column-visited max-col)
                             (substring =22%c     =22 0 (- field digits))=
))))))

                    (len (length expanded))
                    (hilen (max 1           ; at least one column
                                (min len    ; no more than full string
                                     (round (/ (* wlines len)
                                               (float eob-line))))))
                    (lpad (round (/ (* wbeg-line (- len hilen))
                                    (float (- eob-line wlines -2)))))
                    (rpad (+ lpad hilen)))

                 (put-text-property lpad rpad 'face
'mode-line-highlight expanded)
                 expanded))
             ;; Trailing =5D
             (if (=3D wend-line eob-line)
                 =23(=22=5D=22 0 1 (face mode-line-highlight-bold))
               =22=5D=22))))

        (propertize
         widget
         'help-echo =22Buffer position widget=5Cnmouse-1: Line and Column=
 Mode Menu=22
         'mouse-face 'mode-line-highlight
         'local-map '(keymap
                      (mode-line
                       keymap
                       (down-mouse-1
                        keymap
                        (line-number-mode
                         menu-item =22Global Line Number Mode=22 line-num=
ber-mode
                         :help =22Toggle line number display=22
                         :button (:toggle . line-number-mode))
                        (column-number-mode
                         menu-item =22Global Column Number Mode=22
column-number-mode
                         :help =22Toggle column number display=22
                         :button (:toggle . column-number-mode))
                        =22Control Line and Column Display Globally=22)))=
)))))

(my/custom-set-variables
 '(mode-line-position '(:eval (my/position-widget)) t)
 )

;;=7D=7D=7D

--599f3ece_74b0dc51_255--