From xemacs-m  Fri Feb 21 11:25:35 1997
Received: from jens.metrix.de (jens@jens.metrix.de [194.123.88.124])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id LAA00818
	for <xemacs-beta@xemacs.org>; Fri, 21 Feb 1997 11:25:28 -0600 (CST)
Received: (from jens@localhost) by jens.metrix.de (8.7.6/8.7.3) id SAA00934; Fri, 21 Feb 1997 18:25:10 +0100
To: xemacs-beta@xemacs.org
Cc: ukchugd@ukpmr.cs.philips.nl
Subject: patch for b94 (func-menu.el)
X-Face: Z[@OB)("ZvE?ev~1b+b!0ZUB.$%rh.9qE>dVf>q}Q/V?%d`J3gd!LR\aAZ8<Hwi]xTA(:*c;i3,?K?+rCy*^b$)a,}E?eo},}x2]5LlJysyoUOK"o[>K)'\Ulb7y-7*.If^;rHl['oa)n_M7E6w+LDKMs"G8_`c)uOS1^}.1|8Ill]7X68X-paeUOpBhz<F`B0?~^2Et~GYfw~/0]H]nx4~C_E/_mp#^7Ixc:
Reply-To: jens@lemming0.lem.uni-karlsruhe.de
Mime-Version: 1.0 (generated by tm-edit 7.105)
Content-Type: multipart/mixed;
 boundary="Multipart_Fri_Feb_21_18:25:08_1997-1"
Content-Transfer-Encoding: 7bit
From: Jens Lautenbacher <jens@metrix.de>
Date: 21 Feb 1997 18:25:08 +0100
Message-ID: <m3enea8423.fsf@jens.metrix.de>
Lines: 219
X-Mailer: Gnus v5.4.13/XEmacs 19.15

--Multipart_Fri_Feb_21_18:25:08_1997-1
Content-Type: text/plain; charset=US-ASCII



Hi.

this fixes some annoying, long standing bug (_No_, I don,t think it's
feature!) with func-menu (f-m). To undestand what I mean, just load a 
small c file with nevertheless some functions in it and move around
with the cursor keys at the bottom of the file. You will notice an
unacceptable slowdown on cursor movement. The reason for this is with
f-m's autoscan feature. To know when it's time again to rescan
the buffer, f-m increments a counter with every action and on arriving
at zero, triggers rescanning. 

This is perfectly fine. But the starting value is build by 

(/ (buffer-size) fume-rescan-trigger-counter-buffer-size)

while the last variable has a default of 10000. Clearly there is no
way to avoid rescanning on *every* keystroke for small buffers. A
different value for fume-rescan-trigger-counter-buffer-size doesn't
help, as it would need to be so small that rescanning in larger
buffers would rarely ever occur.

The following patch adds fume-rescan-trigger-counter-min (default: 50)
and changes the above mentioned algorithm to 

(max  fume-rescan-trigger-counter-min 
      (/ (buffer-size) fume-rescan-trigger-counter-buffer-size))

which is clearly not the best way (one would like to have a smooth
crossing between the threshold and the linear growth) but seems to be
OK in general use.

The slowdown I noticed was on a P133/Linux2.0.28 with enough RAM
etc. I don't think that this machine should be counted as "too low
ressources for running an editor" :-)

Maybe I just include the c-file this has happened to me the first
time now in this cycle (I had the habbit of fixing this bug in the
recent XEmacsen for myself, but I hope to get rid of it now in the
"official way")

First, the patch:


--Multipart_Fri_Feb_21_18:25:08_1997-1
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="fumediff"
Content-Transfer-Encoding: 7bit

cd /usr/local/lib/xemacs-19.15/lisp/packages/
diff -c /usr/local/lib/xemacs-19.15/lisp/packages/func-menu.el\~ /usr/local/lib/xemacs-19.15/lisp/packages/func-menu.el
*** /usr/local/lib/xemacs-19.15/lisp/packages/func-menu.el~	Sun Feb  2 06:05:51 1997
--- /usr/local/lib/xemacs-19.15/lisp/packages/func-menu.el	Fri Feb 21 17:43:56 1997
***************
*** 450,456 ****
    "Used to tune the frequency of automatic checks on the buffer.
  The function fume-rescan-buffer-trigger only works whenever the value of the
  variable fume-rescan-trigger-counter reaches zero, whereupon it gets reset to
! buffer-size/fume-rescan-trigger-counter-buffer-size.")
  
  (fume-defvar-local
   fume-sort-function 'fume-sort-by-name
--- 450,464 ----
    "Used to tune the frequency of automatic checks on the buffer.
  The function fume-rescan-buffer-trigger only works whenever the value of the
  variable fume-rescan-trigger-counter reaches zero, whereupon it gets reset to
! the maximum of a) buffer-size/fume-rescan-trigger-counter-buffer-size 
!             or b) fume-rescan-trigger-counter-min")
! 
! (defvar fume-rescan-trigger-counter-min 50
!   "Used to tune the frequency of automatic checks on the buffer.
! The function fume-rescan-buffer-trigger only works whenever the value of the
! variable fume-rescan-trigger-counter reaches zero, whereupon it gets reset to
! the maximum of a) buffer-size/fume-rescan-trigger-counter-buffer-size 
!             or b) fume-rescan-trigger-counter-min")
  
  (fume-defvar-local
   fume-sort-function 'fume-sort-by-name
***************
*** 1779,1785 ****
        (if (> fume-rescan-trigger-counter 0)
            (setq fume-rescan-trigger-counter (1- fume-rescan-trigger-counter))
          (setq fume-rescan-trigger-counter
!               (/ (buffer-size) fume-rescan-trigger-counter-buffer-size))
          (if (or fume-funclist-dirty-p
                  (save-excursion
                    (let (find fnam)
--- 1787,1794 ----
        (if (> fume-rescan-trigger-counter 0)
            (setq fume-rescan-trigger-counter (1- fume-rescan-trigger-counter))
          (setq fume-rescan-trigger-counter
! 	      (max fume-rescan-trigger-counter-min
!               (/ (buffer-size) fume-rescan-trigger-counter-buffer-size)))
          (if (or fume-funclist-dirty-p
                  (save-excursion
                    (let (find fnam)



--Multipart_Fri_Feb_21_18:25:08_1997-1
Content-Type: text/plain; charset=US-ASCII

And now to c file (just a little blob I got from the net...) so you
can just try it without searhing for some reasonably small piece of
code. 


--Multipart_Fri_Feb_21_18:25:08_1997-1
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="netkbd.c"
Content-Transfer-Encoding: 7bit

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h> 
#include <fcntl.h>
#include <linux/kd.h>
#include <linux/types.h>

unsigned char savedleds = 0; 	/* saved led states */
int ttyfd;			/* fd for the tty */

void scrollon(void)
{
        ioctl(ttyfd,KDGETLED,&savedleds);
        ioctl(ttyfd,KDSETLED,savedleds^LED_SCR);
}

void scrolloff(void)
{
        ioctl(ttyfd,KDGETLED,&savedleds);
        ioctl(ttyfd,KDSETLED,savedleds&~LED_SCR);
}

void capson(void)
{
        ioctl(ttyfd,KDGETLED,&savedleds);
        ioctl(ttyfd,KDSETLED,savedleds^LED_CAP);
}

void capsoff(void)
{
        ioctl(ttyfd,KDGETLED,&savedleds);
        ioctl(ttyfd,KDSETLED,savedleds&~LED_CAP);
}

int main(int argc, char *argv[])		
{
FILE *F1 = NULL;
char tty[10] = "/dev/";	/* device name */
int packets[2] = { 0, 0 };
static int last_packets[2] = { 0, 0 };
int skip = 0, dummy;
char line[256] = { '\0' };
char face[256];
char *word = NULL;

fprintf(stderr, "\nnetkbd-1.0 emre@mercan.cmpe.boun.edu.tr\n" );
if (argc<2){
fprintf(stderr, "Arguments missing.\n Example:  \"netkbd tty3 ppp0\" \n");
exit(1);
}

strcat(tty,argv[1]);
if((ttyfd = open(tty,O_RDWR)) < 0) {	
       	fprintf(stderr,"Error opening keyboard %s\n ",tty); 
	exit(1);
}

while (1){

F1 = fopen("/proc/net/dev", "r");
if (F1 == NULL) {
       	fprintf(stderr,"Error using proc "); 
	exit(1);
}
	strcpy(face, "");
	while (!feof(F1)) {
		fgets(line, 256, F1);
		if (feof(F1)) break;
		word = (char *)strtok(line, " ");
		if (word != NULL) {
			strcpy(face, word);
		}
		face[strlen(face)-1]='\0';
		word = (char *)strtok(NULL, " ");
		if (word != NULL) {
			sscanf(word, "%d", &packets[0]);
		}

		for (skip=0; skip < 5; skip++) {
			word = (char *)strtok(NULL, " ");
		}

		if (word != NULL) {
			sscanf(word, "%d", &packets[1]);
		}
		
		if (strcmp(argv[2], face) == 0) {
			if (packets[0]!=last_packets[0]) capson(); else capsoff();
			if (packets[1]!=last_packets[1]) scrollon(); else scrolloff();
			last_packets[0] = packets[0];
			last_packets[1] = packets[1];
		}
	}
fclose(F1);
usleep(100000);
}

}



--Multipart_Fri_Feb_21_18:25:08_1997-1--

