-DEFUN ("newline", Fnewline, Snewline, 0, 1, "P",
- "Insert a newline. With arg, insert that many newlines.\n\
-In Auto Fill mode, if no numeric arg, break the preceding line if it's long.")
- (arg1)
- Lisp_Object arg1;
-{
- int flag, i;
- Lisp_Object arg;
- char c1 = '\n';
-
- arg = Fprefix_numeric_value (arg1);
-
- if (!NILP (current_buffer->read_only))
- Fbarf_if_buffer_read_only ();
-
- /* Inserting a newline at the end of a line produces better
- redisplay in try_window_id than inserting at the beginning of a
- line, and the textual result is the same. So, if we're at
- beginning of line, pretend to be at the end of the previous line.
-
- We can't use internal_self_insert in that case since it won't do
- the insertion correctly. Luckily, internal_self_insert's special
- features all do nothing in that case. */
-
- flag = point > BEGV && FETCH_CHAR (point - 1) == '\n';
- /* Don't do this if at the beginning of the window. */
- if (XBUFFER (XWINDOW (selected_window)->buffer) == current_buffer
- && marker_position (XWINDOW (selected_window)->start) == PT)
- flag = 0;
-
-#ifdef USE_TEXT_PROPERTIES
- /* We cannot use this optimization if properties change
- in the vicinity.
- ??? We need to check for change hook properties, etc. */
- if (flag)
- if (! (point - 1 > BEGV && ! property_change_between_p (point - 2, point)))
- flag = 0;
-#endif
-
- if (flag)
- SET_PT (point - 1);
-
- for (i = XINT (arg); i > 0; i--)
- {
- if (flag)
- insert_and_inherit (&c1, 1);
- else
- internal_self_insert ('\n', !NILP (arg1));
- }
-
-#ifdef USE_TEXT_PROPERTIES
- if (Vuse_hard_newlines)
- {
- Lisp_Object from, to, sticky;
- XSETFASTINT (from, PT - arg);
- XSETFASTINT (to, PT);
- Fput_text_property (from, to, Qhard, Qt, Qnil);
- /* If rear_nonsticky is not "t", locally add Qhard to the list. */
- sticky = Fget_text_property (from, Qrear_nonsticky, Qnil);
- if (NILP (sticky)
- || (CONSP (sticky) && NILP (Fmemq (Qhard, sticky))))
- {
- sticky = Fcons (Qhard, sticky);
- Fput_text_property (from, to, Qrear_nonsticky, sticky, Qnil);
- }
- }
-#endif
-
-
- if (flag)
- SET_PT (point + 1);
-
- return Qnil;
-}
-
-/* Insert character C1. If NOAUTOFILL is nonzero, don't do autofill