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.
@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
** 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.
+
\f
* Changes in Emacs 27.1 on Non-Free Operating Systems
;; 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
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;
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);
{
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]));
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);
}
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;
}
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);
return val;
xsignal1 (Qinvalid_read_syntax,
- Fmake_string (make_number (1), make_number (c)));
+ Fmake_string (make_number (1), make_number (c), Qnil));
}
\f
/* Grow a read buffer BUF that contains OFFSET useful bytes of data,
/* 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);
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);