diff options
| author | Boris Goldowsky | 1995-03-01 15:29:37 +0000 |
|---|---|---|
| committer | Boris Goldowsky | 1995-03-01 15:29:37 +0000 |
| commit | 2e16553ccc8c37df91211c6f63fafd66d69b7105 (patch) | |
| tree | 03c5efbb8184bfa55efaab5258c671529f0f340a /src | |
| parent | 55cc56775b1405e61621a6395d1c981bee4cca0b (diff) | |
| download | emacs-2e16553ccc8c37df91211c6f63fafd66d69b7105.tar.gz emacs-2e16553ccc8c37df91211c6f63fafd66d69b7105.zip | |
(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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmds.c | 105 |
1 files changed, 7 insertions, 98 deletions
diff --git a/src/cmds.c b/src/cmds.c index abad2cf63af..867a646657b 100644 --- a/src/cmds.c +++ b/src/cmds.c | |||
| @@ -26,7 +26,6 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |||
| 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; |
| @@ -37,10 +36,6 @@ Lisp_Object Vself_insert_face; | |||
| 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 | 38 | ||
| 40 | #ifdef USE_TEXT_PROPERTIES | ||
| 41 | Lisp_Object Qhard; | ||
| 42 | #endif | ||
| 43 | |||
| 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", |
| @@ -236,81 +231,6 @@ Whichever character you type to run this command is inserted.") | |||
| 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 | ||
| @@ -364,11 +284,15 @@ internal_self_insert (c1, noautofill) | |||
| 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 |
| @@ -407,19 +331,6 @@ syms_of_cmds () | |||
| 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'."); |
| @@ -445,14 +356,12 @@ More precisely, a char with closeparen syntax is self-inserted."); | |||
| 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"); |