summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2017-11-04 15:00:25 +0200
committerEli Zaretskii <eliz@gnu.org>2017-11-04 15:00:25 +0200
commitbd886c6f566cb1e79e388305f8be05e55753b730 (patch)
tree7e5f7161a7f0e6398de42b94b79385d5b183be1a
parente973c5f5f43ad4d6c98995eea269509b8a258781 (diff)
downloademacs-bd886c6f566cb1e79e388305f8be05e55753b730.tar.gz
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.
-rw-r--r--doc/lispref/strings.texi9
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/ruler-mode.el26
-rw-r--r--src/alloc.c12
-rw-r--r--src/cmds.c5
-rw-r--r--src/coding.c2
-rw-r--r--src/editfns.c2
-rw-r--r--src/lread.c2
-rw-r--r--src/xdisp.c5
9 files changed, 41 insertions, 27 deletions
diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi
index 09c3bdf71f6..31734c5ecf6 100644
--- a/doc/lispref/strings.texi
+++ b/doc/lispref/strings.texi
@@ -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
diff --git a/etc/NEWS b/etc/NEWS
index f9481405e4e..0dd6e36c70a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -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
diff --git a/lisp/ruler-mode.el b/lisp/ruler-mode.el
index 3d27858d0fe..cac91e421e0 100644
--- a/lisp/ruler-mode.el
+++ b/lisp/ruler-mode.el
@@ -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
diff --git a/src/alloc.c b/src/alloc.c
index 0fc79fe68ac..f479226845a 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -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]));
diff --git a/src/cmds.c b/src/cmds.c
index e4c0c866916..f76fe873720 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -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);
}
diff --git a/src/coding.c b/src/coding.c
index d790ad08ea9..1705838ffad 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -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;
diff --git a/src/editfns.c b/src/editfns.c
index e250c91ecbc..84cfbb2c877 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -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);
diff --git a/src/lread.c b/src/lread.c
index 33da8667228..19ed07220cd 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -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,
diff --git a/src/xdisp.c b/src/xdisp.c
index dc23959aadb..900a8dc1637 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -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);