comparison src/cmds.c @ 10865:4887c9593b79

(use_hard_newlines): Variable definition moved to paragraphs.el. (newline): Function moved to simple.el. (internal_self_insert): Insert newline BEFORE calling auto-fill-function, so centering & right-justify can work.
author Boris Goldowsky <boris@gnu.org>
date Wed, 01 Mar 1995 15:29:37 +0000
parents fb4f688fc2cf
children 636d0fa5a920
comparison
equal deleted inserted replaced
10864:33769cbeb58e 10865:4887c9593b79
24 #include "buffer.h" 24 #include "buffer.h"
25 #include "syntax.h" 25 #include "syntax.h"
26 #include "window.h" 26 #include "window.h"
27 27
28 Lisp_Object Qkill_forward_chars, Qkill_backward_chars, Vblink_paren_function; 28 Lisp_Object Qkill_forward_chars, Qkill_backward_chars, Vblink_paren_function;
29 Lisp_Object Vuse_hard_newlines;
30 29
31 /* A possible value for a buffer's overwrite-mode variable. */ 30 /* A possible value for a buffer's overwrite-mode variable. */
32 Lisp_Object Qoverwrite_mode_binary; 31 Lisp_Object Qoverwrite_mode_binary;
33 32
34 /* Non-nil means put this face on the next self-inserting character. */ 33 /* Non-nil means put this face on the next self-inserting character. */
35 Lisp_Object Vself_insert_face; 34 Lisp_Object Vself_insert_face;
36 35
37 /* This is the command that set up Vself_insert_face. */ 36 /* This is the command that set up Vself_insert_face. */
38 Lisp_Object Vself_insert_face_command; 37 Lisp_Object Vself_insert_face_command;
39
40 #ifdef USE_TEXT_PROPERTIES
41 Lisp_Object Qhard;
42 #endif
43 38
44 extern Lisp_Object Qface; 39 extern Lisp_Object Qface;
45 40
46 DEFUN ("forward-char", Fforward_char, Sforward_char, 0, 1, "p", 41 DEFUN ("forward-char", Fforward_char, Sforward_char, 0, 1, "p",
47 "Move point right ARG characters (left if ARG negative).\n\ 42 "Move point right ARG characters (left if ARG negative).\n\
234 } 229 }
235 230
236 return Qnil; 231 return Qnil;
237 } 232 }
238 233
239 DEFUN ("newline", Fnewline, Snewline, 0, 1, "P",
240 "Insert a newline. With arg, insert that many newlines.\n\
241 In Auto Fill mode, if no numeric arg, break the preceding line if it's long.")
242 (arg1)
243 Lisp_Object arg1;
244 {
245 int flag, i;
246 Lisp_Object arg;
247 char c1 = '\n';
248
249 arg = Fprefix_numeric_value (arg1);
250
251 if (!NILP (current_buffer->read_only))
252 Fbarf_if_buffer_read_only ();
253
254 /* Inserting a newline at the end of a line produces better
255 redisplay in try_window_id than inserting at the beginning of a
256 line, and the textual result is the same. So, if we're at
257 beginning of line, pretend to be at the end of the previous line.
258
259 We can't use internal_self_insert in that case since it won't do
260 the insertion correctly. Luckily, internal_self_insert's special
261 features all do nothing in that case. */
262
263 flag = point > BEGV && FETCH_CHAR (point - 1) == '\n';
264 /* Don't do this if at the beginning of the window. */
265 if (XBUFFER (XWINDOW (selected_window)->buffer) == current_buffer
266 && marker_position (XWINDOW (selected_window)->start) == PT)
267 flag = 0;
268
269 #ifdef USE_TEXT_PROPERTIES
270 /* We cannot use this optimization if properties change
271 in the vicinity.
272 ??? We need to check for change hook properties, etc. */
273 if (flag)
274 if (! (point - 1 > BEGV && ! property_change_between_p (point - 2, point)))
275 flag = 0;
276 #endif
277
278 if (flag)
279 SET_PT (point - 1);
280
281 for (i = XINT (arg); i > 0; i--)
282 {
283 if (flag)
284 insert_and_inherit (&c1, 1);
285 else
286 internal_self_insert ('\n', !NILP (arg1));
287 }
288
289 #ifdef USE_TEXT_PROPERTIES
290 if (Vuse_hard_newlines)
291 {
292 Lisp_Object from, to, sticky;
293 XSETFASTINT (from, PT - arg);
294 XSETFASTINT (to, PT);
295 Fput_text_property (from, to, Qhard, Qt, Qnil);
296 /* If rear_nonsticky is not "t", locally add Qhard to the list. */
297 sticky = Fget_text_property (from, Qrear_nonsticky, Qnil);
298 if (NILP (sticky)
299 || (CONSP (sticky) && NILP (Fmemq (Qhard, sticky))))
300 {
301 sticky = Fcons (Qhard, sticky);
302 Fput_text_property (from, to, Qrear_nonsticky, sticky, Qnil);
303 }
304 }
305 #endif
306
307
308 if (flag)
309 SET_PT (point + 1);
310
311 return Qnil;
312 }
313
314 /* Insert character C1. If NOAUTOFILL is nonzero, don't do autofill 234 /* Insert character C1. If NOAUTOFILL is nonzero, don't do autofill
315 even if it is enabled. 235 even if it is enabled.
316 236
317 If this insertion is suitable for direct output (completely simple), 237 If this insertion is suitable for direct output (completely simple),
318 return 0. A value of 1 indicates this *might* not have been simple. 238 return 0. A value of 1 indicates this *might* not have been simple.
362 } 282 }
363 if ((c == ' ' || c == '\n') 283 if ((c == ' ' || c == '\n')
364 && !noautofill 284 && !noautofill
365 && !NILP (current_buffer->auto_fill_function)) 285 && !NILP (current_buffer->auto_fill_function))
366 { 286 {
367 if (c1 != '\n') 287 insert_and_inherit (&c1, 1);
368 insert_and_inherit (&c1, 1); 288 if (c1 == '\n')
289 /* After inserting a newline, move to previous line and fill */
290 /* that. Must have the newline in place already so filling and */
291 /* justification, if any, know where the end is going to be. */
292 SET_PT (point - 1);
369 call0 (current_buffer->auto_fill_function); 293 call0 (current_buffer->auto_fill_function);
370 if (c1 == '\n') 294 if (c1 == '\n')
371 insert_and_inherit (&c1, 1); 295 SET_PT (point + 1);
372 hairy = 2; 296 hairy = 2;
373 } 297 }
374 else 298 else
375 insert_and_inherit (&c1, 1); 299 insert_and_inherit (&c1, 1);
376 300
405 staticpro (&Qkill_forward_chars); 329 staticpro (&Qkill_forward_chars);
406 330
407 Qoverwrite_mode_binary = intern ("overwrite-mode-binary"); 331 Qoverwrite_mode_binary = intern ("overwrite-mode-binary");
408 staticpro (&Qoverwrite_mode_binary); 332 staticpro (&Qoverwrite_mode_binary);
409 333
410 Qhard = intern ("hard");
411 staticpro (&Qhard);
412
413 DEFVAR_BOOL ("use-hard-newlines", &Vuse_hard_newlines,
414 "Non-nil means to distinguish hard and soft newlines.\n\
415 When this is non-nil, the functions `newline' and `open-line' add the\n\
416 text-property `hard' to newlines that they insert. Also, a line is\n\
417 only considered as a candidate to match `paragraph-start' or\n\
418 `paragraph-separate' if it follows a hard newline. Newlines not\n\
419 marked hard are called \"soft\", and are always internal to\n\
420 paragraphs. The fill functions always insert soft newlines.");
421 Vuse_hard_newlines = 0;
422
423 DEFVAR_LISP ("self-insert-face", &Vself_insert_face, 334 DEFVAR_LISP ("self-insert-face", &Vself_insert_face,
424 "If non-nil, set the face of the next self-inserting character to this.\n\ 335 "If non-nil, set the face of the next self-inserting character to this.\n\
425 See also `self-insert-face-command'."); 336 See also `self-insert-face-command'.");
426 Vself_insert_face = Qnil; 337 Vself_insert_face = Qnil;
427 338
443 354
444 defsubr (&Sdelete_char); 355 defsubr (&Sdelete_char);
445 defsubr (&Sdelete_backward_char); 356 defsubr (&Sdelete_backward_char);
446 357
447 defsubr (&Sself_insert_command); 358 defsubr (&Sself_insert_command);
448 defsubr (&Snewline);
449 } 359 }
450 360
451 keys_of_cmds () 361 keys_of_cmds ()
452 { 362 {
453 int n; 363 int n;
454 364
455 initial_define_key (global_map, Ctl ('M'), "newline");
456 initial_define_key (global_map, Ctl ('I'), "self-insert-command"); 365 initial_define_key (global_map, Ctl ('I'), "self-insert-command");
457 for (n = 040; n < 0177; n++) 366 for (n = 040; n < 0177; n++)
458 initial_define_key (global_map, n, "self-insert-command"); 367 initial_define_key (global_map, n, "self-insert-command");
459 #ifdef MSDOS 368 #ifdef MSDOS
460 for (n = 0200; n < 0240; n++) 369 for (n = 0200; n < 0240; n++)