Allow 'make-string' callers force creation of multibyte strings

* src/alloc.c (Fmake_string): Accept additional argument
MULTIBYTE, and produce a multibyte string if it is non-nil.
(make_event_array):
* src/lread.c (read0):
* src/editfns.c (Ftranslate_region_internal):
* src/coding.c (Fdefine_coding_system_internal):
* src/cmds.c (internal_self_insert):
* src/xdisp.c (build_desired_tool_bar_string)
(store_mode_line_string): All C callers changed.

* doc/lispref/strings.texi (Creating Strings): Document the new
optional argument.

* etc/NEWS: Mention the new optional argument.

* lisp/ruler-mode.el (ruler-mode-ruler): Call make-string with the
3rd argument non-nil.
This commit is contained in:
Eli Zaretskii 2017-11-04 15:00:25 +02:00
parent e973c5f5f4
commit bd886c6f56
9 changed files with 41 additions and 27 deletions

View file

@ -121,7 +121,7 @@ character (i.e., an integer), @code{nil} otherwise.
The following functions create strings, either from scratch, or by
putting strings together, or by taking them apart.
@defun make-string count character
@defun make-string count character &optional multibyte
This function returns a string made up of @var{count} repetitions of
@var{character}. If @var{count} is negative, an error is signaled.
@ -132,6 +132,13 @@ This function returns a string made up of @var{count} repetitions of
@result{} ""
@end example
Normally, if @var{character} is an @acronym{ASCII} character, the
result is a unibyte string. But if the optional argument
@var{multibyte} is non-@code{nil}, the function will produce a
multibyte string instead. This is useful when you later need to
concatenate the result with non-@acronym{ASCII} strings or replace
some of its characters with non-@acronym{ASCII} characters.
Other functions to compare with this one include @code{make-vector}
(@pxref{Vectors}) and @code{make-list} (@pxref{Building Lists}).
@end defun

View file

@ -131,6 +131,11 @@ bug on OS X 10.8 and later (Bug#28639).
** The function 'get-free-disk-space' returns now a non-nil value for
remote systems, which support this check.
+++
** The function 'make-string' accepts an additional optional argument.
If the optional third argument is non-nil, 'make-string' will produce
a multibyte string even if its second argument is an ASCII character.
* Changes in Emacs 27.1 on Non-Free Operating Systems

View file

@ -709,20 +709,18 @@ Optional argument PROPS specifies other text properties to apply."
;; Create an "clean" ruler.
(ruler
(propertize
;; FIXME: `make-string' returns a unibyte string if it's ASCII-only,
;; which prevents further `aset' from inserting non-ASCII chars,
;; hence the need for `string-to-multibyte'.
;; https://lists.gnu.org/archive/html/emacs-devel/2017-05/msg00841.html
(string-to-multibyte
;; Make the part of header-line corresponding to the
;; line-number display be blank, not filled with
;; ruler-mode-basic-graduation-char.
(if display-line-numbers
(let* ((lndw (round (line-number-display-width 'columns)))
(s (make-string lndw ?\s)))
(concat s (make-string (- w lndw)
ruler-mode-basic-graduation-char)))
(make-string w ruler-mode-basic-graduation-char)))
;; Make the part of header-line corresponding to the
;; line-number display be blank, not filled with
;; ruler-mode-basic-graduation-char.
(if display-line-numbers
(let* ((lndw (round (line-number-display-width 'columns)))
;; We need a multibyte string here so we could
;; later use aset to insert multibyte characters
;; into that string.
(s (make-string lndw ?\s t)))
(concat s (make-string (- w lndw)
ruler-mode-basic-graduation-char t)))
(make-string w ruler-mode-basic-graduation-char t))
'face 'ruler-mode-default
'local-map ruler-mode-map
'help-echo (cond

View file

@ -2298,11 +2298,13 @@ string_overflow (void)
error ("Maximum string size exceeded");
}
DEFUN ("make-string", Fmake_string, Smake_string, 2, 2, 0,
DEFUN ("make-string", Fmake_string, Smake_string, 2, 3, 0,
doc: /* Return a newly created string of length LENGTH, with INIT in each element.
LENGTH must be an integer.
INIT must be an integer that represents a character. */)
(Lisp_Object length, Lisp_Object init)
INIT must be an integer that represents a character.
If optional argument MULTIBYTE is non-nil, the result will be
a multibyte string even if INIT is an ASCII character. */)
(Lisp_Object length, Lisp_Object init, Lisp_Object multibyte)
{
register Lisp_Object val;
int c;
@ -2312,7 +2314,7 @@ INIT must be an integer that represents a character. */)
CHECK_CHARACTER (init);
c = XFASTINT (init);
if (ASCII_CHAR_P (c))
if (ASCII_CHAR_P (c) && NILP (multibyte))
{
nbytes = XINT (length);
val = make_uninit_string (nbytes);
@ -3930,7 +3932,7 @@ make_event_array (ptrdiff_t nargs, Lisp_Object *args)
{
Lisp_Object result;
result = Fmake_string (make_number (nargs), make_number (0));
result = Fmake_string (make_number (nargs), make_number (0), Qnil);
for (i = 0; i < nargs; i++)
{
SSET (result, i, XINT (args[i]));

View file

@ -439,12 +439,13 @@ internal_self_insert (int c, EMACS_INT n)
int mc = ((NILP (BVAR (current_buffer, enable_multibyte_characters))
&& SINGLE_BYTE_CHAR_P (c))
? UNIBYTE_TO_CHAR (c) : c);
Lisp_Object string = Fmake_string (make_number (n), make_number (mc));
Lisp_Object string = Fmake_string (make_number (n), make_number (mc),
Qnil);
if (spaces_to_insert)
{
tem = Fmake_string (make_number (spaces_to_insert),
make_number (' '));
make_number (' '), Qnil);
string = concat2 (string, tem);
}

View file

@ -10236,7 +10236,7 @@ usage: (define-coding-system-internal ...) */)
ASET (attrs, coding_attr_ccl_encoder, val);
val = args[coding_arg_ccl_valids];
valids = Fmake_string (make_number (256), make_number (0));
valids = Fmake_string (make_number (256), make_number (0), Qnil);
for (tail = val; CONSP (tail); tail = XCDR (tail))
{
int from, to;

View file

@ -3718,7 +3718,7 @@ It returns the number of characters changed. */)
}
else
{
string = Fmake_string (make_number (1), val);
string = Fmake_string (make_number (1), val, Qnil);
}
replace_range (pos, pos + len, string, 1, 0, 1, 0);
pos_byte += SBYTES (string);

View file

@ -2269,7 +2269,7 @@ read0 (Lisp_Object readcharfun)
return val;
xsignal1 (Qinvalid_read_syntax,
Fmake_string (make_number (1), make_number (c)));
Fmake_string (make_number (1), make_number (c), Qnil));
}
/* Grow a read buffer BUF that contains OFFSET useful bytes of data,

View file

@ -12320,7 +12320,7 @@ build_desired_tool_bar_string (struct frame *f)
/* Reuse f->desired_tool_bar_string, if possible. */
if (size < size_needed || NILP (f->desired_tool_bar_string))
fset_desired_tool_bar_string
(f, Fmake_string (make_number (size_needed), make_number (' ')));
(f, Fmake_string (make_number (size_needed), make_number (' '), Qnil));
else
{
AUTO_LIST4 (props, Qdisplay, Qnil, Qmenu_item, Qnil);
@ -23837,7 +23837,8 @@ store_mode_line_string (const char *string, Lisp_Object lisp_string,
if (field_width > len)
{
field_width -= len;
lisp_string = Fmake_string (make_number (field_width), make_number (' '));
lisp_string = Fmake_string (make_number (field_width), make_number (' '),
Qnil);
if (!NILP (props))
Fadd_text_properties (make_number (0), make_number (field_width),
props, lisp_string);