unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* how to scroll other buffer to beginning
@ 2006-07-13  5:39 Ye Wenbin
  2006-07-13 15:16 ` Kevin Rodgers
  0 siblings, 1 reply; 2+ messages in thread
From: Ye Wenbin @ 2006-07-13  5:39 UTC (permalink / raw)


I wrote a perl script to count directory size, when I write this function,
I found that when the "*Shell Command Output*" buffer is displayed, the  
buffer
can't scroll to beginning. How to avoid it?

(defun ywb-dired-count-dir-size ()
   (interactive)
   (let ((dir (dired-get-filename nil t))
         proc)
     (when (file-directory-p dir)
       (with-current-buffer (get-buffer-create "*Shell Command Output*")
         (erase-buffer)
         (setq proc
               (start-process-shell-command "dirsize" (current-buffer)
                                            "/home/ywb/bin/dirsize " dir))
         (while (eq (process-status proc) 'run)
           (sleep-for 0 100)
           (message "%s" (process-status proc)))
         (display-buffer (current-buffer) t)
         (beginning-of-buffer)))))
(define-key dired-mode-map " " 'ywb-dired-count-dir-size)

this is my perl script for test:
#!/usr/bin/perl -w
# dirsize --- Caculate directory size
# Last modify Time-stamp: <Ye Wenbin 2006-07-11 16:23:15>
# Version: v 0.0 2006/07/06 06:03:53
# Author: Ye Wenbin <wenbinye@163.com>
use strict;
use warnings;
use File::Find;
my $dir = shift;
exit unless -d $dir;
printf "$dir size: %s\n", dirsize($dir);
sub dirsize {
     my $dir = shift;
     my $kb = 1024;
     my $mb = 1024*1024;
     my $total = 0;
     my $count = sub {
         if (-f $_) {
             $total += -s $_;
         }
     };
     find($count, $dir);
     if ($total > $mb) {
         return sprintf("%.2f", $total/$mb)." M";
     }
     else {
         return sprintf("%.2f", $total/$kb)." K";
     }
}


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-07-13 15:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-13  5:39 how to scroll other buffer to beginning Ye Wenbin
2006-07-13 15:16 ` Kevin Rodgers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).