unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Lennart Borgman <lennart.borgman@gmail.com>
To: Drew Adams <drew.adams@oracle.com>
Cc: emacs-devel@gnu.org, "Zhu, Shenli" <zhushenli2@gmail.com>
Subject: Re: scrollbar alternative
Date: Tue, 16 Mar 2010 13:44:50 +0100	[thread overview]
Message-ID: <e01d8a51003160544y4b19cd54m13939b7d129f8418@mail.gmail.com> (raw)
In-Reply-To: <CEA3CA7D2FE3406D869DB130CB9B2D4C@us.oracle.com>

[-- Attachment #1: Type: text/plain, Size: 1019 bytes --]

On Tue, Mar 16, 2010 at 5:34 AM, Drew Adams <drew.adams@oracle.com> wrote:
>> I tried to copy your code to my .emacs file, but my mode bar
>> doesn't change like yours. Shall I change something else?
>
> If your window is not wide enough, it might actually be "showing", but off to
> the right, too far for you to see (outside the window).  The mode line can be
> truncated at the right, depending on the window width. If you make your window
> wider, you might see the indicator.
>
> (That explanation doesn't apply if your Emacs version is 21 - in that case, the
> indicator appears just after the buffer name.)
>
> Try this (same code, just tweaked a bit, mainly to avoid wrapping by my mailer).
> The last line here moves the indicator to where the size indicator normally is,
> just after the buffer name, so you should be able to see it OK.


I like the feature. I think something like this should be in Emacs.

Attached is a little bit more elaborated version. Name suggestions are welcome.

[-- Attachment #2: sml-modeline.el --]
[-- Type: text/plain, Size: 4756 bytes --]

;;; sml-modeline.el --- Show position in a scrollbar like way in mode-line
;;
;; Author: Lennart Borgman (lennart O borgman A gmail O com)
;; Created: 2010-03-16 Tue
;; Version:
;; Last-Updated:
;; URL:
;; Keywords:
;; Compatibility:
;;
;; Features that might be required by this library:
;;
;;   None
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; Show scrollbar like position indicator in mode line.
;;
;; Idea and part of this code is adapted from Drew Adam's code in this
;; mail message:
;;
;;   http://permalink.gmane.org/gmane.emacs.devel/122038
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Change log:
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 3, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:

(defgroup sml-modeline nil
  "Customization group for `sml-mode'."
  :group 'frames)

(defcustom sml-len 12
  "Mode line indicator total length."
  :type 'integer
  :group 'sml-modeline)

(defcustom sml-borders nil
  "Indicator borders.
This is a pair of indicators, like [] or nil."
  :type '(choice (const :tag "None" nil)
                 (cons (string :tag "Left border")
                       (string :tag "Right border")))
  :group 'sml-modeline)

;;(sml-create)
(defun sml-create ()
 (let* ((wstart (window-start))
        (wend (window-end))
        (real-point-max (save-restriction (widen) (point-max)))
        (percentage-beg (/ (float wstart) (float real-point-max)))
        (percentage-end (/ (float wend) (float real-point-max)))
        (sml-begin (or (car sml-borders) ""))
        (sml-end   (or (cdr sml-borders) ""))
        (inner-len (- sml-len (length sml-begin) (length sml-end)))
        bpad-len
        epad-len
        (start (floor (* percentage-beg inner-len)))
        (end (ceiling (* percentage-end inner-len)))
        string)
   (if (not (or (< wend real-point-max) (> wstart 1)))
       ""
     (setq string
           (concat (format "%02d" (round (* percentage-beg 100))) ""
                   "-"
                   (format "%02d" (round (* percentage-end 100))) "%%"
                   ))
     (setq bpad-len (/ (- inner-len (length string)) 2))
     (setq epad-len (- inner-len (length string) bpad-len))
     (setq string (concat sml-begin
                          (make-string bpad-len 32)
                          string
                          (make-string epad-len 32)
                          sml-end))
     (assert (= (length string) sml-len) t)
     (setq start (+ start (length sml-begin)))
     (when (= start
              (setq end (+ end (length sml-begin))))
       (setq end  (1+ end)))
     (when (and (= (elt string start) 37)
                (= (elt string end) 37))
       (setq end  (1+ end)))
     (put-text-property
      start end
      'face `(:background ,(face-foreground 'mode-line)
              :foreground ,(face-background 'mode-line))
      string)
     (when (and (= 0 (length sml-begin))
                (= 0 (length sml-end)))
       (put-text-property
        0 start
        'face `(:background ,(face-foreground 'mode-line-inactive)
                :foreground ,(face-background 'mode-line))
        string)
       (put-text-property
        end sml-len
        'face `(:background ,(face-foreground 'mode-line-inactive)
                :foreground ,(face-background 'mode-line))
        string)
       )
     string)))

(defvar sml-old-car-mode-line-position nil)

(define-minor-mode sml-mode
  "Show buffer size and position like scrollbar in mode line."
  :global t
  :group 'sml-modeline
  (if sml-mode
      (progn
        (unless sml-old-car-mode-line-position
          (setq sml-old-car-mode-line-position (car mode-line-position)))
        (setcar mode-line-position '(:eval (list (sml-create)))))
    (setcar mode-line-position sml-old-car-mode-line-position)))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; sml-modeline.el ends here

  parent reply	other threads:[~2010-03-16 12:44 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-15 16:38 scrollbar alternative joakim
2010-03-15 17:28 ` David Engster
2010-03-15 18:20   ` Drew Adams
2010-03-15 19:57     ` David Engster
2010-03-15 19:41   ` Leo
2010-03-15 20:18     ` David Engster
2010-03-16  3:12       ` Zhu, Shenli
2010-03-16  4:34         ` Drew Adams
2010-03-16  6:24           ` Zhu, Shenli
2010-03-16 12:44           ` Lennart Borgman [this message]
2010-03-16 15:40             ` Drew Adams
2010-03-16 15:43               ` Lennart Borgman
2010-03-16 16:10                 ` Drew Adams
2010-03-16 16:53                   ` Lennart Borgman
2010-03-16 16:54                 ` Deniz Dogan
2010-03-29 19:47             ` Progress indicator (was: scrollbar alternative) Leo
2010-03-29 19:54               ` Lennart Borgman
2010-03-29 21:30                 ` Leo
2010-03-29 21:32                   ` Lennart Borgman
2010-03-29 21:47                   ` Eli Zaretskii
2010-03-15 18:36 ` scrollbar alternative Deniz Dogan

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=e01d8a51003160544y4b19cd54m13939b7d129f8418@mail.gmail.com \
    --to=lennart.borgman@gmail.com \
    --cc=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    --cc=zhushenli2@gmail.com \
    /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).