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