diff options
| -rw-r--r-- | src/buffer.c | 65 |
1 files changed, 41 insertions, 24 deletions
diff --git a/src/buffer.c b/src/buffer.c index 23d4ebf9b23..c9deb2cb0f2 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -222,8 +222,7 @@ 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); |
| @@ -275,27 +274,7 @@ The value is never nil.") | |||
| 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 |
| @@ -892,6 +871,36 @@ record_buffer (buf) | |||
| 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\ |
| @@ -916,7 +925,14 @@ the window-buffer correspondences.") | |||
| 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); |
| @@ -3050,6 +3066,7 @@ is a member of the list."); | |||
| 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); |