comparison lisp/modeline.el @ 771:943eaba38521

[xemacs-hg @ 2002-03-13 08:51:24 by ben] The big ben-mule-21-5 check-in! Various files were added and deleted. See CHANGES-ben-mule. There are still some test suite failures. No crashes, though. Many of the failures have to do with problems in the test suite itself rather than in the actual code. I'll be addressing these in the next day or so -- none of the test suite failures are at all critical. Meanwhile I'll be trying to address the biggest issues -- i.e. build or run failures, which will almost certainly happen on various platforms. All comments should be sent to ben@xemacs.org -- use a Cc: if necessary when sending to mailing lists. There will be pre- and post- tags, something like pre-ben-mule-21-5-merge-in, and post-ben-mule-21-5-merge-in.
author ben
date Wed, 13 Mar 2002 08:54:06 +0000
parents 217aff1c578d
children b325de44db27
comparison
equal deleted inserted replaced
770:336a418893b5 771:943eaba38521
1 ;;; modeline.el --- modeline hackery. 1 ;;; modeline.el --- modeline hackery.
2 2
3 ;; Copyright (C) 1988, 1992-1994, 1997 Free Software Foundation, Inc. 3 ;; Copyright (C) 1988, 1992-1994, 1997 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995, 1996 Ben Wing. 4 ;; Copyright (C) 1995, 1996, 2002 Ben Wing.
5 5
6 ;; Maintainer: XEmacs Development Team 6 ;; Maintainer: XEmacs Development Team
7 ;; Keywords: extensions, dumped 7 ;; Keywords: extensions, dumped
8 8
9 ;; This file is part of XEmacs. 9 ;; This file is part of XEmacs.
42 (defcustom modeline-3d-p ;; added for the options menu 42 (defcustom modeline-3d-p ;; added for the options menu
43 (let ((thickness 43 (let ((thickness
44 (specifier-instance modeline-shadow-thickness))) 44 (specifier-instance modeline-shadow-thickness)))
45 (and (integerp thickness) 45 (and (integerp thickness)
46 (> thickness 0))) 46 (> thickness 0)))
47 "Whether the default toolbar is globally visible. This option can be 47 "Whether the default toolbar is globally visible.
48 customized through the options menu." 48 This option only has an effect when set using `customize-set-variable',
49 or through the Options menu."
49 :group 'display 50 :group 'display
50 :type 'boolean 51 :type 'boolean
51 :set #'(lambda (var val) 52 :set #'(lambda (var val)
52 (if val 53 (if val
53 (set-specifier modeline-shadow-thickness 2) 54 (set-specifier modeline-shadow-thickness 2)
81 text horizontally (vertical motion controls window resizing and horizontal 82 text horizontally (vertical motion controls window resizing and horizontal
82 motion controls modeline scrolling). 83 motion controls modeline scrolling).
83 84
84 With a value of t, the modeline text is scrolled in the same direction as 85 With a value of t, the modeline text is scrolled in the same direction as
85 the mouse motion. With a value of 'scrollbar, the modeline is considered as 86 the mouse motion. With a value of 'scrollbar, the modeline is considered as
86 a scrollbar for its own text, which then moves in the opposite direction." 87 a scrollbar for its own text, which then moves in the opposite direction.
88
89 This option should be set using `customize-set-variable'."
87 :type '(choice (const :tag "none" nil) 90 :type '(choice (const :tag "none" nil)
88 (const :tag "text" t) 91 (const :tag "text" t)
89 (const :tag "scrollbar" scrollbar)) 92 (const :tag "scrollbar" scrollbar))
90 :set (lambda (sym val) 93 :set (lambda (sym val)
91 (set-default sym val) 94 (set-default sym val)
561 (set-extent-face modeline-minor-mode-extent 'modeline-mousable) 564 (set-extent-face modeline-minor-mode-extent 'modeline-mousable)
562 (set-extent-keymap modeline-minor-mode-extent modeline-minor-mode-map) 565 (set-extent-keymap modeline-minor-mode-extent modeline-minor-mode-map)
563 566
564 567
565 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 568 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
566 ;;; Other ;;; 569 ;;; Modeline definition ;;;
567 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 570 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
571
572 (defmacro define-modeline-control (name contents doc-string &optional face
573 help-echo)
574 "Define a modeline control named NAME, a symbol.
575 A modeline control is a section of the modeline whose contents can easily
576 be changed independently of the rest of the modeline, which can have its
577 own color, and which can have its own mouse commands, which apply when the
578 mouse is over the control.
579
580 Logically, a modeline control should be an object; but we have terrible
581 object support in XEmacs, and so history has given us a series of related
582 variables, which [hopefully] all follow the same conventions.
583
584 Three variables are created:
585
586 1. The variable holding the control specification is called
587 `modeline-NAME', and is automatically buffer-local.
588
589 2. The variable holding the extent that covers the control area in the
590 modeline is called `modeline-NAME-extent'. Onto this extent, colors and
591 keymaps (and possibly glyphs?) can be added, and will be noticed by the
592 modeline redisplay code. The attachment of the extent and its control
593 is done somewhere in the modeline specification: either in the main spec
594 in `modeline-format', or in some other control, like this:
595
596 (cons modeline-NAME-extent 'modeline-NAME)
597
598 3. The keymap holding the mousable commands for the control is called
599 `modeline-NAME-map'. This is automatically attached to the extent by
600 this macro.
601
602 Initial contents of the control are CONTENTS (see `modeline-format' for
603 information about the structure of this contents). DOC-STRING specifies
604 help text that will be placed in the control variable's documentation,
605 indicating what's supposed to be in the control.
606
607 Optional argument FACE specifies the face of the control's
608 extent. (`modeline-mousable' is a good choice if your control is, in fact,
609 mousable (i.e. it has some mouse commands defined for it). Optional
610 argument HELP-ECHO specifies some help-echo to be displayed when the mouse
611 moves over the control, indicating what mouse strokes are available. "
612 (let ((control-var (intern (format "modeline-%s" name)))
613 (extent-var (intern (format "modeline-%s-extent" name)))
614 (map-var (intern (format "modeline-%s-map" name)))
615 )
616 `(progn
617 (defconst ,control-var ,contents
618 ,(format "%s
619
620 The format of the contents of this variable is documented in
621 `modeline-format'. The way the control is displayed can be changed by
622 setting the face of `%s'. Mouse commands
623 for the control can be set using `%s'." doc-string extent-var map-var))
624 (make-variable-buffer-local ',control-var)
625 (defvar ,extent-var (make-extent nil nil)
626 ,(format "Extent covering the `%s' control." control-var))
627 (defvar ,map-var (make-sparse-keymap 'modeline-narrowed-map)
628 ,(format "Keymap consulted for mouse-clicks on the `%s' control."
629 control-var))
630 (set-extent-face ,extent-var ,face)
631 (set-extent-keymap ,extent-var ,map-var)
632 (set-extent-property ,extent-var 'help-echo ,help-echo))))
633 (put 'define-modeline-control 'lisp-indent-function 2)
634
635 ;; ------------------------ modeline buffer id -------------------
568 636
569 (defun modeline-buffers-menu (event) 637 (defun modeline-buffers-menu (event)
570 (interactive "e") 638 (interactive "e")
571 (popup-menu-and-execute-in-window 639 (popup-menu-and-execute-in-window
572 '("Buffers Popup Menu" 640 '("Buffers Popup Menu"
574 ["List All Buffers" list-buffers t] 642 ["List All Buffers" list-buffers t]
575 "--" 643 "--"
576 ) 644 )
577 event)) 645 event))
578 646
579 (defvar modeline-buffer-id-left-map 647 (define-modeline-control buffer-id-left
580 (make-sparse-keymap 'modeline-buffer-id-left-map) 648 'modeline-modified-buffer-highlighted-name ;; "XEmacs:"
581 "Keymap consulted for mouse-clicks on the left half of the buffer-id string.") 649 "Modeline control for left half of buffer ID."
582 650 'modeline-mousable
583 (defvar modeline-buffer-id-right-map 651 "button2 cycles to the previous buffer")
584 (make-sparse-keymap 'modeline-buffer-id-right-map) 652
585 "Keymap consulted for mouse-clicks on the right half of the buffer-id string.") 653 (define-modeline-control buffer-id-right
654 'modeline-modified-buffer-non-highlighted-name ;; " %17b"
655 "Modeline control for right half of buffer ID."
656 nil
657 "button2 cycles to the next buffer")
586 658
587 (define-key modeline-buffer-id-left-map 'button2 'mouse-unbury-buffer) 659 (define-key modeline-buffer-id-left-map 'button2 'mouse-unbury-buffer)
588 (define-key modeline-buffer-id-right-map 'button2 'mouse-bury-buffer) 660 (define-key modeline-buffer-id-right-map 'button2 'mouse-bury-buffer)
589 (define-key modeline-buffer-id-left-map 'button3 'modeline-buffers-menu) 661 (define-key modeline-buffer-id-left-map 'button3 'modeline-buffers-menu)
590 (define-key modeline-buffer-id-right-map 'button3 'modeline-buffers-menu) 662 (define-key modeline-buffer-id-right-map 'button3 'modeline-buffers-menu)
593 "Face for the buffer ID string in the modeline.") 665 "Face for the buffer ID string in the modeline.")
594 (set-face-parent 'modeline-buffer-id 'modeline nil '(default)) 666 (set-face-parent 'modeline-buffer-id 'modeline nil '(default))
595 (when (featurep 'window-system) 667 (when (featurep 'window-system)
596 (set-face-foreground 'modeline-buffer-id "blue4" nil '(default color win)) 668 (set-face-foreground 'modeline-buffer-id "blue4" nil '(default color win))
597 (set-face-font 'modeline-buffer-id [bold-italic] nil '(default mono win)) 669 (set-face-font 'modeline-buffer-id [bold-italic] nil '(default mono win))
598 (set-face-font 'modeline-buffer-id [bold-italic] nil '(default grayscale win))) 670 (set-face-font 'modeline-buffer-id [bold-italic] nil '(default grayscale
671 win)))
599 (when (featurep 'tty) 672 (when (featurep 'tty)
600 (set-face-font 'modeline-buffer-id [bold-italic] nil '(default tty))) 673 (set-face-font 'modeline-buffer-id [bold-italic] nil '(default tty)))
601 674
602 (defvar modeline-buffer-id-extent (make-extent nil nil) 675 (define-modeline-control buffer-id
603 "Extent covering the whole of the buffer-id string.") 676 (list (cons modeline-buffer-id-left-extent 'modeline-buffer-id-left)
604 (set-extent-face modeline-buffer-id-extent 'modeline-buffer-id) 677 (cons modeline-buffer-id-right-extent 'modeline-buffer-id-right))
605
606 (defvar modeline-buffer-id-left-extent (make-extent nil nil)
607 "Extent covering the left half of the buffer-id string.")
608 (set-extent-keymap modeline-buffer-id-left-extent
609 modeline-buffer-id-left-map)
610 (set-extent-property modeline-buffer-id-left-extent 'help-echo
611 "button2 cycles to the previous buffer")
612
613 (defvar modeline-buffer-id-right-extent (make-extent nil nil)
614 "Extent covering the right half of the buffer-id string.")
615 (set-extent-keymap modeline-buffer-id-right-extent
616 modeline-buffer-id-right-map)
617 (set-extent-property modeline-buffer-id-right-extent 'help-echo
618 "button2 cycles to the next buffer")
619
620 (defconst modeline-buffer-identification
621 (list (cons modeline-buffer-id-left-extent "XEmacs%N:")
622 ; this used to be "XEmacs:"
623 (cons modeline-buffer-id-right-extent " %17b"))
624 "Modeline control for identifying the buffer being displayed. 678 "Modeline control for identifying the buffer being displayed.
625 Its default value is 679 Its default value is
626 680
627 (list (cons modeline-buffer-id-left-extent \"XEmacs%N:\") 681 (list (cons modeline-buffer-id-left-extent 'modeline-buffer-id-left)
628 (cons modeline-buffer-id-right-extent \" %17b\"))) 682 (cons modeline-buffer-id-right-extent 'modeline-buffer-id-right))
629 683
630 Major modes that edit things other than ordinary files may change this 684 Major modes that edit things other than ordinary files may change this
631 (e.g. Info, Dired,...).") 685 (e.g. Info, Dired,...)."
632 (make-variable-buffer-local 'modeline-buffer-identification) 686 'modeline-buffer-id)
687
688 (defvaralias 'modeline-buffer-identification 'modeline-buffer-id)
689
690 (defvar modeline-modified-buffer-non-highlighted-name nil)
691 (make-variable-buffer-local 'modeline-modified-buffer-non-highlighted-name)
692 (put 'modeline-modified-buffer-non-highlighted-name 'permanent-local t)
693
694 (defvar modeline-modified-buffer-highlighted-name nil)
695 (make-variable-buffer-local 'modeline-modified-buffer-highlighted-name)
696 (put 'modeline-modified-buffer-highlighted-name 'permanent-local t)
697
698 (defvar modeline-recorded-buffer-name nil)
699 (make-variable-buffer-local 'modeline-recorded-buffer-name)
700 (put 'modeline-recorded-buffer-name 'permanent-local t)
701
702 (defvar modeline-recorded-buffer-file-name nil)
703 (make-variable-buffer-local 'modeline-recorded-buffer-file-name)
704 (put 'modeline-recorded-buffer-file-name 'permanent-local t)
705
706 (add-hook 'buffer-list-changed-hook 'modeline-update-buffer-names)
707
708 (defvar modeline-max-buffer-name-size 30)
709
710 (defun modeline-update-buffer-names (frame)
711 (mapc #'(lambda (buf)
712 (when (or (not (eq (buffer-name buf)
713 (symbol-value-in-buffer
714 'modeline-recorded-buffer-name buf)))
715 (not (eq (buffer-file-name buf)
716 (symbol-value-in-buffer
717 'modeline-recorded-buffer-file-name buf))))
718 ;(dp "processing %s" buf)
719 (with-current-buffer buf
720 (setq modeline-recorded-buffer-name (buffer-name))
721 (setq modeline-recorded-buffer-file-name (buffer-file-name))
722 (if (not modeline-recorded-buffer-file-name)
723 (setq modeline-modified-buffer-non-highlighted-name
724 modeline-recorded-buffer-name
725 modeline-modified-buffer-highlighted-name nil)
726 (let ((fn
727 (if (<= (length modeline-recorded-buffer-file-name)
728 modeline-max-buffer-name-size)
729 modeline-recorded-buffer-file-name
730 (concat "..."
731 (substring
732 modeline-recorded-buffer-file-name
733 (- modeline-max-buffer-name-size))))))
734 (setq modeline-modified-buffer-non-highlighted-name
735 ;; if the filename is very long, the entire
736 ;; directory will get truncated to
737 ;; non-existence.
738 (let ((dir (file-name-directory fn)))
739 (if dir
740 (concat " ("
741 (directory-file-name
742 (file-name-directory fn))
743 ")")
744 ""))
745 modeline-modified-buffer-highlighted-name
746 (file-name-nondirectory fn))))
747 (redraw-modeline))))
748 (buffer-list)))
749
750 (defcustom modeline-new-buffer-id-format t
751 "Whether the new format for the modeline buffer ID (with directory) is used.
752 This option only has an effect when set using `customize-set-variable',
753 or through the Options menu."
754 :group 'modeline
755 :type 'boolean
756 :set #'(lambda (var val)
757 (if val
758 (progn
759 (setq-default modeline-buffer-id-left
760 'modeline-modified-buffer-highlighted-name
761 modeline-buffer-id-right
762 'modeline-modified-buffer-non-highlighted-name)
763 (set-extent-face modeline-buffer-id-left-extent
764 'modeline-mousable))
765 (setq-default modeline-buffer-id-left "XEmacs:"
766 modeline-buffer-id-right '(" %17b"))
767 (set-extent-face modeline-buffer-id-left-extent nil))))
768
769 ;; ------------------------ other modeline controls -------------------
633 770
634 ;; These are for the sake of minor mode menu. #### All of this is 771 ;; These are for the sake of minor mode menu. #### All of this is
635 ;; kind of dirty. `add-minor-mode' started out as a simple substitute 772 ;; kind of dirty. `add-minor-mode' started out as a simple substitute
636 ;; for (or (assq ...) ...) FSF stuff, but now is used for all kind of 773 ;; for (or (assq ...) ...) FSF stuff, but now is used for all kind of
637 ;; stuff. There should perhaps be a separate function to add toggles 774 ;; stuff. There should perhaps be a separate function to add toggles
638 ;; to the minor-mode-menu. 775 ;; to the minor-mode-menu.
639 (add-minor-mode 'line-number-mode "") 776 (add-minor-mode 'line-number-mode "")
640 (add-minor-mode 'column-number-mode "") 777 (add-minor-mode 'column-number-mode "")
641 778
642 (defconst modeline-process nil 779 (define-modeline-control coding-system '("%C")
643 "Modeline control for displaying info on process status. 780 "Modeline control for showing current coding system.")
644 Normally nil in most modes, since there is no process to display.") 781 ;; added March 7, 2002
645 (make-variable-buffer-local 'modeline-process) 782 (define-obsolete-variable-alias 'modeline-multibyte-status
646 783 'modeline-coding-system)
647 (defvar modeline-modified-map (make-sparse-keymap 'modeline-modified-map) 784
648 "Keymap consulted for mouse-clicks on the modeline-modified string.") 785 (define-modeline-control modified '("--%1*%1+-")
786 "Modeline control for displaying whether current buffer is modified."
787 'modeline-mousable
788 "button2 toggles the buffer's read-only status")
649 (define-key modeline-modified-map 'button2 789 (define-key modeline-modified-map 'button2
650 (make-modeline-command-wrapper 'modeline-toggle-read-only)) 790 (make-modeline-command-wrapper 'modeline-toggle-read-only))
651
652 (defvar modeline-modified-extent (make-extent nil nil)
653 "Extent covering the modeline-modified string.")
654 (set-extent-face modeline-modified-extent 'modeline-mousable)
655 (set-extent-keymap modeline-modified-extent modeline-modified-map)
656 (set-extent-property modeline-modified-extent 'help-echo
657 "button2 toggles the buffer's read-only status")
658
659 (defconst modeline-modified '("--%1*%1+-")
660 "Modeline control for displaying whether current buffer is modified.")
661 (make-variable-buffer-local 'modeline-modified)
662
663 (defvar modeline-narrowed-map (make-sparse-keymap 'modeline-narrowed-map)
664 "Keymap consulted for mouse-clicks on the modeline-narrowed string.")
665 (define-key modeline-narrowed-map 'button2
666 (make-modeline-command-wrapper 'widen))
667
668 (defvar modeline-narrowed-extent (make-extent nil nil)
669 "Extent covering the modeline-narrowed string.")
670 (set-extent-face modeline-narrowed-extent 'modeline-mousable)
671 (set-extent-keymap modeline-narrowed-extent modeline-narrowed-map)
672 (set-extent-property modeline-narrowed-extent 'help-echo
673 "button2 widens the buffer")
674
675 (setq-default
676 modeline-format
677 (list
678 ""
679 (cons modeline-modified-extent 'modeline-modified)
680 (cons modeline-buffer-id-extent 'modeline-buffer-identification)
681 " "
682 'global-mode-string
683 " %[("
684 (cons modeline-minor-mode-extent
685 (list "" 'mode-name 'minor-mode-alist))
686 (cons modeline-narrowed-extent "%n")
687 'modeline-process
688 ")%]----"
689 (list 'line-number-mode "L%l--")
690 (list 'column-number-mode "C%c--")
691 (cons -3 "%p")
692 "-%-"))
693 791
694 ;;; Added for XEmacs 20.3. Provide wrapper for vc since it may not always be 792 ;;; Added for XEmacs 20.3. Provide wrapper for vc since it may not always be
695 ;;; present, and its symbols are not visible this early in the dump if it 793 ;;; present, and its symbols are not visible this early in the dump if it
696 ;;; is. 794 ;;; is.
697 795
704 (interactive) 802 (interactive)
705 (if-fboundp 'vc-toggle-read-only 803 (if-fboundp 'vc-toggle-read-only
706 (vc-toggle-read-only) 804 (vc-toggle-read-only)
707 (toggle-read-only))) 805 (toggle-read-only)))
708 806
807 (define-modeline-control line-number (list 'line-number-mode "L%l ")
808 "Modeline control for displaying the line number of point.")
809 (define-modeline-control column-number (list 'column-number-mode "C%c ")
810 "Modeline control for displaying the column number of point.")
811 (define-modeline-control percentage (cons -3 "%p")
812 "Modeline control for displaying percentage of file above point.")
813
814 (define-modeline-control position-status
815 (cons 15 (list
816 (cons modeline-line-number-extent
817 'modeline-line-number)
818 (cons modeline-column-number-extent
819 'modeline-column-number)
820 (cons modeline-percentage-extent
821 'modeline-percentage)))
822 "Modeline control for providing status about the location of point.
823 Generally includes the line number of point, its column number, and the
824 percentage of the file above point."
825 'modeline-buffer-id)
826
827 (defconst modeline-tty-frame-specifier (make-specifier 'boolean))
828 (add-hook 'create-frame-hook 'modeline-update-tty-frame-specifier)
829 (defun modeline-update-tty-frame-specifier (f)
830 (if-fboundp 'frame-tty-p
831 (if (and (frame-tty-p f)
832 (> (frame-property f 'frame-number) 1))
833 (set-specifier modeline-tty-frame-specifier t f))))
834
835 (define-modeline-control tty-frame-id (list modeline-tty-frame-specifier
836 " [%S]"
837 )
838 "Modeline control for showing which TTY frame is selected.")
839
840 (define-modeline-control narrowed '("%n")
841 "Modeline control for displaying whether current buffer is narrowed."
842 'modeline-mousable
843 "button2 widens the buffer")
844 (define-key modeline-narrowed-map 'button2
845 (make-modeline-command-wrapper 'widen))
846
847 (define-modeline-control process nil
848 "Modeline control for displaying info on process status.
849 Normally nil in most modes, since there is no process to display.")
850
851 (setq-default
852 modeline-format
853 (list
854 ""
855 (cons modeline-coding-system-extent 'modeline-coding-system)
856 (cons modeline-modified-extent 'modeline-modified)
857 (cons modeline-position-status-extent 'modeline-position-status)
858 (cons modeline-tty-frame-id-extent 'modeline-tty-frame-id)
859 (cons modeline-buffer-id-extent 'modeline-buffer-id)
860 " "
861 'global-mode-string
862 " %[("
863 (cons modeline-minor-mode-extent
864 (list "" 'mode-name 'minor-mode-alist))
865 (cons modeline-narrowed-extent 'modeline-narrowed)
866 (cons modeline-process-extent 'modeline-process)
867 ")%]%-"))
868
709 ;;; modeline.el ends here 869 ;;; modeline.el ends here