home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / me34src.zip / me3 / mutt / builtin / bstats.mut < prev    next >
Lisp/Scheme  |  1995-01-14  |  4KB  |  156 lines

  1.     ;; bstats.mut : buffer stats
  2.     ;; C Durland    Public Domain
  3.     ;; Last modified:  11/92
  4.  
  5. (include me.mh)
  6. (include tobase.mut)
  7.  
  8. (defun
  9.   show-buffer-stats
  10.   {
  11.     (int buffer-size dot lines buffer-row wasted char-at-dot)    ;; BufferInfo
  12.     (int ratio)
  13.  
  14.     (buffer-stats -1 (loc buffer-size))
  15.     (ratio 0)(if (!= 0 buffer-size)(ratio (/ (* 100 dot) buffer-size)))
  16.     (msg "Row: " buffer-row "/" lines  " Column: " (current-column)
  17.     " CH: 0x" (tobase char-at-dot 16)
  18.     " (" ratio "% of " buffer-size ")")
  19.   }
  20. )
  21.  
  22.     ;; Display a buffer in another window, creating a window if need be.
  23.     ;; If the buffer is already in a window, nothing is done.
  24.     ;; Input:
  25.     ;;   buffer-id : id of the buffer to be displayed
  26.     ;;   Optional:
  27.     ;;     row : row to put the dot on.
  28.     ;;     column : column to put the dot at.
  29.     ;;     If row and column not passed in, dot is not moved.
  30.     ;; Output:
  31.     ;;   Id of the window that is showing the buffer.
  32. (defun 
  33.   popup-buffer (int buffer-id) (int row column)
  34.   {
  35.     (int j)
  36.  
  37.     (j 0)(while (< j (windows))
  38.     {
  39.       (if (== buffer-id (attached-buffer j))    ;; window j is showing buffer
  40.     { (place-dot j (push-args 1)) j (done) })
  41.       (+= j 1)
  42.     })
  43.     (if (== (windows) 1)(split-window))
  44.     (next-window)
  45.     (current-buffer buffer-id TRUE)
  46.  
  47.     (place-dot (j (current-window)) (push-args 1))
  48.  
  49.     (previous-window)
  50.     j
  51.   }
  52.   place-dot (int w)(int row column) HIDDEN
  53.   {
  54.     (int cw)
  55.  
  56.     (if (== 1 (nargs)) (done))
  57.     (cw (current-window))
  58.  
  59.     (current-window w)
  60.     (current-line row)(current-column column)
  61.     (update FALSE)        ;; force the dot
  62.     (current-window cw)
  63.   }
  64. )
  65.  
  66.     ;; Put a list of buffer into a buffer.  Show various infos about those
  67.     ;;   buffers.
  68.     ;; Format:
  69.     ;;   Flags        buffer-size    buffer-name    file-name
  70.     ;;   Modified
  71.     ;;   Undo turned on
  72.     ;;   hidden - hard
  73.     ;;   hidden - soft
  74.     ;;   MUhH, dashes used if flag not set.
  75.     ;; Notes:
  76.     ;;   This does a few (minor) things for the benefit of of buffer-menu.
  77. (const
  78.   END-SIZE-COL    13
  79.   BUF-COL    14
  80.   FILE-COL    28    ;; The real file column - 1
  81. )
  82.  
  83. (defun
  84.   list-buffers
  85.   {
  86.     (int buffer-size dot lines row wasted char-at-dot)    ;; struct BufferInfo
  87.     (int total-bytes total-lines)
  88.     (int j num-buffers cw bp bp1 wp old-curbp)
  89.  
  90.     (if (arg-flag)
  91.       {
  92.     (arg-flag FALSE 1)        ;; reset arg count
  93.     (if (pgm-exists "buffer-menu")
  94.       {
  95.         (floc "buffer-menu"())    ;; recursive - calls list-buffers
  96.         (done)
  97.       })
  98.       })
  99.  
  100.     (num-buffers (total-bytes (total-lines 0)))
  101.     (old-curbp (current-buffer))
  102.  
  103.     (if (== -2 (bp (attached-buffer "*buffer-list*")))
  104.     (bp (create-buffer "*buffer-list*" BFHooHum)))
  105.     (current-buffer bp)(buffer-read-only FALSE)
  106.     (clear-buffer)
  107.     (insert-text "Flags   Size Buffer           File")(newline)
  108.     (insert-text "-----   ---- ------           ----")(newline)
  109.     (for (j 0) (< j (buffers)) (+= j 1)
  110.     {
  111.       (bp1 (nth-buffer j))
  112.       (if (!= bp bp1)
  113.       {
  114.     (buffer-stats bp1 (loc buffer-size))
  115.  
  116.     (insert-text " ")        ;; for buffer menu
  117.  
  118.     (if (!= 0 (bit-and BFNoCare (buffer-flags bp1)))
  119.       (insert-text ".")
  120.       (show-flag bp1 BFModified "M"))
  121.  
  122.     (show-flag bp1 BFUndo     "u")
  123.     (show-flag bp1 BFHidden   "H")
  124.     (show-flag bp1 BFHidden2  "h")
  125.  
  126.     (to-col (- END-SIZE-COL (length-of (concat buffer-size))))
  127.     (insert-text buffer-size)
  128.  
  129.     (insert-text " " (buffer-name bp1))
  130.         ;; " " in case the buffer name is long
  131.     (to-col FILE-COL) (insert-text " " (file-name bp1))
  132.  
  133.     (newline)
  134.     (+= num-buffers 1)(+= total-bytes buffer-size)(+= total-lines lines)
  135.       })
  136.     })
  137.  
  138.     (newline)
  139.     (to-col (- 9 (length-of (concat total-bytes))))
  140.     (insert-text total-bytes " bytes (" total-lines " lines) in "
  141.     num-buffers " buffers.  ")
  142.  
  143.     (buffer-modified -1 FALSE)
  144.     (buffer-read-only TRUE)    ;; mostly for buffer-menu
  145.  
  146.     (current-buffer old-curbp)
  147.  
  148.     (popup-buffer bp 3 BUF-COL)            ;; and return the window id
  149.   }
  150.   show-flag (int buffer-id flag)(string flag-on) HIDDEN
  151.   {
  152.     (insert-text
  153.       (if (!= 0 (bit-and flag (buffer-flags buffer-id))) flag-on "-"))
  154.   }
  155. )
  156.