1. xemacs
  2. ecb

Source

ecb / ecb-mode-line.el

Diff from to

File ecb-mode-line.el

  • Ignore whitespace
   (require 'silentcomp))
 
 (require 'ecb-util)
+(require 'ecb-face)
 
 ;; XEmacs
 (silentcomp-defun redraw-modeline)
+(silentcomp-defun make-extent)
+(silentcomp-defun set-extent-face)
 ;; Emacs
 (silentcomp-defun force-mode-line-update)
+(silentcomp-defun propertize)
+
+(defgroup ecb-mode-line nil
+  "Settings for the modelines of the ECB-tree-buffers."
+  :group 'ecb-general
+  :prefix "ecb-")
 
 
 (defcustom ecb-mode-line-prefixes '((ecb-directories-buffer-name . nil)
-                                    (ecb-sources-buffer-name . nil)
+                                    (ecb-sources-buffer-name . ecb-sources-filter-modeline-prefix)
                                     (ecb-methods-buffer-name . nil)
-                                    (ecb-history-buffer-name . "History"))
+                                    (ecb-history-buffer-name . ecb-history-filter-modeline-prefix))
   "*Prefixes shown in the modelines of the special ECB-buffers.
 The displayed prefix then looks like: \"[ <PREFIX>[: ]]\", means if a prefix
 is defined for an special ECB-buffer then a single space is prepended and if
 If a special ECB-buffer should not have a prefix in its modeline then this
 buffer-name should either not being added to this option or added with \"No
 prefix\" \(= nil as cdr)."
-  :group 'ecb-general
+  :group 'ecb-mode-line
   :set (function (lambda (symbol value)
                    (set symbol value)
                    (if (and (boundp 'ecb-minor-mode)
 
 Currently this feature is only available for GNU Emacs 21.X, because neither
 GNU Emacs < 21 nor XEmacs can evaluate dynamically forms in the mode-line."
-  :group 'ecb-general
+  :group 'ecb-mode-line
   :set (function (lambda (symbol value)
                    (set symbol value)
                    (if (and (boundp 'ecb-minor-mode)
 
 
   
-
 (defcustom ecb-mode-line-data '((ecb-directories-buffer-name . sel-dir)
                                 (ecb-sources-buffer-name . sel-dir)
                                 (ecb-methods-buffer-name . sel-source)
-                                (ecb-history-buffer-name . nil))
+                                (ecb-history-buffer-name . "History"))
   "*Data shown in the modelines of the special ECB-buffers.
 Everey element of this list is a cons-cell where the car is used to define a
 buffer-name and the cdr to define the modeline-data for that buffer. For
 modeline-data and the latter one the current selected source-file \(without
 path).
 
-In addition to these two predefined values for every special ECB-buffer a
-function can be specified which gets three args \(name of the buffer, current
-selected directory and current selected source-file) and must return a string
-which will be displayed in the modeline \(or nil if no data should be
-displayed).
+In addition to these two predefined values for every special ECB-buffer either
+a simple string \(which will be displayed) or a function can be specified
+which gets three args \(name of the buffer, current selected directory and
+current selected source-file) and must return a string which will be displayed
+in the modeline \(or nil if no data should be displayed).
 
 If a special ECB-buffer should not display special data in its modeline then
 this buffer-name should either not being added to this option or added with
 The whole modeline of the special ECB-buffer consists of the prefix of
 `ecb-mode-line-prefixes' and the data of `ecb-mode-line-data' - eventually
 prepended by the window-number, see `ecb-mode-line-display-window-number'."
-  :group 'ecb-general
+  :group 'ecb-mode-line
   :set (function (lambda (symbol value)
                    (set symbol value)
                    (if (and (boundp 'ecb-minor-mode)
                                       :value sel-dir)
                                (const :tag "Current selected source"
                                       :value sel-source)
+                               (string :tag "Data-string")
                                (function :tag "Compute data with")))))
 
 
                                     ((equal data-elem 'sel-source)
                                      (and ecb-path-selected-source
                                           (file-name-nondirectory ecb-path-selected-source)))
+                                    ((stringp data-elem)
+                                     data-elem)
                                     ((null data-elem)
                                      nil)
                                     ((functionp data-elem)
           (ecb-get-current-visible-ecb-buffers))))
 
 
+(defun ecb-mode-line-make-modeline-str (str face)
+  (cond (ecb-running-xemacs
+         (let ((ext (make-extent nil nil)))
+           (set-extent-face ext face)
+           (list (cons ext str))))
+        (ecb-running-emacs-21
+         (list (propertize str 'face face)))
+        (t ;; emacs 20.X
+         str)))
+
+
 (defun ecb-mode-line-set (buffer-name prefix &optional text no-win-nr)
   "Sets the mode line for a buffer. The mode line has the scheme:
 \"[WIN-NR ][PREFIX[: ]][TEXT]\". WIN-NR is the number of the window which
   (when (get-buffer-window buffer-name ecb-frame)
     (let ((shown-prefix (if (stringp prefix)
                             (concat " " prefix (if (stringp text) ": " ""))
-                          (if (stringp text) " " ""))))
+                          (if (stringp text) " " "")))
+          (win-width (window-width (get-buffer-window buffer-name)))
+          (avaiable-text-width nil))
+      (setq shown-prefix (if (> (length shown-prefix) win-width)
+                             ""
+                           shown-prefix))
+      (setq avaiable-text-width (- win-width
+                                   (+ (length shown-prefix)
+                                      (if (and ecb-running-emacs-21
+                                               ecb-mode-line-display-window-number
+                                               (not no-win-nr))
+                                          4 0))))
       (ecb-mode-line-update-buffer
        buffer-name
        (list (if (and ecb-running-emacs-21
                       ecb-mode-line-display-window-number
                       (not no-win-nr))
-                 '(:eval (format " W-%d" (ecb-window-number)))
+                 ;; With :eval we must not use a list
+                 '(:eval (car (ecb-mode-line-make-modeline-str
+                               (format " W-%d" (ecb-window-number))
+                               ecb-mode-line-win-nr-face)))
                "")
-             (concat shown-prefix
-                     (if (stringp text)
-                         (ecb-mode-line-get-directory
-                          (+ (length shown-prefix)
-                             (if (and ecb-running-emacs-21
-                                      ecb-mode-line-display-window-number
-                                      (not no-win-nr))
-                                 4 0))
-                          text
-                          (window-width (get-buffer-window buffer-name))))))))))
+             (ecb-mode-line-make-modeline-str shown-prefix
+                                              ecb-mode-line-prefix-face)
+             (ecb-mode-line-make-modeline-str
+              (concat (if (stringp text)
+                          (ecb-fit-str-to-width
+                           text
+                           avaiable-text-width)))
+              ecb-mode-line-data-face))))))
 
-(defun ecb-mode-line-get-directory (prefix-length directory width)
-  "Given the prefix-length for the mode-line \(' ECB Sources: '), the
-directory to display, and the width of the window, compute what directory name
-to display. This should trim the beginning of the directory so that the
-mode-line does not stretch past the screen."
 
-  (if (< width prefix-length)
-      (ecb-error "Given prefix-length '%d' is longer than modeline, increase window width" prefix-length))
-
-  ;;make modifications to directory so that the line is the correct length
-  ;;remove the first characters of directory so that we have ... at the beginning.
-  (if (> (+ prefix-length
-            (length directory))
-         width)
-
-      ;;basically we need to figure out what the ideal length of the
-      ;;directory string should be based on prefix-length and directory
-      (let ((len-dir (length directory))
-            offset)
-        (setq offset (- (+ prefix-length len-dir)
-                        width))
-        ;; we want to prepend "..." to the shorten directory
-        (setq offset (+ offset 3))
-        ;; at least we must shorten directory from left by (run-over + ...)
-        ;; characters. If this is not possible we show no directory.
-        (if (>= offset len-dir)
-            (setq directory "")
-          (setq directory (substring directory offset len-dir))
-          (setq directory (concat "..." directory)))))
-  ;; return now a window-width fitting directory
-  directory)
 
 (defun ecb-mode-line-update-buffer (buffer-name new-mode-line-format)
   "Update the given buffer...."