help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

how to scroll other buffer to beginning


From: Ye Wenbin
Subject: how to scroll other buffer to beginning
Date: Thu, 13 Jul 2006 13:39:40 +0800
User-agent: Opera Mail/9.00 (Linux)

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/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]