comparison src/buffer.c @ 9732:577db538b0b6

(Fset_buffer_major_mode): New function. Set the default major mode here. (Fget_buffer_create): Not here. (Fswitch_to_buffer): Call Fset_buffer_major_mode. (syms_of_buffer): defsubr the new function.
author Karl Heuer <kwzh@gnu.org>
date Thu, 27 Oct 1994 22:35:14 +0000
parents 833a19698ef3
children a72386110d83
comparison
equal deleted inserted replaced
9731:2fbc8ef9ff44 9732:577db538b0b6
220 If NAME is a buffer instead of a string, then it is the value returned.\n\ 220 If NAME is a buffer instead of a string, then it is the value returned.\n\
221 The value is never nil.") 221 The value is never nil.")
222 (name) 222 (name)
223 register Lisp_Object name; 223 register Lisp_Object name;
224 { 224 {
225 register Lisp_Object buf, function, tem; 225 register Lisp_Object buf;
226 int count = specpdl_ptr - specpdl;
227 register struct buffer *b; 226 register struct buffer *b;
228 227
229 buf = Fget_buffer (name); 228 buf = Fget_buffer (name);
230 if (!NILP (buf)) 229 if (!NILP (buf))
231 return buf; 230 return buf;
273 Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buf), Qnil)); 272 Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buf), Qnil));
274 273
275 b->mark = Fmake_marker (); 274 b->mark = Fmake_marker ();
276 b->markers = Qnil; 275 b->markers = Qnil;
277 b->name = name; 276 b->name = name;
278 277 return buf;
279 function = buffer_defaults.major_mode;
280 if (NILP (function))
281 {
282 tem = Fget (current_buffer->major_mode, Qmode_class);
283 if (EQ (tem, Qnil))
284 function = current_buffer->major_mode;
285 }
286
287 if (NILP (function) || EQ (function, Qfundamental_mode))
288 return buf;
289
290 /* To select a nonfundamental mode,
291 select the buffer temporarily and then call the mode function. */
292
293 record_unwind_protect (save_excursion_restore, save_excursion_save ());
294
295 Fset_buffer (buf);
296 call0 (function);
297
298 return unbind_to (count, buf);
299 } 278 }
300 279
301 /* Reinitialize everything about a buffer except its name and contents 280 /* Reinitialize everything about a buffer except its name and contents
302 and local variables. */ 281 and local variables. */
303 282
890 869
891 XCONS(link)->cdr = Vbuffer_alist; 870 XCONS(link)->cdr = Vbuffer_alist;
892 Vbuffer_alist = link; 871 Vbuffer_alist = link;
893 } 872 }
894 873
874 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode, Sset_buffer_major_mode, 1, 1, 0,
875 "Set an appropriate major mode for BUFFER, according to `default-major-mode'.\n\
876 Use this function before selecting the buffer, since it may need to inspect\n\
877 the current buffer's major mode.")
878 (buf)
879 Lisp_Object buf;
880 {
881 int count;
882 Lisp_Object function;
883
884 function = buffer_defaults.major_mode;
885 if (NILP (function) && NILP (Fget (current_buffer->major_mode, Qmode_class)))
886 function = current_buffer->major_mode;
887
888 if (NILP (function) || EQ (function, Qfundamental_mode))
889 return Qnil;
890
891 count = specpdl_ptr - specpdl;
892
893 /* To select a nonfundamental mode,
894 select the buffer temporarily and then call the mode function. */
895
896 record_unwind_protect (save_excursion_restore, save_excursion_save ());
897
898 Fset_buffer (buf);
899 call0 (function);
900
901 return unbind_to (count, Qnil);
902 }
903
895 DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, "BSwitch to buffer: ", 904 DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, "BSwitch to buffer: ",
896 "Select buffer BUFFER in the current window.\n\ 905 "Select buffer BUFFER in the current window.\n\
897 BUFFER may be a buffer or a buffer name.\n\ 906 BUFFER may be a buffer or a buffer name.\n\
898 Optional second arg NORECORD non-nil means\n\ 907 Optional second arg NORECORD non-nil means\n\
899 do not put this buffer at the front of the list of recently selected ones.\n\ 908 do not put this buffer at the front of the list of recently selected ones.\n\
914 error ("Cannot switch buffers in a dedicated window"); 923 error ("Cannot switch buffers in a dedicated window");
915 924
916 if (NILP (bufname)) 925 if (NILP (bufname))
917 buf = Fother_buffer (Fcurrent_buffer (), Qnil); 926 buf = Fother_buffer (Fcurrent_buffer (), Qnil);
918 else 927 else
919 buf = Fget_buffer_create (bufname); 928 {
929 buf = Fget_buffer (bufname);
930 if (NILP (buf))
931 {
932 buf = Fget_buffer_create (bufname);
933 Fset_buffer_major_mode (buf);
934 }
935 }
920 Fset_buffer (buf); 936 Fset_buffer (buf);
921 if (NILP (norecord)) 937 if (NILP (norecord))
922 record_buffer (buf); 938 record_buffer (buf);
923 939
924 Fset_window_buffer (EQ (selected_window, minibuf_window) 940 Fset_window_buffer (EQ (selected_window, minibuf_window)
3048 defsubr (&Sother_buffer); 3064 defsubr (&Sother_buffer);
3049 defsubr (&Sbuffer_disable_undo); 3065 defsubr (&Sbuffer_disable_undo);
3050 defsubr (&Sbuffer_enable_undo); 3066 defsubr (&Sbuffer_enable_undo);
3051 defsubr (&Skill_buffer); 3067 defsubr (&Skill_buffer);
3052 defsubr (&Serase_buffer); 3068 defsubr (&Serase_buffer);
3069 defsubr (&Sset_buffer_major_mode);
3053 defsubr (&Sswitch_to_buffer); 3070 defsubr (&Sswitch_to_buffer);
3054 defsubr (&Spop_to_buffer); 3071 defsubr (&Spop_to_buffer);
3055 defsubr (&Scurrent_buffer); 3072 defsubr (&Scurrent_buffer);
3056 defsubr (&Sset_buffer); 3073 defsubr (&Sset_buffer);
3057 defsubr (&Sbarf_if_buffer_read_only); 3074 defsubr (&Sbarf_if_buffer_read_only);