/* File IO for GNU Emacs.
- Copyright (C) 1985,86,87,88,93,94,95,96 Free Software Foundation, Inc.
+ Copyright (C) 1985,86,87,88,93,94,95,96,1997 Free Software Foundation, Inc.
This file is part of GNU Emacs.
extern int minibuf_level;
+extern int minibuffer_auto_raise;
+
/* These variables describe handlers that have "already" had a chance
to handle the current operation.
/* Decide the coding-system of the file. */
{
- Lisp_Object val = Vcoding_system_for_read;
- if (NILP (current_buffer->enable_multibyte_characters))
- val = Qnil;
- else if (NILP (val))
+ Lisp_Object val;
+
+ if (!NILP (Vcoding_system_for_read))
+ val = Vcoding_system_for_read;
+ else if (NILP (current_buffer->enable_multibyte_characters))
+ val = Qemacs_mule;
+ else
{
Lisp_Object args[6], coding_systems;
setup_coding_system (Fcheck_coding_system (val), &coding);
}
+#ifdef DOS_NT
+ /* Use the conversion type to determine buffer-file-type
+ (find-buffer-file-type is now used to help determine the
+ conversion). */
+ if (coding.type == coding_type_no_conversion)
+ current_buffer->buffer_file_type = Qt;
+ else
+ current_buffer->buffer_file_type = Qnil;
+#endif
+
fd = -1;
#ifndef APOLLO
But if we discover the need for conversion, we give up on this method
and let the following if-statement handle the replace job. */
if (!NILP (replace)
- && (! CODING_REQUIRE_CONVERSION (&coding)
- || (coding.type == coding_type_undecided
- && ! CODING_REQUIRE_EOL_CONVERSION (&coding))
- || (coding.eol_type == CODING_EOL_UNDECIDED
- && ! CODING_REQUIRE_TEXT_CONVERSION (&coding))))
+ && CODING_MAY_REQUIRE_NO_CONVERSION (&coding))
{
int same_at_start = BEGV;
int same_at_end = ZV;
if (coding.type == coding_type_undecided)
detect_coding (&coding, buffer, nread);
if (coding.type != coding_type_undecided
- && CODING_REQUIRE_TEXT_CONVERSION (&coding))
+ && coding.type != coding_type_no_conversion
+ && coding.type != coding_type_emacs_mule)
/* We found that the file should be decoded somehow.
Let's give up here. */
{
if (coding.eol_type == CODING_EOL_UNDECIDED)
detect_eol (&coding, buffer, nread);
if (coding.eol_type != CODING_EOL_UNDECIDED
- && CODING_REQUIRE_EOL_CONVERSION (&coding))
+ && coding.eol_type != CODING_EOL_LF)
/* We found that the format of eol should be decoded.
Let's give up here. */
{
we cannot use this method; giveup and try the other. */
if (same_at_end > same_at_start
&& FETCH_BYTE (same_at_end - 1) >= 0200
- && ! NILP (current_buffer->enable_multibyte_characters))
+ && ! NILP (current_buffer->enable_multibyte_characters)
+ && ! CODING_REQUIRE_NO_CONVERSION (&coding))
giveup_match_end = 1;
break;
}
{
/* We win! We can handle REPLACE the optimized way. */
+ /* Extends the end of non-matching text area to multibyte
+ character boundary. */
+ if (! NILP (current_buffer->enable_multibyte_characters))
+ while (same_at_end < ZV && ! CHAR_HEAD_P (POS_ADDR (same_at_end)))
+ same_at_end++;
+
/* Don't try to reuse the same piece of text twice. */
overlap = same_at_start - BEGV - (same_at_end + st.st_size - ZV);
if (overlap > 0)
how_much += this;
- if (CODING_REQUIRE_CONVERSION (&coding))
+ if (! CODING_REQUIRE_NO_CONVERSION (&coding))
{
int require, produced, consumed;
{
/* try is reserved in some compilers (Microsoft C) */
int trytry = min (total - how_much, READ_BUF_SIZE - unprocessed);
- char *destination = (CODING_REQUIRE_CONVERSION (&coding)
- ? read_buf + unprocessed
- : (char *) (POS_ADDR (PT + inserted - 1) + 1));
+ char *destination = (CODING_REQUIRE_NO_CONVERSION (&coding)
+ ? (char *) (POS_ADDR (PT + inserted - 1) + 1)
+ : read_buf + unprocessed);
int this;
/* Allow quitting out of the actual I/O. */
if (! not_regular)
how_much += this;
- if (CODING_REQUIRE_CONVERSION (&coding))
+ if (! CODING_REQUIRE_NO_CONVERSION (&coding))
{
int require, produced, consumed;
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
struct buffer *given_buffer;
#ifdef DOS_NT
- int buffer_file_type
- = NILP (current_buffer->buffer_file_type) ? O_TEXT : O_BINARY;
+ int buffer_file_type = O_BINARY;
#endif /* DOS_NT */
struct coding_system coding;
{
Lisp_Object val;
- if (auto_saving || NILP (current_buffer->enable_multibyte_characters))
+ if (auto_saving)
val = Qnil;
else if (!NILP (Vcoding_system_for_write))
val = Vcoding_system_for_write;
- else if (!NILP (Flocal_variable_if_set_p (Qbuffer_file_coding_system,
- Qnil)))
- val = Fsymbol_value (Qbuffer_file_coding_system);
+ else if (NILP (current_buffer->enable_multibyte_characters))
+ val = (NILP (Flocal_variable_p (Qbuffer_file_coding_system, Qnil))
+ ? Qnil
+ : Fsymbol_value (Qbuffer_file_coding_system));
else
{
Lisp_Object args[7], coding_systems;
args[3] = filename, args[4] = append, args[5] = visit,
args[6] = lockname;
coding_systems = Ffind_operation_coding_system (7, args);
- val = (CONSP (coding_systems)
+ val = (CONSP (coding_systems) && !NILP (XCONS (coding_systems)->cdr)
? XCONS (coding_systems)->cdr
: current_buffer->buffer_file_coding_system);
}
setup_coding_system (Fcheck_coding_system (val), &coding);
if (!STRINGP (start) && !NILP (current_buffer->selective_display))
coding.selective = 1;
-#ifdef DOS_NT
- if (!NILP (current_buffer->buffer_file_type))
- coding.eol_type = CODING_EOL_LF;
-#endif /* DOS_NT */
}
filename = Fexpand_file_name (filename, Qnil);
/* If we've locked this file for some other buffer,
query before proceeding. */
if (!visiting && EQ (Ffile_locked_p (lockname), Qt))
- call2 (intern ("ask-user-about-lock"), fn, Vuser_login_name);
+ call2 (intern ("ask-user-about-lock"), filename, Vuser_login_name);
lock_file (lockname);
}
save_errno = errno;
}
- if (coding.require_flushing)
+ if (coding.require_flushing && !coding.last_block)
{
/* We have to flush out a data. */
coding.last_block = 1;
return Qnil;
}
+static Lisp_Object
+do_auto_save_unwind_1 (value) /* used as unwind-protect function */
+ Lisp_Object value;
+{
+ minibuffer_auto_raise = XINT (value);
+ return Qnil;
+}
+
DEFUN ("do-auto-save", Fdo_auto_save, Sdo_auto_save, 0, 2, "",
"Auto-save all buffers that need it.\n\
This is all buffers that have auto-saving enabled\n\
Lisp_Object lispstream;
int count = specpdl_ptr - specpdl;
int *ptr;
+ int orig_minibuffer_auto_raise = minibuffer_auto_raise;
/* Ordinarily don't quit within this function,
but don't make it impossible to quit (in case we get hung in I/O). */
}
record_unwind_protect (do_auto_save_unwind, lispstream);
-
+ record_unwind_protect (do_auto_save_unwind_1,
+ make_number (minibuffer_auto_raise));
+ minibuffer_auto_raise = 0;
auto_saving = 1;
/* First, save all files which don't have handlers. If Emacs is
&& NILP (no_message))
{
/* It has shrunk too much; turn off auto-saving here. */
+ minibuffer_auto_raise = orig_minibuffer_auto_raise;
message ("Buffer %s has shrunk a lot; auto save turned off there",
XSTRING (b->name)->data);
+ minibuffer_auto_raise = 0;
/* Turn off auto-saving until there's a real save,
and prevent any more warnings. */
XSETINT (b->save_length, -1);
else if (STRINGP (initial))
{
insdef = initial;
- insdef1 = Fcons (double_dollars (insdef), 0);
+ insdef1 = Fcons (double_dollars (insdef), make_number (0));
}
else
insdef = Qnil, insdef1 = Qnil;
val = Fcompleting_read (prompt, intern ("read-file-name-internal"),
dir, mustmatch, insdef1,
Qfile_name_history, default_filename);
+ /* If Fcompleting_read returned the default string itself
+ (rather than a new string with the same contents),
+ it has to mean that the user typed RET with the minibuffer empty.
+ In that case, we really want to return ""
+ so that commands such as set-visited-file-name can distinguish. */
+ if (EQ (val, default_filename))
+ val = build_string ("");
#ifdef VMS
unbind_to (count, Qnil);