aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2017-11-04 15:00:25 +0200
committerEli Zaretskii2017-11-04 15:00:25 +0200
commitbd886c6f566cb1e79e388305f8be05e55753b730 (patch)
tree7e5f7161a7f0e6398de42b94b79385d5b183be1a
parente973c5f5f43ad4d6c98995eea269509b8a258781 (diff)
downloademacs-bd886c6f566cb1e79e388305f8be05e55753b730.tar.gz
emacs-bd886c6f566cb1e79e388305f8be05e55753b730.zip
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.
121 The following functions create strings, either from scratch, or by 121 The following functions create strings, either from scratch, or by
122putting strings together, or by taking them apart. 122putting strings together, or by taking them apart.
123 123
124@defun make-string count character 124@defun make-string count character &optional multibyte
125This function returns a string made up of @var{count} repetitions of 125This function returns a string made up of @var{count} repetitions of
126@var{character}. If @var{count} is negative, an error is signaled. 126@var{character}. If @var{count} is negative, an error is signaled.
127 127
@@ -132,6 +132,13 @@ This function returns a string made up of @var{count} repetitions of
132 @result{} "" 132 @result{} ""
133@end example 133@end example
134 134
135 Normally, if @var{character} is an @acronym{ASCII} character, the
136result is a unibyte string. But if the optional argument
137@var{multibyte} is non-@code{nil}, the function will produce a
138multibyte string instead. This is useful when you later need to
139concatenate the result with non-@acronym{ASCII} strings or replace
140some of its characters with non-@acronym{ASCII} characters.
141
135 Other functions to compare with this one include @code{make-vector} 142 Other functions to compare with this one include @code{make-vector}
136(@pxref{Vectors}) and @code{make-list} (@pxref{Building Lists}). 143(@pxref{Vectors}) and @code{make-list} (@pxref{Building Lists}).
137@end defun 144@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).
131** The function 'get-free-disk-space' returns now a non-nil value for 131** The function 'get-free-disk-space' returns now a non-nil value for
132remote systems, which support this check. 132remote systems, which support this check.
133 133
134+++
135** The function 'make-string' accepts an additional optional argument.
136If the optional third argument is non-nil, 'make-string' will produce
137a multibyte string even if its second argument is an ASCII character.
138
134 139
135* Changes in Emacs 27.1 on Non-Free Operating Systems 140* Changes in Emacs 27.1 on Non-Free Operating Systems
136 141
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."
709 ;; Create an "clean" ruler. 709 ;; Create an "clean" ruler.
710 (ruler 710 (ruler
711 (propertize 711 (propertize
712 ;; FIXME: `make-string' returns a unibyte string if it's ASCII-only, 712 ;; Make the part of header-line corresponding to the
713 ;; which prevents further `aset' from inserting non-ASCII chars, 713 ;; line-number display be blank, not filled with
714 ;; hence the need for `string-to-multibyte'. 714 ;; ruler-mode-basic-graduation-char.
715 ;; https://lists.gnu.org/archive/html/emacs-devel/2017-05/msg00841.html 715 (if display-line-numbers
716 (string-to-multibyte 716 (let* ((lndw (round (line-number-display-width 'columns)))
717 ;; Make the part of header-line corresponding to the 717 ;; We need a multibyte string here so we could
718 ;; line-number display be blank, not filled with 718 ;; later use aset to insert multibyte characters
719 ;; ruler-mode-basic-graduation-char. 719 ;; into that string.
720 (if display-line-numbers 720 (s (make-string lndw ?\s t)))
721 (let* ((lndw (round (line-number-display-width 'columns))) 721 (concat s (make-string (- w lndw)
722 (s (make-string lndw ?\s))) 722 ruler-mode-basic-graduation-char t)))
723 (concat s (make-string (- w lndw) 723 (make-string w ruler-mode-basic-graduation-char t))
724 ruler-mode-basic-graduation-char)))
725 (make-string w ruler-mode-basic-graduation-char)))
726 'face 'ruler-mode-default 724 'face 'ruler-mode-default
727 'local-map ruler-mode-map 725 'local-map ruler-mode-map
728 'help-echo (cond 726 '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)
2298 error ("Maximum string size exceeded"); 2298 error ("Maximum string size exceeded");
2299} 2299}
2300 2300
2301DEFUN ("make-string", Fmake_string, Smake_string, 2, 2, 0, 2301DEFUN ("make-string", Fmake_string, Smake_string, 2, 3, 0,
2302 doc: /* Return a newly created string of length LENGTH, with INIT in each element. 2302 doc: /* Return a newly created string of length LENGTH, with INIT in each element.
2303LENGTH must be an integer. 2303LENGTH must be an integer.
2304INIT must be an integer that represents a character. */) 2304INIT must be an integer that represents a character.
2305 (Lisp_Object length, Lisp_Object init) 2305If optional argument MULTIBYTE is non-nil, the result will be
2306a multibyte string even if INIT is an ASCII character. */)
2307 (Lisp_Object length, Lisp_Object init, Lisp_Object multibyte)
2306{ 2308{
2307 register Lisp_Object val; 2309 register Lisp_Object val;
2308 int c; 2310 int c;
@@ -2312,7 +2314,7 @@ INIT must be an integer that represents a character. */)
2312 CHECK_CHARACTER (init); 2314 CHECK_CHARACTER (init);
2313 2315
2314 c = XFASTINT (init); 2316 c = XFASTINT (init);
2315 if (ASCII_CHAR_P (c)) 2317 if (ASCII_CHAR_P (c) && NILP (multibyte))
2316 { 2318 {
2317 nbytes = XINT (length); 2319 nbytes = XINT (length);
2318 val = make_uninit_string (nbytes); 2320 val = make_uninit_string (nbytes);
@@ -3930,7 +3932,7 @@ make_event_array (ptrdiff_t nargs, Lisp_Object *args)
3930 { 3932 {
3931 Lisp_Object result; 3933 Lisp_Object result;
3932 3934
3933 result = Fmake_string (make_number (nargs), make_number (0)); 3935 result = Fmake_string (make_number (nargs), make_number (0), Qnil);
3934 for (i = 0; i < nargs; i++) 3936 for (i = 0; i < nargs; i++)
3935 { 3937 {
3936 SSET (result, i, XINT (args[i])); 3938 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)
439 int mc = ((NILP (BVAR (current_buffer, enable_multibyte_characters)) 439 int mc = ((NILP (BVAR (current_buffer, enable_multibyte_characters))
440 && SINGLE_BYTE_CHAR_P (c)) 440 && SINGLE_BYTE_CHAR_P (c))
441 ? UNIBYTE_TO_CHAR (c) : c); 441 ? UNIBYTE_TO_CHAR (c) : c);
442 Lisp_Object string = Fmake_string (make_number (n), make_number (mc)); 442 Lisp_Object string = Fmake_string (make_number (n), make_number (mc),
443 Qnil);
443 444
444 if (spaces_to_insert) 445 if (spaces_to_insert)
445 { 446 {
446 tem = Fmake_string (make_number (spaces_to_insert), 447 tem = Fmake_string (make_number (spaces_to_insert),
447 make_number (' ')); 448 make_number (' '), Qnil);
448 string = concat2 (string, tem); 449 string = concat2 (string, tem);
449 } 450 }
450 451
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 ...) */)
10236 ASET (attrs, coding_attr_ccl_encoder, val); 10236 ASET (attrs, coding_attr_ccl_encoder, val);
10237 10237
10238 val = args[coding_arg_ccl_valids]; 10238 val = args[coding_arg_ccl_valids];
10239 valids = Fmake_string (make_number (256), make_number (0)); 10239 valids = Fmake_string (make_number (256), make_number (0), Qnil);
10240 for (tail = val; CONSP (tail); tail = XCDR (tail)) 10240 for (tail = val; CONSP (tail); tail = XCDR (tail))
10241 { 10241 {
10242 int from, to; 10242 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. */)
3718 } 3718 }
3719 else 3719 else
3720 { 3720 {
3721 string = Fmake_string (make_number (1), val); 3721 string = Fmake_string (make_number (1), val, Qnil);
3722 } 3722 }
3723 replace_range (pos, pos + len, string, 1, 0, 1, 0); 3723 replace_range (pos, pos + len, string, 1, 0, 1, 0);
3724 pos_byte += SBYTES (string); 3724 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)
2269 return val; 2269 return val;
2270 2270
2271 xsignal1 (Qinvalid_read_syntax, 2271 xsignal1 (Qinvalid_read_syntax,
2272 Fmake_string (make_number (1), make_number (c))); 2272 Fmake_string (make_number (1), make_number (c), Qnil));
2273} 2273}
2274 2274
2275/* Grow a read buffer BUF that contains OFFSET useful bytes of data, 2275/* 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)
12320 /* Reuse f->desired_tool_bar_string, if possible. */ 12320 /* Reuse f->desired_tool_bar_string, if possible. */
12321 if (size < size_needed || NILP (f->desired_tool_bar_string)) 12321 if (size < size_needed || NILP (f->desired_tool_bar_string))
12322 fset_desired_tool_bar_string 12322 fset_desired_tool_bar_string
12323 (f, Fmake_string (make_number (size_needed), make_number (' '))); 12323 (f, Fmake_string (make_number (size_needed), make_number (' '), Qnil));
12324 else 12324 else
12325 { 12325 {
12326 AUTO_LIST4 (props, Qdisplay, Qnil, Qmenu_item, Qnil); 12326 AUTO_LIST4 (props, Qdisplay, Qnil, Qmenu_item, Qnil);
@@ -23837,7 +23837,8 @@ store_mode_line_string (const char *string, Lisp_Object lisp_string,
23837 if (field_width > len) 23837 if (field_width > len)
23838 { 23838 {
23839 field_width -= len; 23839 field_width -= len;
23840 lisp_string = Fmake_string (make_number (field_width), make_number (' ')); 23840 lisp_string = Fmake_string (make_number (field_width), make_number (' '),
23841 Qnil);
23841 if (!NILP (props)) 23842 if (!NILP (props))
23842 Fadd_text_properties (make_number (0), make_number (field_width), 23843 Fadd_text_properties (make_number (0), make_number (field_width),
23843 props, lisp_string); 23844 props, lisp_string);