all messages for Emacs-related lists mirrored at yhetil.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, David Engster <deng@randomsample.de>,
	"Zhu, Shenli" <zhushenli2@gmail.com>
Subject: Re: scrollbar alternative
Date: Tue, 16 Mar 2010 17:53:11 +0100	[thread overview]
Message-ID: <e01d8a51003160953o30b67e36s595675e289a4b367@mail.gmail.com> (raw)
In-Reply-To: <E89549F366A149A9AE1CF5AD9D187A47@us.oracle.com>

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

On Tue, Mar 16, 2010 at 5:10 PM, Drew Adams <drew.adams@oracle.com> wrote:
>> BTW there are some minor problems with the code. I will (as usual) try
>> to fix them and put the code in the nXhtml repository for the moment.
>
> Yes, like:
>
> 1. (eval-when-compile (require 'cl)) ; assert

I removed the assert instead.

> 2. Remove the :background for the left and right portions (or define it as
> something different). It is often the case that the inactive mode-line
> foreground is the same as the mode-line foreground, which means, e.g., black on
> black - no movement shown.

I added some faces.

> 3. Change the default value of `sml-borders' to show the ends, e.g. ("[" . "]").

No ;-)

I prefer the version without those. But I hope the code will somehow
be adopted so someone else can decide.

[-- Attachment #2: sml-modeline.el --]
[-- Type: text/plain, Size: 4797 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 David Engster's and Drew
;; Adam's code in these mail messages:
;;
;;   http://lists.gnu.org/archive/html/emacs-devel/2010-03/msg00523.html
;;   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:

;;;###autoload
(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)

(defface sml-end-face
  '((t (:inherit match)))
  "Face for invisible buffer parts."
  :group 'sml-modeline)
;; 'face `(:background ,(face-foreground 'mode-line-inactive)
;;         :foreground ,(face-background 'mode-line))

(defface sml-vis-face
  '((t (:inherit region)))
  "Face for invisible buffer parts."
  :group 'sml-modeline)
;; 'face `(:background ,(face-foreground 'mode-line)
;;         :foreground ,(face-background 'mode-line))

;;(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 (floor (/ (- inner-len (length string)) 2.0)))
     (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)
     (when (= start sml-len) (setq start (1- start)))
     (setq start (+ start (length sml-begin)))
     (put-text-property start end 'face 'sml-vis-face string)
     (when (and (= 0 (length sml-begin))
                (= 0 (length sml-end)))
       (put-text-property 0 start 'face 'sml-end-face string)
       (put-text-property end sml-len 'face 'sml-end-face string))
     string)))

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

;;;###autoload
(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

  reply	other threads:[~2010-03-16 16:53 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
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 [this message]
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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e01d8a51003160953o30b67e36s595675e289a4b367@mail.gmail.com \
    --to=lennart.borgman@gmail.com \
    --cc=deng@randomsample.de \
    --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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.