Annotation of GNUtools/emacs/src/buffer.c, revision 1.1

1.1     ! root        1: /* Buffer manipulation primitives for GNU Emacs.
        !             2:    Copyright (C) 1985, 1986, 1987, 1988, 1990 Free Software Foundation, Inc.
        !             3: 
        !             4: This file is part of GNU Emacs.
        !             5: 
        !             6: GNU Emacs is free software; you can redistribute it and/or modify
        !             7: it under the terms of the GNU General Public License as published by
        !             8: the Free Software Foundation; either version 1, or (at your option)
        !             9: any later version.
        !            10: 
        !            11: GNU Emacs is distributed in the hope that it will be useful,
        !            12: but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            14: GNU General Public License for more details.
        !            15: 
        !            16: You should have received a copy of the GNU General Public License
        !            17: along with GNU Emacs; see the file COPYING.  If not, write to
        !            18: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
        !            19: 
        !            20: 
        !            21: #include <sys/param.h>
        !            22: 
        !            23: #ifndef MAXPATHLEN
        !            24: /* in 4.1, param.h fails to define this. */
        !            25: #define MAXPATHLEN 1024
        !            26: #endif /* not MAXPATHLEN */
        !            27: 
        !            28: #ifdef NULL
        !            29: #undef NULL
        !            30: #endif
        !            31: #include "config.h"
        !            32: #include "lisp.h"
        !            33: #include "window.h"
        !            34: #include "commands.h"
        !            35: #include "buffer.h"
        !            36: #include "syntax.h"
        !            37: 
        !            38: struct buffer *current_buffer;         /* the current buffer */
        !            39: 
        !            40: /* First buffer in chain of all buffers (in reverse order of creation).
        !            41:    Threaded through ->next.  */
        !            42: 
        !            43: struct buffer *all_buffers;
        !            44: 
        !            45: /* This structure holds the default values of the buffer-local variables
        !            46:    defined with DEFVAR_PER_BUFFER, that have special slots in each buffer.
        !            47:    The default value occupies the same slot in this structure
        !            48:    as an individual buffer's value occupies in that buffer.
        !            49:    Setting the default value also goes through the alist of buffers
        !            50:    and stores into each buffer that does not say it has a local value.  */
        !            51: 
        !            52: struct buffer buffer_defaults;
        !            53: /* A Lisp_Object pointer to the above, used for staticpro */
        !            54: static Lisp_Object Vbuffer_defaults;
        !            55: 
        !            56: /* This structure marks which slots in a buffer have corresponding
        !            57:    default values in buffer_defaults.
        !            58:    Each such slot has a nonzero value in this structure.
        !            59:    The value has only one nonzero bit.
        !            60: 
        !            61:    When a buffer has its own local value for a slot,
        !            62:    the bit for that slot (found in the same slot in this structure)
        !            63:    is turned on in the buffer's local_var_flags slot.
        !            64: 
        !            65:    If a slot in this structure is -1, then even though there may
        !            66:    be a DEFVAR_PER_BUFFER for the slot, there is no default value for it;
        !            67:    and the corresponding slot in buffer_defaults is not used.
        !            68: 
        !            69:    If a slot is -2, then there is no DEFVAR_PER_BUFFER for it,
        !            70:    but there is a default value which is copied into each buffer.
        !            71: 
        !            72:    If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
        !            73:    zero, that is a bug */
        !            74: 
        !            75: struct buffer buffer_local_flags;
        !            76: 
        !            77: /* This structure holds the names of symbols whose values may be
        !            78:    buffer-local.  It is indexed and accessed in the same way as the above. */
        !            79: 
        !            80: struct buffer buffer_local_symbols;
        !            81: /* A Lisp_Object pointer to the above, used for staticpro */
        !            82: static Lisp_Object Vbuffer_local_symbols;
        !            83: 
        !            84: Lisp_Object Fset_buffer ();
        !            85: 
        !            86: /* Alist of all buffer names vs the buffers. */
        !            87: /* This used to be a variable, but is no longer,
        !            88:  to prevent lossage due to user rplac'ing this alist or its elements.  */
        !            89: Lisp_Object Vbuffer_alist;
        !            90: 
        !            91: Lisp_Object Qfundamental_mode, Qmode_class;
        !            92: 
        !            93: Lisp_Object QSFundamental;     /* A string "Fundamental" */
        !            94: 
        !            95: /* For debugging; temporary.  See set_buffer_internal.  */
        !            96: /* Lisp_Object Qlisp_mode, Vcheck_symbol; */
        !            97: 
        !            98: nsberror (spec)
        !            99:      Lisp_Object spec;
        !           100: {
        !           101:   if (XTYPE (spec) == Lisp_String)
        !           102:     error ("No buffer named %s", XSTRING (spec)->data);
        !           103:   error ("Invalid buffer argument");
        !           104: }
        !           105: 
        !           106: DEFUN ("buffer-list", Fbuffer_list, Sbuffer_list, 0, 0, 0,
        !           107:   "Return a list of all buffers.")
        !           108:   ()
        !           109: {
        !           110:   return Fmapcar (Qcdr, Vbuffer_alist);
        !           111: }
        !           112: 
        !           113: DEFUN ("get-buffer", Fget_buffer, Sget_buffer, 1, 1, 0,
        !           114:   "Return the buffer named NAME (a string).\n\
        !           115: It is found by looking up NAME in  buffer-alist.\n\
        !           116: If there is no buffer named NAME, nil is returned.\n\
        !           117: NAME may also be a buffer; it is returned.")
        !           118:   (name)
        !           119:      register Lisp_Object name;
        !           120: {
        !           121:   if (XTYPE (name) == Lisp_Buffer)
        !           122:     return name;
        !           123:   CHECK_STRING (name, 0);
        !           124: 
        !           125:   return Fcdr (Fassoc (name, Vbuffer_alist));
        !           126: }
        !           127: 
        !           128: DEFUN ("get-file-buffer", Fget_file_buffer, Sget_file_buffer, 1, 1, 0,
        !           129:   "Return the buffer visiting file FILENAME (a string).\n\
        !           130: If there is no such buffer, nil is returned.")
        !           131:   (filename)
        !           132:      register Lisp_Object filename;
        !           133: {
        !           134:   register Lisp_Object tail, buf, tem;
        !           135:   CHECK_STRING (filename, 0);
        !           136:   filename = Fexpand_file_name (filename, Qnil);
        !           137: 
        !           138:   for (tail = Vbuffer_alist; CONSP (tail); tail = XCONS (tail)->cdr)
        !           139:     {
        !           140:       buf = Fcdr (XCONS (tail)->car);
        !           141:       if (XTYPE (buf) != Lisp_Buffer) continue;
        !           142:       if (XTYPE (XBUFFER (buf)->filename) != Lisp_String) continue;
        !           143:       tem = Fstring_equal (XBUFFER (buf)->filename, filename);
        !           144:       if (!NULL (tem))
        !           145:        return buf;
        !           146:     }
        !           147:   return Qnil;
        !           148: }
        !           149: 
        !           150: DEFUN ("get-buffer-create", Fget_buffer_create, Sget_buffer_create, 1, 1, 0,
        !           151:   "Like get-buffer but creates a buffer named NAME and returns it if none already exists.")
        !           152:   (name)
        !           153:      register Lisp_Object name;
        !           154: {
        !           155:   register Lisp_Object buf, function, tem;
        !           156:   int count = specpdl_ptr - specpdl;
        !           157:   register struct buffer *b;
        !           158:   register unsigned char *data;
        !           159:   /* register struct buffer *bx; */
        !           160: 
        !           161:   buf = Fget_buffer (name);
        !           162:   if (!NULL (buf)) return buf;
        !           163: 
        !           164:   b = (struct buffer *) malloc (sizeof (struct buffer));
        !           165:   if (!b) memory_full ();
        !           166: 
        !           167:   BUF_GAP_SIZE (b) = 20;
        !           168:   data = (unsigned char *) malloc (BUF_GAP_SIZE (b));
        !           169:   if (!data)
        !           170:     {
        !           171:       free (b);
        !           172:       memory_full ();
        !           173:     }
        !           174:   BUF_BEG_ADDR (b) = data;
        !           175:   BUF_PT (b) = 1;
        !           176:   BUF_GPT (b) = 1;
        !           177:   BUF_BEGV (b) = 1;
        !           178:   BUF_ZV (b) = 1;
        !           179:   BUF_Z (b) = 1;
        !           180:   BUF_MODIFF (b) = 1;
        !           181: 
        !           182:   /* Put this on the chain of all buffers including killed ones.  */
        !           183:   b->next = all_buffers;
        !           184:   all_buffers = b;
        !           185: 
        !           186:   /* Put this in the alist of all live buffers.  */
        !           187:   XSET (buf, Lisp_Buffer, b);
        !           188: #if 0
        !           189:   XSETTYPE (buf, Lisp_Buffer);
        !           190:   bx = b;                      /* Use of bx avoids compiler bug on Sun */
        !           191:   XSETBUFFER (buf, bx);
        !           192: #endif
        !           193:   Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buf), Qnil));
        !           194: 
        !           195:   b->mark = Fmake_marker ();
        !           196:   b->markers = Qnil;
        !           197:   b->name = name;
        !           198: 
        !           199:   /* Enable undo in this buffer unless name starts with a space.  */
        !           200:   if (XSTRING (name)->data[0] != ' ')
        !           201:     b->undo_list = Qnil;
        !           202:   else
        !           203:     b->undo_list = Qt;
        !           204: 
        !           205:   reset_buffer (b);
        !           206: 
        !           207:   function = buffer_defaults.major_mode;
        !           208:   if (NULL (function))
        !           209:     {
        !           210:       tem = Fget (current_buffer->major_mode, Qmode_class);
        !           211:       if (EQ (tem, Qnil))
        !           212:        function = current_buffer->major_mode;
        !           213:     }
        !           214: 
        !           215:   if (NULL (function) || EQ (function, Qfundamental_mode))
        !           216:     return buf;
        !           217: 
        !           218:   /* To select a nonfundamental mode,
        !           219:      select the buffer temporarily and then call the mode function. */
        !           220: 
        !           221:   record_unwind_protect (save_excursion_restore, save_excursion_save ());
        !           222: 
        !           223:   Fset_buffer (buf);
        !           224:   call0 (function);
        !           225: 
        !           226:   unbind_to (count);
        !           227:   return buf;
        !           228: }
        !           229: 
        !           230: /* Reinitialize everything about a buffer except its name and contents.  */
        !           231: 
        !           232: void
        !           233: reset_buffer (b)
        !           234:      register struct buffer *b;
        !           235: {
        !           236:   b->filename = Qnil;
        !           237:   b->directory = (current_buffer) ? current_buffer->directory : Qnil;
        !           238:   b->modtime = 0;
        !           239:   b->save_modified = 1;
        !           240:   b->save_length = 0;
        !           241:   b->last_window_start = 1;
        !           242:   b->backed_up = Qnil;
        !           243:   b->auto_save_modified = 0;
        !           244:   b->auto_save_file_name = Qnil;
        !           245:   b->read_only = Qnil;
        !           246:   reset_buffer_local_variables(b);
        !           247: }
        !           248: 
        !           249: reset_buffer_local_variables(b)
        !           250:      register struct buffer *b;
        !           251: {
        !           252:   register int offset;
        !           253: 
        !           254:   /* Reset the major mode to Fundamental, together with all the
        !           255:      things that depend on the major mode.
        !           256:      default-major-mode is handled at a higher level.
        !           257:      We ignore it here.  */
        !           258:   b->major_mode = Qfundamental_mode;
        !           259:   b->keymap = Qnil;
        !           260:   b->abbrev_table = Vfundamental_mode_abbrev_table;
        !           261:   b->mode_name = QSFundamental;
        !           262: 
        !           263:   /* Reset all per-buffer variables to their defaults.  */
        !           264:   b->local_var_alist = Qnil;
        !           265:   b->local_var_flags = 0;
        !           266: 
        !           267:   /* For each slot that has a default value,
        !           268:      copy that into the slot.  */
        !           269: 
        !           270:   for (offset = (char *)&buffer_local_flags.name - (char *)&buffer_local_flags;
        !           271:        offset < sizeof (struct buffer);
        !           272:        offset += sizeof (Lisp_Object)) /* sizeof int == sizeof Lisp_Object */
        !           273:     if (*(int *)(offset + (char *) &buffer_local_flags) > 0
        !           274:        || *(int *)(offset + (char *) &buffer_local_flags) == -2)
        !           275:       *(Lisp_Object *)(offset + (char *)b) =
        !           276:                *(Lisp_Object *)(offset + (char *)&buffer_defaults);
        !           277: }
        !           278: 
        !           279: DEFUN ("generate-new-buffer", Fgenerate_new_buffer, Sgenerate_new_buffer,
        !           280:   1, 1, 0,
        !           281:   "Creates and returns a buffer named NAME if one does not already exist,\n\
        !           282: else tries adding successive suffixes to NAME until a new buffer-name is\n\
        !           283: formed, then creates and returns a new buffer with that new name.")
        !           284:  (name)
        !           285:      register Lisp_Object name;
        !           286: {
        !           287:   register Lisp_Object gentemp, tem;
        !           288:   int count;
        !           289:   char number[10];
        !           290: 
        !           291:   CHECK_STRING (name, 0);
        !           292: 
        !           293:   tem = Fget_buffer (name);
        !           294:   if (NULL (tem))
        !           295:     return Fget_buffer_create (name);
        !           296: 
        !           297:   count = 1;
        !           298:   while (1)
        !           299:     {
        !           300:       sprintf (number, "<%d>", ++count);
        !           301:       gentemp = concat2 (name, build_string (number));
        !           302:       tem = Fget_buffer (gentemp);
        !           303:       if (NULL (tem))
        !           304:        return Fget_buffer_create (gentemp);
        !           305:     }
        !           306: }
        !           307: 
        !           308: 
        !           309: DEFUN ("buffer-name", Fbuffer_name, Sbuffer_name, 0, 1, 0,
        !           310:   "Return the name of BUFFER, as a string.\n\
        !           311: No arg means return name of current buffer.")
        !           312:   (buffer)
        !           313:      register Lisp_Object buffer;
        !           314: {
        !           315:   if (NULL (buffer))
        !           316:     return current_buffer->name;
        !           317:   CHECK_BUFFER (buffer, 0);
        !           318:   return XBUFFER (buffer)->name;
        !           319: }
        !           320: 
        !           321: #ifdef NOTDEF /* Useless. If you need this, you should be using `eq'
        !           322:   DEFUN ("buffer-number", Fbuffer_number, Sbuffer_number, 0, 1, 0,
        !           323:     "Return the number of BUFFER.\n\
        !           324:   No arg means return number of current buffer.")
        !           325:     (buffer)
        !           326:        Lisp_Object buffer;
        !           327:   {
        !           328:     if (NULL (buffer))
        !           329:       return current_buffer->number;
        !           330:     CHECK_BUFFER (buffer, 0);
        !           331:     return XBUFFER (buffer)->number;
        !           332:   }
        !           333:  */
        !           334: #endif NOTDEF
        !           335: 
        !           336: DEFUN ("buffer-file-name", Fbuffer_file_name, Sbuffer_file_name, 0, 1, 0,
        !           337:   "Return name of file BUFFER is visiting, or NIL if none.\n\
        !           338: No argument means use current buffer as BUFFER.")
        !           339:   (buffer)
        !           340:      register Lisp_Object buffer;
        !           341: {
        !           342:   if (NULL (buffer))
        !           343:     return current_buffer->filename;
        !           344:   CHECK_BUFFER (buffer, 0);
        !           345:   return XBUFFER (buffer)->filename;
        !           346: }
        !           347: 
        !           348: DEFUN ("buffer-local-variables", Fbuffer_local_variables,
        !           349:   Sbuffer_local_variables, 0, 1, 0,
        !           350:   "Return alist of variables that are buffer-local in BUFFER.\n\
        !           351: No argument means use current buffer as BUFFER.\n\
        !           352: Each element of the value looks like (SYMBOL . VALUE).\n\
        !           353: Note that storing new VALUEs in these elements\n\
        !           354: does not change the local values.")
        !           355:   (buffer)
        !           356:      register Lisp_Object buffer;
        !           357: {
        !           358:   register struct buffer *buf;
        !           359:   register Lisp_Object val;
        !           360: 
        !           361:   if (NULL (buffer))
        !           362:     buf = current_buffer;
        !           363:   else
        !           364:     {
        !           365:       CHECK_BUFFER (buffer, 0);
        !           366:       buf = XBUFFER (buffer);
        !           367:     }
        !           368: 
        !           369:   {
        !           370:     /* Reference each variable in the alist in our current buffer.
        !           371:        If inquiring about the current buffer, this gets the current values,
        !           372:        so store them into the alist so the alist is up to date.
        !           373:        If inquiring about some other buffer, this swaps out any values
        !           374:        for that buffer, making the alist up to date automatically.  */
        !           375:     register Lisp_Object tem;
        !           376:     for (tem = buf->local_var_alist; CONSP (tem); tem = XCONS (tem)->cdr)
        !           377:       {
        !           378:        Lisp_Object v1 = Fsymbol_value (XCONS (XCONS (tem)->car)->car);
        !           379:        if (buf == current_buffer)
        !           380:          XCONS (XCONS (tem)->car)->cdr = v1;
        !           381:       }
        !           382:   }
        !           383: 
        !           384:   /* Make a copy of the alist, to return it.  */
        !           385:   val = Fcopy_alist (buf->local_var_alist);
        !           386: 
        !           387:   /* Add on all the variables stored in special slots.  */
        !           388:   {
        !           389:     register int offset, mask;
        !           390: 
        !           391:     for (offset = (char *)&buffer_local_symbols.name - (char *)&buffer_local_symbols;
        !           392:         offset < sizeof (struct buffer);
        !           393:         offset += (sizeof (int))) /* sizeof int == sizeof Lisp_Object */
        !           394:       {
        !           395:        mask = *(int *)(offset + (char *) &buffer_local_flags);
        !           396:        if (mask == -1 || (buf->local_var_flags & mask))
        !           397:          if (XTYPE (*(Lisp_Object *)(offset + (char *)&buffer_local_symbols))
        !           398:              == Lisp_Symbol)
        !           399:            val = Fcons (Fcons (*(Lisp_Object *)(offset + (char *)&buffer_local_symbols),
        !           400:                                *(Lisp_Object *)(offset + (char *)buf)),
        !           401:                         val);
        !           402:       }
        !           403:   }
        !           404:   return (val);
        !           405: }
        !           406: 
        !           407: 
        !           408: DEFUN ("buffer-modified-p", Fbuffer_modified_p, Sbuffer_modified_p,
        !           409:   0, 1, 0,
        !           410:   "Return t if BUFFER is modified since file last read in or saved.\n\
        !           411: No argument means use current buffer as BUFFER.")
        !           412:   (buffer)
        !           413:      register Lisp_Object buffer;
        !           414: {
        !           415:   register struct buffer *buf;
        !           416:   if (NULL (buffer))
        !           417:     buf = current_buffer;
        !           418:   else
        !           419:     {
        !           420:       CHECK_BUFFER (buffer, 0);
        !           421:       buf = XBUFFER (buffer);
        !           422:     }
        !           423: 
        !           424:   return buf->save_modified < BUF_MODIFF (buf) ? Qt : Qnil;
        !           425: }
        !           426: 
        !           427: DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p, Sset_buffer_modified_p,
        !           428:   1, 1, 0,
        !           429:   "Mark current buffer as modified or unmodified according to FLAG.")
        !           430:   (flag)
        !           431:      register Lisp_Object flag;
        !           432: {
        !           433:   register int already;
        !           434:   register Lisp_Object fn;
        !           435: 
        !           436: #ifdef CLASH_DETECTION
        !           437:   /* If buffer becoming modified, lock the file.
        !           438:      If buffer becoming unmodified, unlock the file.  */
        !           439: 
        !           440:   fn = current_buffer->filename;
        !           441:   if (!NULL (fn))
        !           442:     {
        !           443:       already = current_buffer->save_modified < MODIFF;
        !           444:       if (!already && !NULL (flag))
        !           445:        lock_file (fn);
        !           446:       else if (already && NULL (flag))
        !           447:        unlock_file (fn);
        !           448:     }
        !           449: #endif /* CLASH_DETECTION */
        !           450: 
        !           451:   current_buffer->save_modified = NULL (flag) ? MODIFF : 0;
        !           452:   update_mode_lines++;
        !           453:   return flag;
        !           454: }
        !           455: 
        !           456: DEFUN ("rename-buffer", Frename_buffer, Srename_buffer, 1, 1,
        !           457:        "sRename buffer (to new name): ",
        !           458:   "Change current buffer's name to NEWNAME (a string).")
        !           459:   (name)
        !           460:      register Lisp_Object name;
        !           461: {
        !           462:   register Lisp_Object tem, buf;
        !           463: 
        !           464:   CHECK_STRING (name, 0);
        !           465:   tem = Fget_buffer (name);
        !           466:   if (!NULL (tem))
        !           467:     error ("Buffer name \"%s\" is in use", XSTRING (name)->data);
        !           468: 
        !           469:   XSET (buf, Lisp_Buffer, current_buffer);
        !           470:   tem = Fmemq (buf, Vminibuffer_list);
        !           471:   if (!NULL (tem))
        !           472:     error ("Cannot rename a minibuffer");
        !           473: 
        !           474:   current_buffer->name = name;
        !           475:   Fsetcar (Frassq (buf, Vbuffer_alist), name);
        !           476:   if (NULL (current_buffer->filename) && !NULL (current_buffer->auto_save_file_name))
        !           477:     call0 (intern ("rename-auto-save-file"));
        !           478:   return Qnil;
        !           479: }
        !           480: 
        !           481: DEFUN ("other-buffer", Fother_buffer, Sother_buffer, 0, 1, 0,
        !           482:   "Return most recently selected buffer other than BUFFER.\n\
        !           483: Buffers not visible in windows are preferred to visible buffers.\n\
        !           484: If no other exists, the buffer *scratch* is returned.\n\
        !           485: If BUFFER is omitted or nil, some interesting buffer is returned.")
        !           486:   (buffer)
        !           487:      register Lisp_Object buffer;
        !           488: {
        !           489:   register Lisp_Object tail, buf, notsogood, tem;
        !           490:   notsogood = Qnil;
        !           491: 
        !           492:   for (tail = Vbuffer_alist; !NULL (tail); tail = Fcdr (tail))
        !           493:     {
        !           494:       buf = Fcdr (Fcar (tail));
        !           495:       if (EQ (buf, buffer))
        !           496:        continue;
        !           497:       if (XSTRING (XBUFFER (buf)->name)->data[0] == ' ')
        !           498:        continue;
        !           499:       tem = Fget_buffer_window (buf);
        !           500:       if (NULL (tem))
        !           501:        return buf;
        !           502:       if (NULL (notsogood))
        !           503:        notsogood = buf;
        !           504:     }
        !           505:   if (!NULL (notsogood))
        !           506:     return notsogood;
        !           507:   return Fget_buffer_create (build_string ("*scratch*"));
        !           508: }
        !           509: 
        !           510: DEFUN ("buffer-flush-undo", Fbuffer_flush_undo, Sbuffer_flush_undo, 1, 1, 0,
        !           511:   "Make BUFFER stop keeping undo information.")
        !           512:   (buf)
        !           513:      register Lisp_Object buf;
        !           514: {
        !           515:   CHECK_BUFFER (buf, 0);
        !           516:   XBUFFER (buf)->undo_list = Qt;
        !           517:   return Qnil;
        !           518: }
        !           519: 
        !           520: DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, Sbuffer_enable_undo,
        !           521:        0, 1, "",
        !           522:   "Start keeping undo information for buffer BUFFER (default is current buffer).")
        !           523:   (buf)
        !           524:      register Lisp_Object buf;
        !           525: {
        !           526:   if (NULL (buf))
        !           527:     {
        !           528:       if (EQ (current_buffer->undo_list, Qt))
        !           529:        current_buffer->undo_list = Qnil;
        !           530:     }
        !           531:   else
        !           532:     {
        !           533:       CHECK_BUFFER (buf, 0);
        !           534:       if (EQ (XBUFFER (buf)->undo_list, Qt))
        !           535:        XBUFFER (buf)->undo_list = Qnil;
        !           536:     }
        !           537:   return Qnil;
        !           538: }
        !           539: 
        !           540: DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 1, 1, "bKill buffer: ",
        !           541:   "One arg, a string or a buffer.  Get rid of the specified buffer.\n\
        !           542: Any processes that have this buffer as the `process-buffer' are killed\n\
        !           543: with `delete-process'.")
        !           544:   (bufname)
        !           545:      Lisp_Object bufname;
        !           546: {
        !           547:   Lisp_Object buf;
        !           548:   register struct buffer *b;
        !           549:   register Lisp_Object tem;
        !           550:   register struct Lisp_Marker *m;
        !           551:   struct gcpro gcpro1, gcpro2;
        !           552: 
        !           553:   if (NULL (bufname))
        !           554:     buf = Fcurrent_buffer ();
        !           555:   else
        !           556:     buf = Fget_buffer (bufname);
        !           557:   if (NULL (buf))
        !           558:     nsberror (bufname);
        !           559: 
        !           560:   b = XBUFFER (buf);
        !           561: 
        !           562:   if (FROM_KBD && !NULL (b->filename)
        !           563:       && BUF_MODIFF (b) > b->save_modified)
        !           564:     {
        !           565:       GCPRO2 (buf, bufname);
        !           566:       tem = Fyes_or_no_p (format1 ("Buffer %s modified; kill anyway? ",
        !           567:                                   XSTRING (b->name)->data));
        !           568:       UNGCPRO;
        !           569:       if (NULL (tem))
        !           570:        return Qnil;
        !           571:     }
        !           572: 
        !           573:   /* We have no more questions to ask.  Verify that it is valid
        !           574:      to kill the buffer.  This must be done after the questions
        !           575:      since anything can happen within Fyes_or_no_p.  */
        !           576: 
        !           577:   /* Don't kill the minibuffer now current.  */
        !           578:   if (EQ (buf, XWINDOW (minibuf_window)->buffer))
        !           579:     return Qnil;
        !           580: 
        !           581:   if (NULL (b->name))
        !           582:     return Qnil;
        !           583: 
        !           584:   /* Make this buffer not be current.
        !           585:      In the process, notice if this is the sole visible buffer
        !           586:      and give up if so.  */
        !           587:   if (b == current_buffer)
        !           588:     {
        !           589:       tem = Fother_buffer (buf);
        !           590:       Fset_buffer (tem);
        !           591:       if (b == current_buffer)
        !           592:        return Qnil;
        !           593:     }
        !           594: 
        !           595:   /* Now there is no question: we can kill the buffer.  */
        !           596: 
        !           597: #ifdef CLASH_DETECTION
        !           598:   /* Unlock this buffer's file, if it is locked.  */
        !           599:   unlock_buffer (b);
        !           600: #endif /* CLASH_DETECTION */
        !           601: 
        !           602: #ifdef subprocesses
        !           603:   kill_buffer_processes (buf);
        !           604: #endif subprocesses
        !           605: 
        !           606:   tem = Vinhibit_quit;
        !           607:   Vinhibit_quit = Qt;
        !           608:   Vbuffer_alist = Fdelq (Frassq (buf, Vbuffer_alist), Vbuffer_alist);
        !           609:   Freplace_buffer_in_windows (buf);
        !           610:   Vinhibit_quit = tem;
        !           611: 
        !           612:   /* Unchain all markers of this buffer
        !           613:      and leave them pointing nowhere.  */
        !           614:   for (tem = b->markers; !EQ (tem, Qnil); )
        !           615:     {
        !           616:       m = XMARKER (tem);
        !           617:       m->buffer = 0;
        !           618:       tem = m->chain;
        !           619:       m->chain = Qnil;
        !           620:     }
        !           621:   b->markers = Qnil;
        !           622: 
        !           623:   b->name = Qnil;
        !           624:   b->undo_list = Qnil;
        !           625:   free (BUF_BEG_ADDR (b));
        !           626: 
        !           627:   return Qnil;
        !           628: }
        !           629: 
        !           630: /* Put the element for buffer `buf' at the front of buffer-alist.
        !           631:  This is done when a buffer is selected "visibly".
        !           632:  It keeps buffer-alist in the order of recency of selection
        !           633:  so that other_buffer will return something nice.  */
        !           634: 
        !           635: record_buffer (buf)
        !           636:      Lisp_Object buf;
        !           637: {
        !           638:   register Lisp_Object link, prev;
        !           639: 
        !           640:   prev = Qnil;
        !           641:   for (link = Vbuffer_alist; CONSP (link); link = XCONS (link)->cdr)
        !           642:     {
        !           643:       if (EQ (XCONS (XCONS (link)->car)->cdr, buf))
        !           644:        break;
        !           645:       prev = link;
        !           646:     }
        !           647: 
        !           648:   /* Effectively do Vbuffer_alist = Fdelq (link, Vbuffer_alist)
        !           649:      but cannot use Fdelq here it that allows quitting.  */
        !           650: 
        !           651:   if (NULL (prev))
        !           652:     Vbuffer_alist = XCONS (Vbuffer_alist)->cdr;
        !           653:   else
        !           654:     XCONS (prev)->cdr = XCONS (XCONS (prev)->cdr)->cdr;
        !           655:        
        !           656:   XCONS(link)->cdr = Vbuffer_alist;
        !           657:   Vbuffer_alist = link;
        !           658: }
        !           659: 
        !           660: DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, "BSwitch to buffer: ",
        !           661:   "Select buffer BUFFER in the current window.\n\
        !           662: BUFFER may be a buffer or a buffer name.\n\
        !           663: Optional second arg NORECORD non-nil means\n\
        !           664: do not put this buffer at the front of the list of recently selected ones.\n\
        !           665: \n\
        !           666: WARNING: This is NOT the way to work on another buffer temporarily\n\
        !           667: within a Lisp program!  Use `set-buffer' instead.  That avoids messing with\n\
        !           668: the window-buffer correspondances.")
        !           669:   (bufname, norecord)
        !           670:      Lisp_Object bufname, norecord;
        !           671: {
        !           672:   register Lisp_Object buf;
        !           673: 
        !           674:   if (EQ (minibuf_window, selected_window))
        !           675:     error ("Cannot switch buffers in minibuffer window");
        !           676: 
        !           677:   if (NULL (bufname))
        !           678:     buf = Fother_buffer (Fcurrent_buffer ());
        !           679:   else
        !           680:     buf = Fget_buffer_create (bufname);
        !           681:   Fset_buffer (buf);
        !           682:   if (NULL (norecord))
        !           683:     record_buffer (buf);
        !           684: 
        !           685:   Fset_window_buffer (EQ (selected_window, minibuf_window)
        !           686:                      ? Fnext_window (minibuf_window, Qnil) : selected_window,
        !           687:                      buf);
        !           688: 
        !           689:   return Qnil;
        !           690: }
        !           691: 
        !           692: DEFUN ("pop-to-buffer", Fpop_to_buffer, Spop_to_buffer, 1, 2, 0,
        !           693:   "Select buffer BUFFER in some window, preferably a different one.\n\
        !           694: If  pop-up-windows  is non-nil, windows can be split to do this.\n\
        !           695: If second arg  OTHER-WINDOW is non-nil, insist on finding another\n\
        !           696: window even if BUFFER is already visible in the selected window.")
        !           697:   (bufname, other)
        !           698:      Lisp_Object bufname, other;
        !           699: {
        !           700:   register Lisp_Object buf;
        !           701:   if (NULL (bufname))
        !           702:     buf = Fother_buffer (Fcurrent_buffer ());
        !           703:   else
        !           704:     buf = Fget_buffer_create (bufname);
        !           705:   Fset_buffer (buf);
        !           706:   record_buffer (buf);
        !           707:   Fselect_window (Fdisplay_buffer (buf, other));
        !           708:   return Qnil;
        !           709: }
        !           710: 
        !           711: DEFUN ("current-buffer", Fcurrent_buffer, Scurrent_buffer, 0, 0, 0,
        !           712:   "Return the current buffer as a Lisp buffer object.")
        !           713:   ()
        !           714: {
        !           715:   register Lisp_Object buf;
        !           716:   XSET (buf, Lisp_Buffer, current_buffer);
        !           717:   return buf;
        !           718: }
        !           719: 
        !           720: DEFUN ("set-buffer", Fset_buffer, Sset_buffer, 1, 1, 0,
        !           721:   "Set the current buffer to the buffer or buffer name supplied as argument.\n\
        !           722: That buffer will then be the default for editing operations and printing.\n\
        !           723: This function's effect can't last past end of current command\n\
        !           724: because returning to command level\n\
        !           725: selects the chosen buffer of the current window,\n\
        !           726: and this function has no effect on what buffer that is.\n\
        !           727: See also `save-excursion' when you want to select a buffer temporarily.\n\
        !           728: Use `switch-to-buffer' or `pop-to-buffer' for interactive buffer selection.")
        !           729:   (bufname)
        !           730:      register Lisp_Object bufname;
        !           731: {
        !           732:   register Lisp_Object buffer;
        !           733:   buffer = Fget_buffer (bufname);
        !           734:   if (NULL (buffer))
        !           735:     nsberror (bufname);
        !           736:   if (NULL (XBUFFER (buffer)->name))
        !           737:     error ("Selecting deleted buffer");
        !           738:   set_buffer_internal (XBUFFER (buffer));
        !           739:   return buffer;
        !           740: }
        !           741: 
        !           742: DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only,
        !           743:                                   Sbarf_if_buffer_read_only, 0, 0, 0,
        !           744:   "Signal a  buffer-read-only  error if the current buffer is read-only.")
        !           745:   ()
        !           746: {
        !           747:   while (!NULL (current_buffer->read_only))
        !           748:     Fsignal (Qbuffer_read_only, (Fcons (Fcurrent_buffer (), Qnil)));
        !           749:   return Qnil;
        !           750: }
        !           751: 
        !           752: DEFUN ("bury-buffer", Fbury_buffer, Sbury_buffer, 0, 1, "",
        !           753:   "Put BUFFER at the end of the list of all buffers.\n\
        !           754: There it is the least likely candidate for other-buffer to return;\n\
        !           755: thus, the least likely buffer for \\[switch-to-buffer] to select by default.\n\
        !           756: BUFFER is also removed from the selected window if it was displayed there.")
        !           757:   (buf)
        !           758:      register Lisp_Object buf;
        !           759: {
        !           760:   register Lisp_Object aelt, link;
        !           761: 
        !           762:   if (NULL (buf))
        !           763:     {
        !           764:       XSET (buf, Lisp_Buffer, current_buffer);
        !           765:       Fswitch_to_buffer (Fother_buffer (buf), Qnil);
        !           766:     }
        !           767:   else
        !           768:     {
        !           769:       Lisp_Object buf1;
        !           770: 
        !           771:       buf1 = Fget_buffer (buf);
        !           772:       if (NULL (buf1))
        !           773:        nsberror (buf);
        !           774:       buf = buf1;
        !           775:     }    
        !           776: 
        !           777:   aelt = Frassq (buf, Vbuffer_alist);
        !           778:   link = Fmemq (aelt, Vbuffer_alist);
        !           779:   Vbuffer_alist = Fdelq (aelt, Vbuffer_alist);
        !           780:   XCONS (link)->cdr = Qnil;
        !           781:   Vbuffer_alist = nconc2 (Vbuffer_alist, link);
        !           782:   return Qnil;
        !           783: }
        !           784: 
        !           785: extern int last_known_column_point;
        !           786: 
        !           787: /* Set the current buffer to B, which is a C pointer,
        !           788:    rather than a Lisp object.  */
        !           789: 
        !           790: set_buffer_internal (b)
        !           791:      register struct buffer *b;
        !           792: {
        !           793:   register struct buffer *swb = 0;
        !           794:   register struct buffer *old_buf;
        !           795:   register Lisp_Object tail, valcontents;
        !           796:   enum Lisp_Type tem;
        !           797: 
        !           798:   if (current_buffer == b)
        !           799:     return;
        !           800: 
        !           801: #if 0
        !           802:   if (XWINDOW (selected_window) != 0)
        !           803:     swb = NULL (selected_window) ? 0 : XBUFFER (XWINDOW (selected_window)->buffer);
        !           804: #endif
        !           805: 
        !           806:   windows_or_buffers_changed = 1;
        !           807: 
        !           808:   /* Vcheck_symbol is set up to the symbol paragraph-start
        !           809:      in order to check for the bug that clobbers it.  */
        !           810: /* if (current_buffer && EQ (current_buffer->major_mode, Qlisp_mode)
        !           811:       && XFASTINT (Vcheck_symbol) != 0
        !           812:       && !NULL (Vcheck_symbol))
        !           813:     {
        !           814:       valcontents = XSYMBOL (Vcheck_symbol)->value;
        !           815:       if (XTYPE (valcontents) != Lisp_Some_Buffer_Local_Value)
        !           816:        abort ();
        !           817:       if (current_buffer == XBUFFER (XCONS (XCONS (valcontents)->cdr)->car)
        !           818:          && (XTYPE (XCONS (valcontents)->car) != Lisp_String
        !           819:              || XSTRING (XCONS (valcontents)->car)->size != 6))
        !           820:        abort ();
        !           821:     }
        !           822: */
        !           823: 
        !           824: #if 0
        !           825:   if (current_buffer == swb && !NULL (selected_window))
        !           826:     Fset_marker (XWINDOW (selected_window)->pointm, make_number (point),
        !           827:                 XWINDOW (selected_window)->buffer);
        !           828: #endif
        !           829:   old_buf = current_buffer;
        !           830:   current_buffer = b;
        !           831: #if 0
        !           832:   if (b == swb)
        !           833:     {
        !           834:       SET_PT (marker_position (XWINDOW (selected_window)->pointm));
        !           835:       if (point < BEGV)
        !           836:        point = BEGV;
        !           837:       if (point > ZV)
        !           838:        point = ZV;
        !           839:     }
        !           840: #endif
        !           841:   last_known_column_point = -1;   /* invalidate indentation cache */
        !           842: 
        !           843:   /* Look down buffer's list of local Lisp variables
        !           844:      to find and update any that forward into C variables. */
        !           845: 
        !           846:   for (tail = b->local_var_alist; !NULL (tail); tail = XCONS (tail)->cdr)
        !           847:     {
        !           848:       valcontents = XSYMBOL (XCONS (XCONS (tail)->car)->car)->value;
        !           849:       if ((XTYPE (valcontents) == Lisp_Buffer_Local_Value
        !           850:           || XTYPE (valcontents) == Lisp_Some_Buffer_Local_Value)
        !           851:          && (tem = XTYPE (XCONS (valcontents)->car),
        !           852:              (tem == Lisp_Boolfwd || tem == Lisp_Intfwd
        !           853:               || tem == Lisp_Objfwd)))
        !           854:        /* Just reference the variable
        !           855:             to cause it to become set for this buffer.  */
        !           856:        Fsymbol_value (XCONS (XCONS (tail)->car)->car);
        !           857:     }
        !           858: 
        !           859:   /* Do the same with any others that were local to the previous buffer */
        !           860: 
        !           861:   if (old_buf)
        !           862:     for (tail = old_buf->local_var_alist; !NULL (tail); tail = XCONS (tail)->cdr)
        !           863:       {
        !           864:        valcontents = XSYMBOL (XCONS (XCONS (tail)->car)->car)->value;
        !           865:        if ((XTYPE (valcontents) == Lisp_Buffer_Local_Value
        !           866:             || XTYPE (valcontents) == Lisp_Some_Buffer_Local_Value)
        !           867:            && (tem = XTYPE (XCONS (valcontents)->car),
        !           868:                (tem == Lisp_Boolfwd || tem == Lisp_Intfwd
        !           869:                 || tem == Lisp_Objfwd)))
        !           870:          /* Just reference the variable
        !           871:                to cause it to become set for this buffer.  */
        !           872:          Fsymbol_value (XCONS (XCONS (tail)->car)->car);
        !           873:       }
        !           874:   /* Vcheck_symbol is set up to the symbol paragraph-start
        !           875:      in order to check for the bug that clobbers it.  */
        !           876: /*if (EQ (b->major_mode, Qlisp_mode)
        !           877:       && Vcheck_symbol
        !           878:       && !NULL (Vcheck_symbol))
        !           879:     {
        !           880:       valcontents = XSYMBOL (Vcheck_symbol)->value;
        !           881:       if (XTYPE (valcontents) != Lisp_Some_Buffer_Local_Value)
        !           882:        abort ();
        !           883:       if (b == XBUFFER (XCONS (XCONS (valcontents)->cdr)->car)
        !           884:          && (XTYPE (XCONS (valcontents)->car) != Lisp_String
        !           885:              || XSTRING (XCONS (valcontents)->car)->size != 6))
        !           886:        abort ();
        !           887:       Fsymbol_value (Vcheck_symbol);
        !           888:       valcontents = XSYMBOL (Vcheck_symbol)->value;
        !           889:       if (b != XBUFFER (XCONS (XCONS (valcontents)->cdr)->car)
        !           890:          || XTYPE (XCONS (valcontents)->car) != Lisp_String
        !           891:          || XSTRING (XCONS (valcontents)->car)->size != 6)
        !           892:        abort ();
        !           893:     }
        !           894:  */
        !           895: }
        !           896: 
        !           897: DEFUN ("erase-buffer", Ferase_buffer, Serase_buffer, 0, 0, 0,
        !           898:   "Delete the entire contents of the current buffer.")
        !           899:   ()
        !           900: {
        !           901:   Fwiden ();
        !           902:   del_range (BEG, Z);
        !           903:   current_buffer->last_window_start = 1;
        !           904:   /* Prevent warnings, or suspension of auto saving, that would happen
        !           905:      if future size is less than past size.  Use of erase-buffer
        !           906:      implies that the future text is not really related to the past text.  */
        !           907:   XFASTINT (current_buffer->save_length) = 0;
        !           908:   return Qnil;
        !           909: }
        !           910: 
        !           911: validate_region (b, e)
        !           912:      register Lisp_Object *b, *e;
        !           913: {
        !           914:   register int i;
        !           915: 
        !           916:   CHECK_NUMBER_COERCE_MARKER (*b, 0);
        !           917:   CHECK_NUMBER_COERCE_MARKER (*e, 1);
        !           918: 
        !           919:   if (XINT (*b) > XINT (*e))
        !           920:     {
        !           921:       i = XFASTINT (*b);       /* This is legit even if *b is < 0 */
        !           922:       *b = *e;
        !           923:       XFASTINT (*e) = i;       /* because this is all we do with i.  */
        !           924:     }
        !           925: 
        !           926:   if (!(BEGV <= XINT (*b) && XINT (*b) <= XINT (*e)
        !           927:         && XINT (*e) <= ZV))
        !           928:     args_out_of_range (*b, *e);
        !           929: }
        !           930: 
        !           931: Lisp_Object
        !           932: list_buffers_1 (files)
        !           933:      Lisp_Object files;
        !           934: {
        !           935:   register Lisp_Object tail, tem, buf;
        !           936:   Lisp_Object col1, col2, col3, minspace;
        !           937:   register struct buffer *old = current_buffer, *b;
        !           938:   int desired_point = 0;
        !           939: 
        !           940:   XFASTINT (col1) = 19;
        !           941:   XFASTINT (col2) = 25;
        !           942:   XFASTINT (col3) = 40;
        !           943:   XFASTINT (minspace) = 1;
        !           944: 
        !           945:   Fset_buffer (Vstandard_output);
        !           946: 
        !           947:   tail = intern ("Buffer-menu-mode");
        !           948:   if (!EQ (tail, current_buffer->major_mode)
        !           949:       && (tem = Ffboundp (tail), !NULL (tem)))
        !           950:     call0 (tail);
        !           951:   Fbuffer_flush_undo (Vstandard_output);
        !           952:   current_buffer->read_only = Qnil;
        !           953: 
        !           954:   write_string ("\
        !           955:  MR Buffer         Size  Mode           File\n\
        !           956:  -- ------         ----  ----           ----\n", -1);
        !           957: 
        !           958:   for (tail = Vbuffer_alist; !NULL (tail); tail = Fcdr (tail))
        !           959:     {
        !           960:       buf = Fcdr (Fcar (tail));
        !           961:       b = XBUFFER (buf);
        !           962:       /* Don't mention the minibuffers. */
        !           963:       if (XSTRING (b->name)->data[0] == ' ')
        !           964:        continue;
        !           965:       /* Optionally don't mention buffers that lack files. */
        !           966:       if (!NULL (files) && NULL (b->filename))
        !           967:        continue;
        !           968:       /* Identify the current buffer. */
        !           969:       if (b == old)
        !           970:        desired_point = point;
        !           971:       write_string (b == old ? "." : " ", -1);
        !           972:       /* Identify modified buffers */
        !           973:       write_string (BUF_MODIFF (b) > b->save_modified ? "*" : " ", -1);
        !           974:       write_string (NULL (b->read_only) ? "  " : "% ", -1);
        !           975:       Fprinc (b->name, Qnil);
        !           976:       Findent_to (col1, make_number (2));
        !           977:       XFASTINT (tem) = BUF_Z (b) - BUF_BEG (b);
        !           978:       Fprin1 (tem, Qnil);
        !           979:       Findent_to (col2, minspace);
        !           980:       Fprinc (b->mode_name, Qnil);
        !           981:       Findent_to (col3, minspace);
        !           982:       if (!NULL (b->filename))
        !           983:        Fprinc (b->filename, Qnil);
        !           984:       write_string ("\n", -1);
        !           985:     }
        !           986: 
        !           987:   current_buffer->read_only = Qt;
        !           988:   set_buffer_internal (old);
        !           989: /* Foo.  This doesn't work since temp_output_buffer_show sets point to 1
        !           990:   if (desired_point)
        !           991:     BUF_PT (XBUFFER (Vstandard_output)) = desired_point;
        !           992:  */
        !           993:   return Qnil;
        !           994: }
        !           995: 
        !           996: DEFUN ("list-buffers", Flist_buffers, Slist_buffers, 0, 1, "P",
        !           997:   "Display a list of names of existing buffers.\n\
        !           998: Inserts it in buffer *Buffer List* and displays that.\n\
        !           999: Note that buffers with names starting with spaces are omitted.\n\
        !          1000: Non-null optional arg FILES-ONLY means mention only file buffers.\n\
        !          1001: \n\
        !          1002: The M column contains a * for buffers that are modified.\n\
        !          1003: The R column contains a % for buffers that are read-only.")
        !          1004:   (files)
        !          1005:      Lisp_Object files;
        !          1006: {
        !          1007:   internal_with_output_to_temp_buffer ("*Buffer List*",
        !          1008:                                       list_buffers_1, files);
        !          1009:   return Qnil;
        !          1010: }
        !          1011: 
        !          1012: DEFUN ("kill-all-local-variables", Fkill_all_local_variables, Skill_all_local_variables,
        !          1013:   0, 0, 0,
        !          1014:   "Eliminate all the buffer-local variable values of the current buffer.\n\
        !          1015: This buffer will then see the default values of all variables.")
        !          1016:   ()
        !          1017: {
        !          1018:   register Lisp_Object alist, sym, tem;
        !          1019: 
        !          1020:   for (alist = current_buffer->local_var_alist; !NULL (alist); alist = XCONS (alist)->cdr)
        !          1021:     {
        !          1022:       sym = XCONS (XCONS (alist)->car)->car;
        !          1023: 
        !          1024:       /* Need not do anything if some other buffer's binding is now encached.  */
        !          1025:       tem = XCONS (XCONS (XSYMBOL (sym)->value)->cdr)->car;
        !          1026:       if (XBUFFER (tem) == current_buffer)
        !          1027:        {
        !          1028:          /* Symbol is set up for this buffer's old local value.
        !          1029:             Set it up for the current buffer with the default value.  */
        !          1030: 
        !          1031:          tem = XCONS (XCONS (XSYMBOL (sym)->value)->cdr)->cdr;
        !          1032:          XCONS (tem)->car = tem;
        !          1033:          XCONS (XCONS (XSYMBOL (sym)->value)->cdr)->car = Fcurrent_buffer ();
        !          1034:          store_symval_forwarding (sym, XCONS (XSYMBOL (sym)->value)->car,
        !          1035:                                   XCONS (tem)->cdr);
        !          1036:        }
        !          1037:     }
        !          1038: 
        !          1039:   reset_buffer_local_variables (current_buffer);
        !          1040:   return Qnil;
        !          1041: }
        !          1042: 
        !          1043: extern Lisp_Object Vprin1_to_string_buffer;    /* in print.c */
        !          1044: init_buffer_once ()
        !          1045: {
        !          1046:   register Lisp_Object tem;
        !          1047: 
        !          1048:   /* Make sure all markable slots in buffer_defaults
        !          1049:      are initialized reasonably, so mark_buffer won't choke.  */
        !          1050:   reset_buffer (&buffer_defaults);
        !          1051:   reset_buffer (&buffer_local_symbols);
        !          1052:   XSET (Vbuffer_defaults, Lisp_Buffer, &buffer_defaults);
        !          1053:   XSET (Vbuffer_local_symbols, Lisp_Buffer, &buffer_local_symbols);
        !          1054: 
        !          1055:   /* Set up the default values of various buffer slots.  */
        !          1056:   /* Must do these before making the first buffer! */
        !          1057: 
        !          1058:   /* real setup is done in loaddefs.el */
        !          1059:   buffer_defaults.mode_line_format = build_string ("%-");
        !          1060:   buffer_defaults.abbrev_mode = Qnil;
        !          1061:   buffer_defaults.overwrite_mode = Qnil;
        !          1062:   buffer_defaults.case_fold_search = Qt;
        !          1063:   buffer_defaults.auto_fill_hook = Qnil;
        !          1064:   buffer_defaults.selective_display = Qnil;
        !          1065:   buffer_defaults.selective_display_ellipses = Qt;
        !          1066:   buffer_defaults.abbrev_table = Qnil;
        !          1067:   buffer_defaults.undo_list = Qnil;
        !          1068: 
        !          1069:   XFASTINT (buffer_defaults.tab_width) = 8;
        !          1070:   buffer_defaults.truncate_lines = Qnil;
        !          1071:   buffer_defaults.ctl_arrow = Qt;
        !          1072: 
        !          1073:   XFASTINT (buffer_defaults.fill_column) = 70;
        !          1074:   XFASTINT (buffer_defaults.left_margin) = 0;
        !          1075: 
        !          1076:   /* Assign the local-flags to the slots that have default values.
        !          1077:      The local flag is a bit that is used in the buffer
        !          1078:      to say that it has its own local value for the slot.
        !          1079:      The local flag bits are in the local_var_flags slot of the buffer.  */
        !          1080: 
        !          1081:   /* Nothing can work if this isn't true */
        !          1082:   if (sizeof (int) != sizeof (Lisp_Object)) abort ();
        !          1083: 
        !          1084:   /* 0 means not a lisp var, -1 means always local, else mask */
        !          1085:   bzero (&buffer_local_flags, sizeof buffer_local_flags);
        !          1086:   XFASTINT (buffer_local_flags.filename) = -1;
        !          1087:   XFASTINT (buffer_local_flags.directory) = -1;
        !          1088:   XFASTINT (buffer_local_flags.backed_up) = -1;
        !          1089:   XFASTINT (buffer_local_flags.save_length) = -1;
        !          1090:   XFASTINT (buffer_local_flags.auto_save_file_name) = -1;
        !          1091:   XFASTINT (buffer_local_flags.read_only) = -1;
        !          1092:   XFASTINT (buffer_local_flags.major_mode) = -1;
        !          1093:   XFASTINT (buffer_local_flags.mode_name) = -1;
        !          1094:   XFASTINT (buffer_local_flags.undo_list) = -1;
        !          1095: 
        !          1096:   XFASTINT (buffer_local_flags.mode_line_format) = 1;
        !          1097:   XFASTINT (buffer_local_flags.abbrev_mode) = 2;
        !          1098:   XFASTINT (buffer_local_flags.overwrite_mode) = 4;
        !          1099:   XFASTINT (buffer_local_flags.case_fold_search) = 8;
        !          1100:   XFASTINT (buffer_local_flags.auto_fill_hook) = 0x10;
        !          1101:   XFASTINT (buffer_local_flags.selective_display) = 0x20;
        !          1102:   XFASTINT (buffer_local_flags.selective_display_ellipses) = 0x40;
        !          1103:   XFASTINT (buffer_local_flags.tab_width) = 0x80;
        !          1104:   XFASTINT (buffer_local_flags.truncate_lines) = 0x100;
        !          1105:   XFASTINT (buffer_local_flags.ctl_arrow) = 0x200;
        !          1106:   XFASTINT (buffer_local_flags.fill_column) = 0x400;
        !          1107:   XFASTINT (buffer_local_flags.left_margin) = 0x800;
        !          1108:   XFASTINT (buffer_local_flags.abbrev_table) = 0x1000;
        !          1109:   XFASTINT (buffer_local_flags.syntax_table) = 0x2000;
        !          1110: 
        !          1111:   Vbuffer_alist = Qnil;
        !          1112:   current_buffer = 0;
        !          1113:   all_buffers = 0;
        !          1114: 
        !          1115:   QSFundamental = build_string ("Fundamental");
        !          1116: 
        !          1117:   Qfundamental_mode = intern ("fundamental-mode");
        !          1118:   buffer_defaults.major_mode = Qfundamental_mode;
        !          1119: 
        !          1120:   Qmode_class = intern ("mode-class");
        !          1121: 
        !          1122:   Vprin1_to_string_buffer = Fget_buffer_create (build_string (" prin1"));
        !          1123:   /* super-magic invisible buffer */
        !          1124:   Vbuffer_alist = Qnil;
        !          1125: 
        !          1126:   Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
        !          1127: }
        !          1128: 
        !          1129: init_buffer ()
        !          1130: {
        !          1131:   char buf[MAXPATHLEN+1];
        !          1132: 
        !          1133:   Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
        !          1134:   if (getwd (buf) == 0)
        !          1135:     fatal ("`getwd' failed: %s.\n", buf);
        !          1136: 
        !          1137: #ifndef VMS
        !          1138:   /* Maybe this should really use some standard subroutine
        !          1139:      whose definition is filename syntax dependent.  */
        !          1140:   if (buf[strlen (buf) - 1] != '/')
        !          1141:     strcat (buf, "/");
        !          1142: #endif /* not VMS */
        !          1143:   current_buffer->directory = build_string (buf);
        !          1144: }
        !          1145: 
        !          1146: /* initialize the buffer routines */
        !          1147: syms_of_buffer ()
        !          1148: {
        !          1149:   staticpro (&Vbuffer_defaults);
        !          1150:   staticpro (&Vbuffer_local_symbols);
        !          1151:   staticpro (&Qfundamental_mode);
        !          1152:   staticpro (&Qmode_class);
        !          1153:   staticpro (&QSFundamental);
        !          1154:   staticpro (&Vbuffer_alist);
        !          1155: 
        !          1156: /*staticpro (&Qlisp_mode);
        !          1157:   Qlisp_mode = intern ("lisp-mode");
        !          1158: */
        !          1159: 
        !          1160:   /* All these use DEFVAR_LISP_NOPRO because the slots in
        !          1161:      buffer_defaults will all be marked via Vbuffer_defaults.  */
        !          1162: 
        !          1163:   DEFVAR_LISP_NOPRO ("default-mode-line-format",
        !          1164:              &buffer_defaults.mode_line_format,
        !          1165:     "Default mode-line-format for buffers that do not override it.\n\
        !          1166: This is the same as (default-value 'mode-line-format).");
        !          1167: 
        !          1168:   DEFVAR_LISP_NOPRO ("default-abbrev-mode",
        !          1169:              &buffer_defaults.abbrev_mode,
        !          1170:     "Default abbrev-mode for buffers that do not override it.\n\
        !          1171: This is the same as (default-value 'abbrev-mode).");
        !          1172: 
        !          1173:   DEFVAR_LISP_NOPRO ("default-ctl-arrow",
        !          1174:              &buffer_defaults.ctl_arrow,
        !          1175:     "Default ctl-arrow for buffers that do not override it.\n\
        !          1176: This is the same as (default-value 'ctl-arrow).");
        !          1177: 
        !          1178:   DEFVAR_LISP_NOPRO ("default-truncate-lines",
        !          1179:              &buffer_defaults.truncate_lines,
        !          1180:     "Default truncate-lines for buffers that do not override it.\n\
        !          1181: This is the same as (default-value 'truncate-lines).");
        !          1182: 
        !          1183:   DEFVAR_LISP_NOPRO ("default-fill-column",
        !          1184:              &buffer_defaults.fill_column,
        !          1185:     "Default fill-column for buffers that do not override it.\n\
        !          1186: This is the same as (default-value 'fill-column).");
        !          1187: 
        !          1188:   DEFVAR_LISP_NOPRO ("default-left-margin",
        !          1189:              &buffer_defaults.left_margin,
        !          1190:     "Default left-margin for buffers that do not override it.\n\
        !          1191: This is the same as (default-value 'left-margin).");
        !          1192: 
        !          1193:   DEFVAR_LISP_NOPRO ("default-tab-width",
        !          1194:              &buffer_defaults.tab_width,
        !          1195:     "Default tab-width for buffers that do not override it.\n\
        !          1196: This is the same as (default-value 'tab-width).");
        !          1197: 
        !          1198:   DEFVAR_LISP_NOPRO ("default-case-fold-search",
        !          1199:              &buffer_defaults.case_fold_search,
        !          1200:     "Default case-fold-search for buffers that do not override it.\n\
        !          1201: This is the same as (default-value 'case-fold-search).");
        !          1202: 
        !          1203:   DEFVAR_PER_BUFFER ("mode-line-format", &current_buffer->mode_line_format, 0);
        !          1204: 
        !          1205: /* This doc string is too long for cpp; cpp dies.
        !          1206:   DEFVAR_PER_BUFFER ("mode-line-format", &current_buffer->mode_line_format,
        !          1207:     "Template for displaying mode line for current buffer.\n\
        !          1208: Each buffer has its own value of this variable.\n\
        !          1209: Value may be a string, a symbol or a list or cons cell.\n\
        !          1210: For a symbol, its value is used (but it is ignored if t or nil).\n\
        !          1211:  A string appearing directly as the value of a symbol is processed verbatim\n\
        !          1212:  in that the %-constructs below are not recognized.\n\
        !          1213: For a list whose car is a symbol, the symbol's value is taken,\n\
        !          1214:  and if that is non-nil, the cadr of the list is processed recursively.\n\
        !          1215:  Otherwise, the caddr of the list (if there is one) is processed.\n\
        !          1216: For a list whose car is a string or list, each element is processed\n\
        !          1217:  recursively and the results are effectively concatenated.\n\
        !          1218: For a list whose car is an integer, the cdr of the list is processed\n\
        !          1219:   and padded (if the number is positive) or truncated (if negative)\n\
        !          1220:   to the width specified by that number.\n\
        !          1221: A string is printed verbatim in the mode line except for %-constructs:\n\
        !          1222:   (%-constructs are allowed when the string is the entire mode-line-format\n\
        !          1223:    or when it is found in a cons-cell or a list)\n\
        !          1224:   %b -- print buffer name.      %f -- print visited file name.\n\
        !          1225:   %* -- print *, % or hyphen.   %m -- print value of mode-name (obsolete).\n\
        !          1226:   %s -- print process status.   %M -- print value of global-mode-string. (obs)\n\
        !          1227:   %p -- print percent of buffer above top of window, or top, bot or all.\n\
        !          1228:   %n -- print Narrow if appropriate.\n\
        !          1229:   %[ -- print one [ for each recursive editing level.  %] similar.\n\
        !          1230:   %% -- print %.   %- -- print infinitely many dashes.\n\
        !          1231: Decimal digits after the % specify field width to which to pad.");
        !          1232: */
        !          1233: 
        !          1234:   DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults.major_mode,
        !          1235:     "*Major mode for new buffers.  Defaults to fundamental-mode.\n\
        !          1236: nil here means use current buffer's major mode.");
        !          1237: 
        !          1238:   DEFVAR_PER_BUFFER ("major-mode", &current_buffer->major_mode,
        !          1239:     "Symbol for current buffer's major mode.");
        !          1240: 
        !          1241:   DEFVAR_PER_BUFFER ("abbrev-mode", &current_buffer->abbrev_mode,
        !          1242:     "Non-nil turns on automatic expansion of abbrevs when inserted.\n\
        !          1243: Automatically becomes local when set in any fashion.");
        !          1244: 
        !          1245:   DEFVAR_PER_BUFFER ("case-fold-search", &current_buffer->case_fold_search,
        !          1246:     "*Non-nil if searches should ignore case.\n\
        !          1247: Automatically becomes local when set in any fashion.");
        !          1248: 
        !          1249:   DEFVAR_PER_BUFFER ("mode-name", &current_buffer->mode_name,
        !          1250:     "Pretty name of current buffer's major mode (a string).");
        !          1251: 
        !          1252:   DEFVAR_PER_BUFFER ("fill-column", &current_buffer->fill_column,
        !          1253:     "*Column beyond which automatic line-wrapping should happen.\n\
        !          1254: Automatically becomes local when set in any fashion.");
        !          1255: 
        !          1256:   DEFVAR_PER_BUFFER ("left-margin", &current_buffer->left_margin,
        !          1257:     "*Column for the default indent-line-function to indent to.\n\
        !          1258: Linefeed indents to this column in Fundamental mode.\n\
        !          1259: Automatically becomes local when set in any fashion.");
        !          1260: 
        !          1261:   DEFVAR_PER_BUFFER ("tab-width", &current_buffer->tab_width,
        !          1262:     "*Distance between tab stops (for display of tab characters), in columns.\n\
        !          1263: Automatically becomes local when set in any fashion.");
        !          1264: 
        !          1265:   DEFVAR_PER_BUFFER ("ctl-arrow", &current_buffer->ctl_arrow,
        !          1266:     "*Non-nil means display control chars with uparrow.\n\
        !          1267: Nil means use backslash and octal digits.\n\
        !          1268: Automatically becomes local when set in any fashion.");
        !          1269: 
        !          1270:   DEFVAR_PER_BUFFER ("truncate-lines", &current_buffer->truncate_lines,
        !          1271:     "*Non-nil means do not display continuation lines;\n\
        !          1272: give each line of text one screen line.\n\
        !          1273: Automatically becomes local when set in any fashion.\n\
        !          1274: \n\
        !          1275: Note that this is overridden by the variable\n\
        !          1276: truncate-partial-width-windows if that variable is non-nil\n\
        !          1277: and this buffer is not full-screen width.");
        !          1278: 
        !          1279:   DEFVAR_PER_BUFFER ("default-directory", &current_buffer->directory,
        !          1280:     "Name of default directory of current buffer.  Should end with slash.");
        !          1281: 
        !          1282:   DEFVAR_PER_BUFFER ("auto-fill-hook", &current_buffer->auto_fill_hook,
        !          1283:     "Function called (if non-nil) after self-inserting a space at column beyond fill-column");
        !          1284: 
        !          1285:   DEFVAR_PER_BUFFER ("buffer-file-name", &current_buffer->filename,
        !          1286:     "Name of file visited in current buffer, or nil if not visiting a file.");
        !          1287: 
        !          1288:   DEFVAR_PER_BUFFER ("buffer-auto-save-file-name",
        !          1289:                    &current_buffer->auto_save_file_name,
        !          1290:     "Name of file for auto-saving current buffer,\n\
        !          1291: or nil if buffer should not be auto-saved.");
        !          1292: 
        !          1293:   DEFVAR_PER_BUFFER ("buffer-read-only", &current_buffer->read_only,
        !          1294:     "Non-nil if this buffer is read-only.");
        !          1295: 
        !          1296:   DEFVAR_PER_BUFFER ("buffer-backed-up", &current_buffer->backed_up,
        !          1297:     "Non-nil if this buffer's file has been backed up.\n\
        !          1298: Backing up is done before the first time the file is saved.");
        !          1299: 
        !          1300:   DEFVAR_PER_BUFFER ("buffer-saved-size", &current_buffer->save_length,
        !          1301:     "Length of current buffer when last read in, saved or auto-saved.\n\
        !          1302: 0 initially.");
        !          1303: 
        !          1304:   DEFVAR_PER_BUFFER ("selective-display", &current_buffer->selective_display,
        !          1305:     "t enables selective display:\n\
        !          1306:  after a ^M, all the rest of the line is invisible.\n\
        !          1307:  ^M's in the file are written into files as newlines.\n\
        !          1308: Integer n as value means display only lines\n\
        !          1309:  that start with less than n columns of space.\n\
        !          1310: Automatically becomes local when set in any fashion.");
        !          1311: 
        !          1312:   DEFVAR_PER_BUFFER ("selective-display-ellipses",
        !          1313:                    &current_buffer->selective_display_ellipses,
        !          1314:     "t means display ... on previous line when a line is invisible.\n\
        !          1315: Automatically becomes local when set in any fashion.");
        !          1316: 
        !          1317:   DEFVAR_PER_BUFFER ("overwrite-mode", &current_buffer->overwrite_mode,
        !          1318:     "Non-nil if self-insertion should replace existing text.\n\
        !          1319: Automatically becomes local when set in any fashion.");
        !          1320: 
        !          1321:   DEFVAR_PER_BUFFER ("buffer-undo-list", &current_buffer->undo_list,
        !          1322:     "List of undo entries in current buffer.");
        !          1323: 
        !          1324: /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol,
        !          1325:     "Don't ask.");
        !          1326: */
        !          1327:   defsubr (&Sbuffer_list);
        !          1328:   defsubr (&Sget_buffer);
        !          1329:   defsubr (&Sget_file_buffer);
        !          1330:   defsubr (&Sget_buffer_create);
        !          1331:   defsubr (&Sgenerate_new_buffer);
        !          1332:   defsubr (&Sbuffer_name);
        !          1333: /*defsubr (&Sbuffer_number);*/
        !          1334:   defsubr (&Sbuffer_file_name);
        !          1335:   defsubr (&Sbuffer_local_variables);
        !          1336:   defsubr (&Sbuffer_modified_p);
        !          1337:   defsubr (&Sset_buffer_modified_p);
        !          1338:   defsubr (&Srename_buffer);
        !          1339:   defsubr (&Sother_buffer);
        !          1340:   defsubr (&Sbuffer_flush_undo);
        !          1341:   defsubr (&Sbuffer_enable_undo);
        !          1342:   defsubr (&Skill_buffer);
        !          1343:   defsubr (&Serase_buffer);
        !          1344:   defsubr (&Sswitch_to_buffer);
        !          1345:   defsubr (&Spop_to_buffer);
        !          1346:   defsubr (&Scurrent_buffer);
        !          1347:   defsubr (&Sset_buffer);
        !          1348:   defsubr (&Sbarf_if_buffer_read_only);
        !          1349:   defsubr (&Sbury_buffer);
        !          1350:   defsubr (&Slist_buffers);
        !          1351:   defsubr (&Skill_all_local_variables);
        !          1352: }
        !          1353: 
        !          1354: keys_of_buffer ()
        !          1355: {
        !          1356:   ndefkey (Vctl_x_map, 'b', "switch-to-buffer");
        !          1357:   ndefkey (Vctl_x_map, 'k', "kill-buffer");
        !          1358:   ndefkey (Vctl_x_map, Ctl ('B'), "list-buffers");
        !          1359: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.