unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* insert-char as alias to ucs-insert
@ 2012-07-12 14:00 René Kyllingstad
  2012-07-14  2:07 ` Leo
  0 siblings, 1 reply; 10+ messages in thread
From: René Kyllingstad @ 2012-07-12 14:00 UTC (permalink / raw)
  To: Emacs Dev [emacs-devel]


[-- Attachment #1.1: Type: text/plain, Size: 232 bytes --]

Hi,

I have a hard time remembering the name of ucs-insert. What about adding a
insert-char alias?

2012-07-12  René Kyllingstad  <rene@kyllingstad.com>

* international/mule-cmds.el (insert-char): New alias.


-- René

[-- Attachment #1.2: Type: text/html, Size: 444 bytes --]

[-- Attachment #2: insert-char-alias.patch --]
[-- Type: application/octet-stream, Size: 576 bytes --]

=== modified file 'lisp/international/mule-cmds.el'
*** lisp/international/mule-cmds.el	2012-06-27 21:15:13 +0000
--- lisp/international/mule-cmds.el	2012-07-11 14:59:47 +0000
*************** point or a number in hash notation, e.g.
*** 2954,2959 ****
--- 2954,2961 ----
       (t
        (cdr (assoc-string input (ucs-names) t))))))
  
+ (defalias 'insert-char 'ucs-insert)
+ 
  (defun ucs-insert (character &optional count inherit)
    "Insert COUNT copies of CHARACTER of the given Unicode code point.
  Interactively, prompts for a Unicode character name or a hex number


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: insert-char as alias to ucs-insert
  2012-07-12 14:00 insert-char as alias to ucs-insert René Kyllingstad
@ 2012-07-14  2:07 ` Leo
  2012-07-14 15:57   ` Chong Yidong
  0 siblings, 1 reply; 10+ messages in thread
From: Leo @ 2012-07-14  2:07 UTC (permalink / raw)
  To: emacs-devel

On 2012-07-12 22:00 +0800, René Kyllingstad wrote:
> I have a hard time remembering the name of ucs-insert. What about adding a
> insert-char alias?
>
> 2012-07-12  René Kyllingstad  <rene@kyllingstad.com>
>
> * international/mule-cmds.el (insert-char): New alias.

I don't think this is worth it.

You can put any aliases in your .emacs. BTW, insert-char is a C
primitive.

Leo




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: insert-char as alias to ucs-insert
  2012-07-14  2:07 ` Leo
@ 2012-07-14 15:57   ` Chong Yidong
  2012-07-15 16:35     ` René Kyllingstad
  0 siblings, 1 reply; 10+ messages in thread
From: Chong Yidong @ 2012-07-14 15:57 UTC (permalink / raw)
  To: Leo; +Cc: emacs-devel, Rene

Leo <sdl.web@gmail.com> writes:

> On 2012-07-12 22:00 +0800, René Kyllingstad wrote:
>> I have a hard time remembering the name of ucs-insert. What about adding a
>> insert-char alias?
>>
>> 2012-07-12  René Kyllingstad  <rene@kyllingstad.com>
>>
>> * international/mule-cmds.el (insert-char): New alias.
>
> I don't think this is worth it.
>
> You can put any aliases in your .emacs. BTW, insert-char is a C
> primitive.

Happily, ucs-insert has the same arglist as insert-char.  So we could
make insert-char interactive, with an interactive spec that performs the
ucs-insert character-reading magic.  Then ucs-insert could be made into
an alias for insert-char.

Patch welcome.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: insert-char as alias to ucs-insert
  2012-07-14 15:57   ` Chong Yidong
@ 2012-07-15 16:35     ` René Kyllingstad
  2012-07-16  9:16       ` Chong Yidong
  0 siblings, 1 reply; 10+ messages in thread
From: René Kyllingstad @ 2012-07-15 16:35 UTC (permalink / raw)
  To: Chong Yidong; +Cc: Leo, emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 1194 bytes --]

On Sat, Jul 14, 2012 at 5:57 PM, Chong Yidong <cyd@gnu.org> wrote:

> Leo <sdl.web@gmail.com> writes:
>
> > On 2012-07-12 22:00 +0800, René Kyllingstad wrote:
> >> I have a hard time remembering the name of ucs-insert. What about
> adding a
> >> insert-char alias?
> >>
> >> 2012-07-12  René Kyllingstad  <rene@kyllingstad.com>
> >>
> >> * international/mule-cmds.el (insert-char): New alias.
> >
> > I don't think this is worth it.
> >
> > You can put any aliases in your .emacs. BTW, insert-char is a C
> > primitive.
>
> Happily, ucs-insert has the same arglist as insert-char.  So we could
> make insert-char interactive, with an interactive spec that performs the
> ucs-insert character-reading magic.  Then ucs-insert could be made into
> an alias for insert-char.
>
> Patch welcome.
>

Patch attached.


-- René
2012-07-15  René Kyllingstad  <rene@kyllingstad.com>

* editfns.c (Finsert_char): Add interactive entry
          of unicode characters, moved from ucs-insert.

2012-07-15  René Kyllingstad  <rene@kyllingstad.com>

* international/mule-cmds.el (ucs-insert): Move interactive
  functionality to insert-char, and make this an alias.

[-- Attachment #1.2: Type: text/html, Size: 2399 bytes --]

[-- Attachment #2: insert-char-interactive.patch --]
[-- Type: application/octet-stream, Size: 4278 bytes --]

=== modified file 'lisp/international/mule-cmds.el'
*** lisp/international/mule-cmds.el	2012-06-27 21:15:13 +0000
--- lisp/international/mule-cmds.el	2012-07-15 15:31:27 +0000
*************** point or a number in hash notation, e.g.
*** 2954,2996 ****
       (t
        (cdr (assoc-string input (ucs-names) t))))))
  
! (defun ucs-insert (character &optional count inherit)
!   "Insert COUNT copies of CHARACTER of the given Unicode code point.
! Interactively, prompts for a Unicode character name or a hex number
! using `read-char-by-name'.
! 
! You can type a few of the first letters of the Unicode name and
! use completion.  If you type a substring of the Unicode name
! preceded by an asterisk `*' and use completion, it will show all
! the characters whose names include that substring, not necessarily
! at the beginning of the name.
! 
! This function also accepts a hexadecimal number of Unicode code
! point or a number in hash notation, e.g. #o21430 for octal,
! #x2318 for hex, or #10r8984 for decimal.
! 
! The optional third arg INHERIT (non-nil when called interactively),
! says to inherit text properties from adjoining text, if those
! properties are sticky."
!   (interactive
!    (list (read-char-by-name "Unicode (name or hex): ")
! 	 (prefix-numeric-value current-prefix-arg)
! 	 t))
!   (unless count (setq count 1))
!   (if (and (stringp character)
! 	   (string-match-p "\\`[0-9a-fA-F]+\\'" character))
!       (setq character (string-to-number character 16)))
!   (cond
!    ((null character)
!     (error "Not a Unicode character"))
!    ((not (integerp character))
!     (error "Not a Unicode character code: %S" character))
!    ((or (< character 0) (> character #x10FFFF))
!     (error "Not a Unicode character code: 0x%X" character)))
!   (if inherit
!       (dotimes (i count) (insert-and-inherit character))
!     (dotimes (i count) (insert character))))
! 
! (define-key ctl-x-map "8\r" 'ucs-insert)
  
  ;;; mule-cmds.el ends here
--- 2954,2960 ----
       (t
        (cdr (assoc-string input (ucs-names) t))))))
  
! (defalias 'ucs-insert 'insert-char)
! (define-key ctl-x-map "8\r" 'insert-char)
  
  ;;; mule-cmds.el ends here

=== modified file 'src/editfns.c'
*** src/editfns.c	2012-07-10 23:24:36 +0000
--- src/editfns.c	2012-07-15 16:03:00 +0000
*************** usage: (insert-before-markers-and-inheri
*** 2368,2378 ****
    return Qnil;
  }
  \f
! DEFUN ("insert-char", Finsert_char, Sinsert_char, 2, 3, 0,
!        doc: /* Insert COUNT copies of CHARACTER.
  Point, and before-insertion markers, are relocated as in the function `insert'.
! The optional third arg INHERIT, if non-nil, says to inherit text properties
! from adjoining text, if those properties are sticky.  */)
    (Lisp_Object character, Lisp_Object count, Lisp_Object inherit)
  {
    int i, stringlen;
--- 2368,2397 ----
    return Qnil;
  }
  \f
! DEFUN ("insert-char", Finsert_char, Sinsert_char, 1, 3,
!        "(list (read-char-by-name \"Unicode (name or hex): \")\
! 	 (prefix-numeric-value current-prefix-arg)\
! 	 t))",
!        doc: /*Insert COUNT copies of CHARACTER.
! Interactively, prompts for a Unicode character name or a hex number
! using `read-char-by-name'.
! 
! You can type a few of the first letters of the Unicode name and
! use completion.  If you type a substring of the Unicode name
! preceded by an asterisk `*' and use completion, it will show all
! the characters whose names include that substring, not necessarily
! at the beginning of the name.
! 
! This function also accepts a hexadecimal number of Unicode code
! point or a number in hash notation, e.g. #o21430 for octal,
! #x2318 for hex, or #10r8984 for decimal.
! 
! The optional third arg INHERIT (non-nil when called interactively),
! says to inherit text properties from adjoining text, if those
! properties are sticky.
! 
  Point, and before-insertion markers, are relocated as in the function `insert'.
! */)
    (Lisp_Object character, Lisp_Object count, Lisp_Object inherit)
  {
    int i, stringlen;
*************** from adjoining text, if those properties
*** 2382,2387 ****
--- 2401,2408 ----
    char string[4000];
  
    CHECK_CHARACTER (character);
+   if (NILP (count))
+     XSETFASTINT (count, 1);
    CHECK_NUMBER (count);
    c = XFASTINT (character);
  


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: insert-char as alias to ucs-insert
  2012-07-15 16:35     ` René Kyllingstad
@ 2012-07-16  9:16       ` Chong Yidong
  2012-07-16 10:31         ` Thien-Thi Nguyen
  0 siblings, 1 reply; 10+ messages in thread
From: Chong Yidong @ 2012-07-16  9:16 UTC (permalink / raw)
  To: Rene; +Cc: Leo, emacs-devel

René Kyllingstad <Rene@Kyllingstad.com> writes:

>     Happily, ucs-insert has the same arglist as insert-char. So we
>     could make insert-char interactive, with an interactive spec that
>     performs the ucs-insert character-reading magic. Then ucs-insert
>     could be made into an alias for insert-char.
>     
>     Patch welcome.
>
> Patch attached.

Thanks, this looks almost completely straightforward.

One significant difference is that ucs-insert errors out if the argument
is larger than #x10FFFF, whereas insert-char does not---it tests for
CHARACTERP, which accepts up to #x3FFFFF.  That's because the code space
of utf-8-emacs is larger than Unicode.  Off the top of my head, making
it more permissive is OK, i.e. we should allow insert-char with
arguments of up to #x3FFFFF.  Anyone have a different opinion?



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: insert-char as alias to ucs-insert
  2012-07-16  9:16       ` Chong Yidong
@ 2012-07-16 10:31         ` Thien-Thi Nguyen
  2012-07-16 15:58           ` Eli Zaretskii
  2012-07-16 16:14           ` Stefan Monnier
  0 siblings, 2 replies; 10+ messages in thread
From: Thien-Thi Nguyen @ 2012-07-16 10:31 UTC (permalink / raw)
  To: Chong Yidong; +Cc: emacs-devel, Leo, Rene

() Chong Yidong <cyd@gnu.org>
() Mon, 16 Jul 2012 17:16:20 +0800

   One significant difference is that ucs-insert errors out if the
   argument is larger than #x10FFFF, whereas insert-char does
   not---it tests for CHARACTERP, which accepts up to #x3FFFFF.
   That's because the code space of utf-8-emacs is larger than
   Unicode.  Off the top of my head, making it more permissive is
   OK, i.e. we should allow insert-char with arguments of up to
   #x3FFFFF.  Anyone have a different opinion?

So this would break code that depends on ‘ucs-insert’ throwing
this range error.  Is there a lot of code like that in the wild?
Regardless, it feels wrong to discard this check.  Better IMHO
would be to factor out the common bits (i.e., ‘ucs-insert’ w/
specified range) into a separate func and have both ‘ucs-insert’
and ‘insert-char’ call that, specifying their expected range.

Otherwise, we would need to document ‘ucs-insert’ as not actually
respecting "UCS" range, i.e., a misnomer.  Somewhat suboptimal...



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: insert-char as alias to ucs-insert
  2012-07-16 10:31         ` Thien-Thi Nguyen
@ 2012-07-16 15:58           ` Eli Zaretskii
  2012-07-16 19:13             ` Thien-Thi Nguyen
  2012-07-17 13:11             ` Jason Rumney
  2012-07-16 16:14           ` Stefan Monnier
  1 sibling, 2 replies; 10+ messages in thread
From: Eli Zaretskii @ 2012-07-16 15:58 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: Rene, cyd, sdl.web, emacs-devel

> From: Thien-Thi Nguyen <ttn@gnuvola.org>
> Date: Mon, 16 Jul 2012 12:31:04 +0200
> Cc: emacs-devel@gnu.org, Leo <sdl.web@gmail.com>, Rene@Kyllingstad.com
> 
> () Chong Yidong <cyd@gnu.org>
> () Mon, 16 Jul 2012 17:16:20 +0800
> 
>    One significant difference is that ucs-insert errors out if the
>    argument is larger than #x10FFFF, whereas insert-char does
>    not---it tests for CHARACTERP, which accepts up to #x3FFFFF.
>    That's because the code space of utf-8-emacs is larger than
>    Unicode.  Off the top of my head, making it more permissive is
>    OK, i.e. we should allow insert-char with arguments of up to
>    #x3FFFFF.  Anyone have a different opinion?
> 
> So this would break code that depends on ‘ucs-insert’ throwing
> this range error.  Is there a lot of code like that in the wild?

If there is such a code, it is already broken, because a character in
Emacs can really have values up to #x3FFFFF.

> Regardless, it feels wrong to discard this check.

Can you explain why?




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: insert-char as alias to ucs-insert
  2012-07-16 10:31         ` Thien-Thi Nguyen
  2012-07-16 15:58           ` Eli Zaretskii
@ 2012-07-16 16:14           ` Stefan Monnier
  1 sibling, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2012-07-16 16:14 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: Rene, Chong Yidong, Leo, emacs-devel

>    #x3FFFFF.  Anyone have a different opinion?

Just make ucs-insert into an obsolete alias.

> So this would break code that depends on ‘ucs-insert’ throwing
> this range error.

I highly doubt there is such code out there.


        Stefan



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: insert-char as alias to ucs-insert
  2012-07-16 15:58           ` Eli Zaretskii
@ 2012-07-16 19:13             ` Thien-Thi Nguyen
  2012-07-17 13:11             ` Jason Rumney
  1 sibling, 0 replies; 10+ messages in thread
From: Thien-Thi Nguyen @ 2012-07-16 19:13 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Rene, cyd, sdl.web, emacs-devel

() Eli Zaretskii <eliz@gnu.org>
() Mon, 16 Jul 2012 18:58:45 +0300

   > So this would break code that depends on ‘ucs-insert’ throwing
   > this range error.  Is there a lot of code like that in the wild?

   If there is such a code, it is already broken, because a character in
   Emacs can really have values up to #x3FFFFF.

Perhaps that code was not interested in Emacs' abilities per se,
but in filtering valid Unicode characters...

   > Regardless, it feels wrong to discard this check.

   Can you explain why?

Not really.  It's just a gut feeling that the name of the function
(includes "UCS") should not need to have to be explained away in
the documentation:

(defun ucs-insert (CHARACTER ...)
  "Insert COUNT copies of CHARACTER of the given Unicode code point.
Actually, CHARACTER can also be up to #x3FFFFF, which is not properly
Unicode, but you get the idea [insert other convulsions here]..."
   ...)

I see in another message by Stefan Monnier the idea to declare
‘ucs-insert’ obsolete, reducing confusion for stickler programmers
(like me).  That's fine, too.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: insert-char as alias to ucs-insert
  2012-07-16 15:58           ` Eli Zaretskii
  2012-07-16 19:13             ` Thien-Thi Nguyen
@ 2012-07-17 13:11             ` Jason Rumney
  1 sibling, 0 replies; 10+ messages in thread
From: Jason Rumney @ 2012-07-17 13:11 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: sdl.web, cyd, emacs-devel, Thien-Thi Nguyen, Rene

Eli Zaretskii <eliz@gnu.org> writes:

>> So this would break code that depends on ‘ucs-insert’ throwing
>> this range error.  Is there a lot of code like that in the wild?
>
> If there is such a code, it is already broken, because a character in
> Emacs can really have values up to #x3FFFFF.

Which is why code that expects an error for non-Unicode characters uses
ucs-insert, not insert-char.  There is nothing broken about that.




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-07-17 13:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-12 14:00 insert-char as alias to ucs-insert René Kyllingstad
2012-07-14  2:07 ` Leo
2012-07-14 15:57   ` Chong Yidong
2012-07-15 16:35     ` René Kyllingstad
2012-07-16  9:16       ` Chong Yidong
2012-07-16 10:31         ` Thien-Thi Nguyen
2012-07-16 15:58           ` Eli Zaretskii
2012-07-16 19:13             ` Thien-Thi Nguyen
2012-07-17 13:11             ` Jason Rumney
2012-07-16 16:14           ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).