comparison lisp/ruler-mode.el @ 42003:a22f2256bce0

(ruler-mode-left-fringe-cols): Variable removed. (ruler-mode-left-fringe-cols): Function replaced by more efficient implementation `ruler-mode-extra-left-cols'. (ruler-mode-ruler): Use above new function. Take into account that the fringe areas can now be resized.
author Richard M. Stallman <rms@gnu.org>
date Thu, 13 Dec 2001 07:55:49 +0000
parents 5507024cc13c
children 6e891121e1cc
comparison
equal deleted inserted replaced
42002:166eb9cc3397 42003:a22f2256bce0
3 ;; Copyright (C) 2001 Free Software Foundation, Inc. 3 ;; Copyright (C) 2001 Free Software Foundation, Inc.
4 4
5 ;; Author: David Ponce <david@dponce.com> 5 ;; Author: David Ponce <david@dponce.com>
6 ;; Maintainer: David Ponce <david@dponce.com> 6 ;; Maintainer: David Ponce <david@dponce.com>
7 ;; Created: 24 Mar 2001 7 ;; Created: 24 Mar 2001
8 ;; Version: 1.3.1 8 ;; Version: 1.4
9 ;; Keywords: environment 9 ;; Keywords: environment
10 10
11 ;; This file is part of GNU Emacs. 11 ;; This file is part of GNU Emacs.
12 12
13 ;; This program is free software; you can redistribute it and/or 13 ;; This program is free software; you can redistribute it and/or
436 436
437 (defconst ruler-mode-right-margin-help-echo 437 (defconst ruler-mode-right-margin-help-echo
438 "Right margin %S" 438 "Right margin %S"
439 "Help string shown when mouse is over the right margin area.") 439 "Help string shown when mouse is over the right margin area.")
440 440
441 (defvar ruler-mode-left-fringe-cols nil 441 (defun ruler-mode-extra-left-cols ()
442 "Hold last result of function `ruler-mode-left-fringe-cols'. 442 "Return number of extra columns on the left side of selected frame.
443 This cache is local to each frame.") 443 That is the number of columns occupied by the left fringe area and
444 (make-variable-frame-local 'ruler-mode-left-fringe-cols) 444 vertical scrollbar on the left side of the selected frame."
445 445 (let ((w (frame-first-window))
446 (defun ruler-mode-left-fringe-cols (&optional check) 446 (xy (cons 0 0)))
447 "Return the character width of fringe and left vertical scrollbar. 447 (with-current-buffer (window-buffer w)
448 That is a pair (FRINGE-COLS . VSCROLLBAR-COLS) where: 448 (let (header-line-format)
449 449 (while (not (listp (coordinates-in-window-p xy w)))
450 - - FRINGE-COLS is the number of columns occupied by a fringe area. 450 (setcar xy (1+ (car xy))))
451 451 (car xy)))))
452 - - VSCROLLBAR-COLS is the number of columns occupied by the left
453 vertical scrollbar or 0 if there is no vertical scrollbar on the
454 left side.
455
456 The first time this function is called its result is saved in a frame
457 local cache and then returned on next calls. If optional argument
458 CHECK is non-nil or if the frame 'vertical-scroll-bars parameter has
459 been changed the function re-computes the result."
460 (let* ((f (selected-frame))
461 (vsb (frame-parameter f 'vertical-scroll-bars))
462 (lfc (frame-parameter f 'ruler-mode-left-fringe-cols)))
463 (if (or check (not (eq (cdr lfc) vsb)))
464 (let* ((w (frame-first-window f))
465 (sbw (frame-pixel-width f))
466 (chw (frame-char-width f))
467 (chx (/ 1.0 (float chw)))
468 (pos (cons 0.0 0))
469 (lfw 0.0)
470 coord)
471 (if vsb
472 (modify-frame-parameters
473 f '((vertical-scroll-bars . nil))))
474 (setq coord (coordinates-in-window-p pos w))
475 (while (not (memq coord '(left-fringe mode-line)))
476 (setcdr pos (1+ (cdr pos)))
477 (setq coord (coordinates-in-window-p pos w)))
478 (while (eq coord 'left-fringe)
479 (setcar pos (+ (car pos) chx))
480 (setq lfw (+ lfw chx)
481 coord (coordinates-in-window-p pos w)))
482 (or vsb
483 (modify-frame-parameters
484 f '((vertical-scroll-bars . right))))
485 (setq sbw (/ (abs (- sbw (frame-pixel-width f))) chw)
486 lfw (floor lfw))
487 (setq lfc (cons (cons lfw (if (eq vsb 'left) sbw 0)) vsb))
488 (modify-frame-parameters
489 f (list (cons 'vertical-scroll-bars vsb)
490 (cons 'ruler-mode-left-fringe-cols lfc)))))
491 (car lfc)))
492 452
493 (defun ruler-mode-ruler () 453 (defun ruler-mode-ruler ()
494 "Return a string ruler." 454 "Return a string ruler."
495 (if ruler-mode 455 (if ruler-mode
496 (let* ((lfr (ruler-mode-left-fringe-cols)) 456 (let* ((j (ruler-mode-extra-left-cols))
497 (w (+ (window-width) 1 (cdr lfr))) 457 (k (/ (or (frame-parameter nil 'right-fringe) 0)
458 (frame-char-width)))
459 (w (+ (window-width) j))
498 (m (window-margins)) 460 (m (window-margins))
499 (l (or (car m) 0)) 461 (l (or (car m) 0))
500 (r (or (cdr m) 0)) 462 (r (or (cdr m) 0))
501 (j (+ (car lfr) (cdr lfr)))
502 (o (- (window-hscroll) l j)) 463 (o (- (window-hscroll) l j))
503 (i 0) 464 (i 0)
504 (ruler (concat 465 (ruler (concat
505 ;; unit graduations 466 ;; unit graduations
506 (make-string w ruler-mode-basic-graduation-char) 467 (make-string w ruler-mode-basic-graduation-char)
507 ;; extra space to fill the header line 468 ;; extra space to fill the header line
508 (make-string j ?\ ))) 469 (make-string k ?\ )))
509 c k) 470 c)
510 471
511 ;; Setup default face and help echo. 472 ;; Setup default face and help echo.
512 (put-text-property 0 (length ruler) 473 (put-text-property 0 (length ruler)
513 'face 'ruler-mode-default-face 474 'face 'ruler-mode-default-face
514 ruler) 475 ruler)