aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2018-09-10 12:46:22 +0300
committerEli Zaretskii2018-09-10 12:46:22 +0300
commit5cf282d65f10f59f7efa63359dfd2b2e124943da (patch)
tree2f46d097912980052ce13faa6433913adc580f72
parent96281c5ee1582ac0c329d09797ab7ab3dbae26d1 (diff)
downloademacs-5cf282d65f10f59f7efa63359dfd2b2e124943da.tar.gz
emacs-5cf282d65f10f59f7efa63359dfd2b2e124943da.zip
Clarify documentation of functions reading character events
* doc/lispref/help.texi (Describing Characters): * doc/lispref/commands.texi (Keyboard Events) (Reading One Event, Classifying Events): Make the distinction between characters and character events more explicit. * src/keymap.c (Ftext_char_description) (Fsingle_key_description): * src/lread.c (Fread_char, Fread_char_exclusive): Doc fixes, to make a clear distinction between a character input event and a character code. (Bug#32562)
-rw-r--r--doc/lispref/commands.texi64
-rw-r--r--doc/lispref/help.texi14
-rw-r--r--src/keymap.c17
-rw-r--r--src/lread.c20
4 files changed, 73 insertions, 42 deletions
diff --git a/doc/lispref/commands.texi b/doc/lispref/commands.texi
index 0753d6fb67c..3e74f05e4c8 100644
--- a/doc/lispref/commands.texi
+++ b/doc/lispref/commands.texi
@@ -1076,9 +1076,10 @@ the current Emacs session. If a symbol has not yet been so used,
1076@cindex keyboard events 1076@cindex keyboard events
1077 1077
1078There are two kinds of input you can get from the keyboard: ordinary 1078There are two kinds of input you can get from the keyboard: ordinary
1079keys, and function keys. Ordinary keys correspond to characters; the 1079keys, and function keys. Ordinary keys correspond to (possibly
1080events they generate are represented in Lisp as characters. The event 1080modified) characters; the events they generate are represented in Lisp
1081type of a character event is the character itself (an integer); see 1081as characters. The event type of a character event is the character
1082itself (an integer), which might have some modifier bits set; see
1082@ref{Classifying Events}. 1083@ref{Classifying Events}.
1083 1084
1084@cindex modifier bits (of input character) 1085@cindex modifier bits (of input character)
@@ -1123,7 +1124,7 @@ for @kbd{%} plus
11232**26 11242**26
1124@end ifnottex 1125@end ifnottex
1125(assuming the terminal supports non-@acronym{ASCII} 1126(assuming the terminal supports non-@acronym{ASCII}
1126control characters). 1127control characters), i.e.@: with the 27th bit set.
1127 1128
1128@item shift 1129@item shift
1129The 1130The
@@ -1133,8 +1134,8 @@ The
1133@ifnottex 1134@ifnottex
11342**25 11352**25
1135@end ifnottex 1136@end ifnottex
1136bit in the character code indicates an @acronym{ASCII} control 1137bit (the 26th bit) in the character event code indicates an
1137character typed with the shift key held down. 1138@acronym{ASCII} control character typed with the shift key held down.
1138 1139
1139For letters, the basic code itself indicates upper versus lower case; 1140For letters, the basic code itself indicates upper versus lower case;
1140for digits and punctuation, the shift key selects an entirely different 1141for digits and punctuation, the shift key selects an entirely different
@@ -1146,7 +1147,7 @@ character with a different basic code. In order to keep within the
1146@ifnottex 1147@ifnottex
11472**25 11482**25
1148@end ifnottex 1149@end ifnottex
1149bit for those characters. 1150bit for those character events.
1150 1151
1151However, @acronym{ASCII} provides no way to distinguish @kbd{C-A} from 1152However, @acronym{ASCII} provides no way to distinguish @kbd{C-A} from
1152@kbd{C-a}, so Emacs uses the 1153@kbd{C-a}, so Emacs uses the
@@ -1167,7 +1168,7 @@ The
1167@ifnottex 1168@ifnottex
11682**24 11692**24
1169@end ifnottex 1170@end ifnottex
1170bit in the character code indicates a character 1171bit in the character event code indicates a character
1171typed with the hyper key held down. 1172typed with the hyper key held down.
1172 1173
1173@item super 1174@item super
@@ -1178,7 +1179,7 @@ The
1178@ifnottex 1179@ifnottex
11792**23 11802**23
1180@end ifnottex 1181@end ifnottex
1181bit in the character code indicates a character 1182bit in the character event code indicates a character
1182typed with the super key held down. 1183typed with the super key held down.
1183 1184
1184@item alt 1185@item alt
@@ -1189,9 +1190,9 @@ The
1189@ifnottex 1190@ifnottex
11902**22 11912**22
1191@end ifnottex 1192@end ifnottex
1192bit in the character code indicates a character typed with the alt key 1193bit in the character event code indicates a character typed with the
1193held down. (The key labeled @key{Alt} on most keyboards is actually 1194alt key held down. (The key labeled @key{Alt} on most keyboards is
1194treated as the meta key, not this.) 1195actually treated as the meta key, not this.)
1195@end table 1196@end table
1196 1197
1197 It is best to avoid mentioning specific bit numbers in your program. 1198 It is best to avoid mentioning specific bit numbers in your program.
@@ -1949,6 +1950,10 @@ Here are some examples:
1949 1950
1950The modifiers list for a click event explicitly contains @code{click}, 1951The modifiers list for a click event explicitly contains @code{click},
1951but the event symbol name itself does not contain @samp{click}. 1952but the event symbol name itself does not contain @samp{click}.
1953Similarly, the modifiers list for an @acronym{ASCII} control
1954character, such as @samp{C-a}, contains @code{control}, even though
1955reading such an event via @code{read-char} will return the value 1
1956with the control modifier bit removed.
1952@end defun 1957@end defun
1953 1958
1954@defun event-basic-type event 1959@defun event-basic-type event
@@ -2545,17 +2550,31 @@ right-arrow function key:
2545@end defun 2550@end defun
2546 2551
2547@defun read-char &optional prompt inherit-input-method seconds 2552@defun read-char &optional prompt inherit-input-method seconds
2548This function reads and returns a character of command input. If the 2553This function reads and returns a character input event. If the
2549user generates an event which is not a character (i.e., a mouse click or 2554user generates an event which is not a character (i.e., a mouse click or
2550function key event), @code{read-char} signals an error. The arguments 2555function key event), @code{read-char} signals an error. The arguments
2551work as in @code{read-event}. 2556work as in @code{read-event}.
2552 2557
2553In the first example, the user types the character @kbd{1} (@acronym{ASCII} 2558If the event has modifiers, Emacs attempts to resolve them and return
2554code 49). The second example shows a keyboard macro definition that 2559the code of the corresponding character. For example, if the user
2555calls @code{read-char} from the minibuffer using @code{eval-expression}. 2560types @kbd{C-a}, the function returns 1, which is the @acronym{ASCII}
2556@code{read-char} reads the keyboard macro's very next character, which 2561code of the @samp{C-a} character. If some of the modifiers cannot be
2557is @kbd{1}. Then @code{eval-expression} displays its return value in 2562reflected in the character code, @code{read-char} leaves the
2558the echo area. 2563unresolved modifier bits set in the returned event. For example, if
2564the user types @kbd{C-M-a}, the function returns 134217729, 8000001 in
2565hex, i.e.@: @samp{C-a} with the Meta modifier bit set. This value is
2566not a valid character code: it fails the @code{characterp} test
2567(@pxref{Character Codes}). Use @code{event-basic-type}
2568(@pxref{Classifying Events}) to recover the character code with the
2569modifier bits removed; use @code{event-modifiers} to test for
2570modifiers in the character event returned by @code{read-char}.
2571
2572In the first example below, the user types the character @kbd{1}
2573(@acronym{ASCII} code 49). The second example shows a keyboard macro
2574definition that calls @code{read-char} from the minibuffer using
2575@code{eval-expression}. @code{read-char} reads the keyboard macro's
2576very next character, which is @kbd{1}. Then @code{eval-expression}
2577displays its return value in the echo area.
2559 2578
2560@example 2579@example
2561@group 2580@group
@@ -2577,10 +2596,11 @@ the echo area.
2577@end defun 2596@end defun
2578 2597
2579@defun read-char-exclusive &optional prompt inherit-input-method seconds 2598@defun read-char-exclusive &optional prompt inherit-input-method seconds
2580This function reads and returns a character of command input. If the 2599This function reads and returns a character input event. If the
2581user generates an event which is not a character, 2600user generates an event which is not a character event,
2582@code{read-char-exclusive} ignores it and reads another event, until it 2601@code{read-char-exclusive} ignores it and reads another event, until it
2583gets a character. The arguments work as in @code{read-event}. 2602gets a character. The arguments work as in @code{read-event}. The
2603returned value may include modifier bits, as with @code{read-char}.
2584@end defun 2604@end defun
2585 2605
2586 None of the above functions suppress quitting. 2606 None of the above functions suppress quitting.
diff --git a/doc/lispref/help.texi b/doc/lispref/help.texi
index 6dd55d0b256..a23bc413d25 100644
--- a/doc/lispref/help.texi
+++ b/doc/lispref/help.texi
@@ -556,13 +556,13 @@ brackets.
556 556
557@defun text-char-description character 557@defun text-char-description character
558This function returns a string describing @var{character} in the 558This function returns a string describing @var{character} in the
559standard Emacs notation for characters that appear in text---like 559standard Emacs notation for characters that can appear in text---like
560@code{single-key-description}, except that control characters are 560@code{single-key-description}, except that the argument must be a
561represented with a leading caret (which is how control characters in 561valid character code that passes a @code{characterp} test
562Emacs buffers are usually displayed). Another difference is that 562(@pxref{Character Codes}), control characters are represented with a
563@code{text-char-description} recognizes the 2**7 bit as the Meta 563leading caret (which is how control characters in Emacs buffers are
564character, whereas @code{single-key-description} uses the 2**27 bit 564usually displayed), and the 2**7 bit is treated as the Meta bit,
565for Meta. 565whereas @code{single-key-description} uses the 2**27 bit for Meta.
566 566
567@smallexample 567@smallexample
568@group 568@group
diff --git a/src/keymap.c b/src/keymap.c
index c8cc933e782..ec483c7a632 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -2205,10 +2205,12 @@ push_key_description (EMACS_INT ch, char *p)
2205 2205
2206DEFUN ("single-key-description", Fsingle_key_description, 2206DEFUN ("single-key-description", Fsingle_key_description,
2207 Ssingle_key_description, 1, 2, 0, 2207 Ssingle_key_description, 1, 2, 0,
2208 doc: /* Return a pretty description of command character KEY. 2208 doc: /* Return a pretty description of a character event KEY.
2209Control characters turn into C-whatever, etc. 2209Control characters turn into C-whatever, etc.
2210Optional argument NO-ANGLES non-nil means don't put angle brackets 2210Optional argument NO-ANGLES non-nil means don't put angle brackets
2211around function keys and event symbols. */) 2211around function keys and event symbols.
2212
2213See `text-char-description' for describing character codes. */)
2212 (Lisp_Object key, Lisp_Object no_angles) 2214 (Lisp_Object key, Lisp_Object no_angles)
2213{ 2215{
2214 USE_SAFE_ALLOCA; 2216 USE_SAFE_ALLOCA;
@@ -2282,11 +2284,12 @@ push_text_char_description (register unsigned int c, register char *p)
2282/* This function cannot GC. */ 2284/* This function cannot GC. */
2283 2285
2284DEFUN ("text-char-description", Ftext_char_description, Stext_char_description, 1, 1, 0, 2286DEFUN ("text-char-description", Ftext_char_description, Stext_char_description, 1, 1, 0,
2285 doc: /* Return a pretty description of file-character CHARACTER. 2287 doc: /* Return the description of CHARACTER in standard Emacs notation.
2286Control characters turn into "^char", etc. This differs from 2288CHARACTER must be a valid character code that passes the `characterp' test.
2287`single-key-description' which turns them into "C-char". 2289Control characters turn into "^char", the 2**7 bit is treated as Meta, etc.
2288Also, this function recognizes the 2**7 bit as the Meta character, 2290This differs from `single-key-description' which accepts character events,
2289whereas `single-key-description' uses the 2**27 bit for Meta. 2291and thus doesn't enforce the `characterp' condition, turns control
2292characters into "C-char", and uses the 2**27 bit for Meta.
2290See Info node `(elisp)Describing Characters' for examples. */) 2293See Info node `(elisp)Describing Characters' for examples. */)
2291 (Lisp_Object character) 2294 (Lisp_Object character)
2292{ 2295{
diff --git a/src/lread.c b/src/lread.c
index d5ba48a170d..2e5cba510c5 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -735,10 +735,14 @@ read_filtered_event (bool no_switch_frame, bool ascii_required,
735} 735}
736 736
737DEFUN ("read-char", Fread_char, Sread_char, 0, 3, 0, 737DEFUN ("read-char", Fread_char, Sread_char, 0, 3, 0,
738 doc: /* Read a character from the command input (keyboard or macro). 738 doc: /* Read a character event from the command input (keyboard or macro).
739It is returned as a number. 739It is returned as a number.
740If the character has modifiers, they are resolved and reflected to the 740If the event has modifiers, they are resolved and reflected in the
741character code if possible (e.g. C-SPC -> 0). 741returned character code if possible (e.g. C-SPC yields 0 and C-a yields 97).
742If some of the modifiers cannot be reflected in the character code, the
743returned value will include those modifiers, and will not be a valid
744character code: it will fail the `characterp' test. Use `event-basic-type'
745to recover the character code with the modifiers removed.
742 746
743If the user generates an event which is not a character (i.e. a mouse 747If the user generates an event which is not a character (i.e. a mouse
744click or function key event), `read-char' signals an error. As an 748click or function key event), `read-char' signals an error. As an
@@ -785,10 +789,14 @@ floating-point value. */)
785} 789}
786 790
787DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 3, 0, 791DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 3, 0,
788 doc: /* Read a character from the command input (keyboard or macro). 792 doc: /* Read a character event from the command input (keyboard or macro).
789It is returned as a number. Non-character events are ignored. 793It is returned as a number. Non-character events are ignored.
790If the character has modifiers, they are resolved and reflected to the 794If the event has modifiers, they are resolved and reflected in the
791character code if possible (e.g. C-SPC -> 0). 795returned character code if possible (e.g. C-SPC yields 0 and C-a yields 97).
796If some of the modifiers cannot be reflected in the character code, the
797returned value will include those modifiers, and will not be a valid
798character code: it will fail the `characterp' test. Use `event-basic-type'
799to recover the character code with the modifiers removed.
792 800
793If the optional argument PROMPT is non-nil, display that as a prompt. 801If the optional argument PROMPT is non-nil, display that as a prompt.
794If the optional argument INHERIT-INPUT-METHOD is non-nil and some 802If the optional argument INHERIT-INPUT-METHOD is non-nil and some