Prefer AUTO_STRING_WITH_LEN to make_formatted_string
* src/buffer.c (Fgenerate_new_buffer_name): * src/filelock.c (get_boot_time): * src/minibuf.c (get_minibuffer): * src/process.c (make_process): * src/xdisp.c (ensure_echo_area_buffers): Prefer AUTO_STRING_WITH_LEN + sprintf to make_formatted_string when either will do.
This commit is contained in:
parent
3c623c26ae
commit
b4c7869e5e
5 changed files with 51 additions and 68 deletions
46
src/buffer.c
46
src/buffer.c
|
@ -1051,44 +1051,36 @@ it is in the sequence to be tried) even if a buffer with that name exists.
|
|||
If NAME begins with a space (i.e., a buffer that is not normally
|
||||
visible to users), then if buffer NAME already exists a random number
|
||||
is first appended to NAME, to speed up finding a non-existent buffer. */)
|
||||
(register Lisp_Object name, Lisp_Object ignore)
|
||||
(Lisp_Object name, Lisp_Object ignore)
|
||||
{
|
||||
register Lisp_Object gentemp, tem, tem2;
|
||||
ptrdiff_t count;
|
||||
char number[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"];
|
||||
Lisp_Object genbase;
|
||||
|
||||
CHECK_STRING (name);
|
||||
|
||||
tem = Fstring_equal (name, ignore);
|
||||
if (!NILP (tem))
|
||||
return name;
|
||||
tem = Fget_buffer (name);
|
||||
if (NILP (tem))
|
||||
if (!NILP (Fstring_equal (name, ignore)) || NILP (Fget_buffer (name)))
|
||||
return name;
|
||||
|
||||
if (!strncmp (SSDATA (name), " ", 1)) /* see bug#1229 */
|
||||
if (SREF (name, 0) != ' ') /* See bug#1229. */
|
||||
genbase = name;
|
||||
else
|
||||
{
|
||||
/* Note fileio.c:make_temp_name does random differently. */
|
||||
tem2 = concat2 (name, make_formatted_string
|
||||
(number, "-%"pI"d",
|
||||
XFASTINT (Frandom (make_number (999999)))));
|
||||
tem = Fget_buffer (tem2);
|
||||
if (NILP (tem))
|
||||
return tem2;
|
||||
char number[sizeof "-999999"];
|
||||
int i = XFASTINT (Frandom (make_number (999999)));
|
||||
AUTO_STRING_WITH_LEN (lnumber, number, sprintf (number, "-%d", i));
|
||||
genbase = concat2 (name, lnumber);
|
||||
if (NILP (Fget_buffer (genbase)))
|
||||
return genbase;
|
||||
}
|
||||
else
|
||||
tem2 = name;
|
||||
|
||||
count = 1;
|
||||
while (1)
|
||||
for (ptrdiff_t count = 1; ; count++)
|
||||
{
|
||||
gentemp = concat2 (tem2, make_formatted_string
|
||||
(number, "<%"pD"d>", ++count));
|
||||
tem = Fstring_equal (gentemp, ignore);
|
||||
if (!NILP (tem))
|
||||
return gentemp;
|
||||
tem = Fget_buffer (gentemp);
|
||||
if (NILP (tem))
|
||||
char number[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"];
|
||||
AUTO_STRING_WITH_LEN (lnumber, number,
|
||||
sprintf (number, "<%"pD"d>", count));
|
||||
Lisp_Object gentemp = concat2 (genbase, lnumber);
|
||||
if (!NILP (Fstring_equal (gentemp, ignore))
|
||||
|| NILP (Fget_buffer (gentemp)))
|
||||
return gentemp;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -191,14 +191,11 @@ get_boot_time (void)
|
|||
/* If we did not find a boot time in wtmp, look at wtmp, and so on. */
|
||||
for (counter = 0; counter < 20 && ! boot_time; counter++)
|
||||
{
|
||||
Lisp_Object filename = Qnil;
|
||||
bool delete_flag = false;
|
||||
char cmd_string[sizeof WTMP_FILE ".19.gz"];
|
||||
Lisp_Object tempname, filename;
|
||||
bool delete_flag = 0;
|
||||
|
||||
filename = Qnil;
|
||||
|
||||
tempname = make_formatted_string
|
||||
(cmd_string, "%s.%d", WTMP_FILE, counter);
|
||||
AUTO_STRING_WITH_LEN (tempname, cmd_string,
|
||||
sprintf (cmd_string, "%s.%d", WTMP_FILE, counter));
|
||||
if (! NILP (Ffile_exists_p (tempname)))
|
||||
filename = tempname;
|
||||
else
|
||||
|
@ -218,7 +215,7 @@ get_boot_time (void)
|
|||
CALLN (Fcall_process, build_string ("gzip"), Qnil,
|
||||
list2 (QCfile, filename), Qnil,
|
||||
build_string ("-cd"), tempname);
|
||||
delete_flag = 1;
|
||||
delete_flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -742,27 +742,25 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
|
|||
}
|
||||
|
||||
/* Return a buffer to be used as the minibuffer at depth `depth'.
|
||||
depth = 0 is the lowest allowed argument, and that is the value
|
||||
used for nonrecursive minibuffer invocations. */
|
||||
depth = 0 is the lowest allowed argument, and that is the value
|
||||
used for nonrecursive minibuffer invocations. */
|
||||
|
||||
Lisp_Object
|
||||
get_minibuffer (EMACS_INT depth)
|
||||
{
|
||||
Lisp_Object tail, num, buf;
|
||||
char name[sizeof " *Minibuf-*" + INT_STRLEN_BOUND (EMACS_INT)];
|
||||
|
||||
XSETFASTINT (num, depth);
|
||||
tail = Fnthcdr (num, Vminibuffer_list);
|
||||
Lisp_Object tail = Fnthcdr (make_number (depth), Vminibuffer_list);
|
||||
if (NILP (tail))
|
||||
{
|
||||
tail = list1 (Qnil);
|
||||
Vminibuffer_list = nconc2 (Vminibuffer_list, tail);
|
||||
}
|
||||
buf = Fcar (tail);
|
||||
Lisp_Object buf = Fcar (tail);
|
||||
if (NILP (buf) || !BUFFER_LIVE_P (XBUFFER (buf)))
|
||||
{
|
||||
buf = Fget_buffer_create
|
||||
(make_formatted_string (name, " *Minibuf-%"pI"d*", depth));
|
||||
static char const name_fmt[] = " *Minibuf-%"pI"d*";
|
||||
char name[sizeof name_fmt + INT_STRLEN_BOUND (EMACS_INT)];
|
||||
AUTO_STRING_WITH_LEN (lname, name, sprintf (name, name_fmt, depth));
|
||||
buf = Fget_buffer_create (lname);
|
||||
|
||||
/* Although the buffer's name starts with a space, undo should be
|
||||
enabled in it. */
|
||||
|
|
|
@ -675,12 +675,7 @@ allocate_process (void)
|
|||
static Lisp_Object
|
||||
make_process (Lisp_Object name)
|
||||
{
|
||||
register Lisp_Object val, tem, name1;
|
||||
register struct Lisp_Process *p;
|
||||
char suffix[sizeof "<>" + INT_STRLEN_BOUND (printmax_t)];
|
||||
printmax_t i;
|
||||
|
||||
p = allocate_process ();
|
||||
struct Lisp_Process *p = allocate_process ();
|
||||
/* Initialize Lisp data. Note that allocate_process initializes all
|
||||
Lisp data to nil, so do it only for slots which should not be nil. */
|
||||
pset_status (p, Qrun);
|
||||
|
@ -690,7 +685,7 @@ make_process (Lisp_Object name)
|
|||
non-Lisp data, so do it only for slots which should not be zero. */
|
||||
p->infd = -1;
|
||||
p->outfd = -1;
|
||||
for (i = 0; i < PROCESS_OPEN_FDS; i++)
|
||||
for (int i = 0; i < PROCESS_OPEN_FDS; i++)
|
||||
p->open_fd[i] = -1;
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
|
@ -700,17 +695,22 @@ make_process (Lisp_Object name)
|
|||
|
||||
/* If name is already in use, modify it until it is unused. */
|
||||
|
||||
name1 = name;
|
||||
for (i = 1; ; i++)
|
||||
Lisp_Object name1 = name;
|
||||
for (printmax_t i = 1; ; i++)
|
||||
{
|
||||
tem = Fget_process (name1);
|
||||
if (NILP (tem)) break;
|
||||
name1 = concat2 (name, make_formatted_string (suffix, "<%"pMd">", i));
|
||||
Lisp_Object tem = Fget_process (name1);
|
||||
if (NILP (tem))
|
||||
break;
|
||||
char const suffix_fmt[] = "<%"pMd">";
|
||||
char suffix[sizeof suffix_fmt + INT_STRLEN_BOUND (printmax_t)];
|
||||
AUTO_STRING_WITH_LEN (lsuffix, suffix, sprintf (suffix, suffix_fmt, i));
|
||||
name1 = concat2 (name, lsuffix);
|
||||
}
|
||||
name = name1;
|
||||
pset_name (p, name);
|
||||
pset_sentinel (p, Qinternal_default_process_sentinel);
|
||||
pset_filter (p, Qinternal_default_process_filter);
|
||||
Lisp_Object val;
|
||||
XSETPROCESS (val, p);
|
||||
Vprocess_alist = Fcons (Fcons (name, val), Vprocess_alist);
|
||||
return val;
|
||||
|
|
18
src/xdisp.c
18
src/xdisp.c
|
@ -10528,25 +10528,21 @@ update_echo_area (void)
|
|||
static void
|
||||
ensure_echo_area_buffers (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 2; ++i)
|
||||
for (int i = 0; i < 2; i++)
|
||||
if (!BUFFERP (echo_buffer[i])
|
||||
|| !BUFFER_LIVE_P (XBUFFER (echo_buffer[i])))
|
||||
{
|
||||
char name[30];
|
||||
Lisp_Object old_buffer;
|
||||
int j;
|
||||
|
||||
old_buffer = echo_buffer[i];
|
||||
echo_buffer[i] = Fget_buffer_create
|
||||
(make_formatted_string (name, " *Echo Area %d*", i));
|
||||
Lisp_Object old_buffer = echo_buffer[i];
|
||||
static char const name_fmt[] = " *Echo Area %d*";
|
||||
char name[sizeof name_fmt + INT_STRLEN_BOUND (int)];
|
||||
AUTO_STRING_WITH_LEN (lname, name, sprintf (name, name_fmt, i));
|
||||
echo_buffer[i] = Fget_buffer_create (lname);
|
||||
bset_truncate_lines (XBUFFER (echo_buffer[i]), Qnil);
|
||||
/* to force word wrap in echo area -
|
||||
it was decided to postpone this*/
|
||||
/* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
|
||||
|
||||
for (j = 0; j < 2; ++j)
|
||||
for (int j = 0; j < 2; j++)
|
||||
if (EQ (old_buffer, echo_area_buffer[j]))
|
||||
echo_area_buffer[j] = echo_buffer[i];
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue