diff options
| author | Po Lu | 2023-07-20 19:50:45 +0800 |
|---|---|---|
| committer | Po Lu | 2023-07-20 19:50:45 +0800 |
| commit | f9bbe3189b0eee627c3d8bca3221882cf0c29b26 (patch) | |
| tree | 63c50759b630140a49b92c233a83ff6d5b12bd88 /src | |
| parent | 7ff41bf8ed8439c949af4cdd3ae8d01c8cdf997f (diff) | |
| parent | 4bd8e8c6d2b75d678c13ae34c401668d3e8eecc7 (diff) | |
| download | emacs-f9bbe3189b0eee627c3d8bca3221882cf0c29b26.tar.gz emacs-f9bbe3189b0eee627c3d8bca3221882cf0c29b26.zip | |
Merge from origin/emacs-29
4bd8e8c6d2b ; * src/xdisp.c: Fix wording in commentary.
3af27a4b815 Improve commentary in nsfns.m
5de5e4b4d0a Fix typos and ommissions in cus-edit.el
9d93c6ba14a ; * src/xdisp.c: Fix typos in the commentary.
86f2d6d62fc ; * src/xdisp.c: Improve commentary. (Bug#64596)
ac075176bf0 ; * admin/notes/bugtracker: Fix punctuation.
81518534471 ; * admin/notes/bugtracker: Use 'e.g.' throughout the doc...
f063f79a493 Convert NUL-containing NSString objects to Lisp strings c...
d172cd59854 ; * doc/lispref/keymaps.texi (Modifying Menus): Add cross...
927e8b470fc ; * doc/lispref/keymaps.texi (Extended Menu Items): Add @...
77f489421ec ; * src/xdisp.c: Minor improvements of the commentary.
ce3f9fba1a3 ; Improve accuracy of out-out-order message insertion
17073af84d7 ; Improve robustness of package-report-bug
Diffstat (limited to 'src')
| -rw-r--r-- | src/nsfns.m | 8 | ||||
| -rw-r--r-- | src/xdisp.c | 153 |
2 files changed, 101 insertions, 60 deletions
diff --git a/src/nsfns.m b/src/nsfns.m index 90159533128..2519f1ebac8 100644 --- a/src/nsfns.m +++ b/src/nsfns.m | |||
| @@ -3840,7 +3840,13 @@ all_nonzero_ascii (unsigned char *str, ptrdiff_t n) | |||
| 3840 | /* Make a Lisp string from an NSString. */ | 3840 | /* Make a Lisp string from an NSString. */ |
| 3841 | - (Lisp_Object)lispString | 3841 | - (Lisp_Object)lispString |
| 3842 | { | 3842 | { |
| 3843 | return build_string ([self UTF8String]); | 3843 | /* `make_string' creates a string with a given length, instead of |
| 3844 | searching for a trailing NULL byte to determine its end. This is | ||
| 3845 | important because this function is called to convert NSString | ||
| 3846 | objects containing clipboard data, which can contain NUL bytes, | ||
| 3847 | into Lisp strings. (bug#64697) */ | ||
| 3848 | return make_string ([self UTF8String], | ||
| 3849 | [self lengthOfBytesUsingEncoding: NSUTF8StringEncoding]); | ||
| 3844 | } | 3850 | } |
| 3845 | @end | 3851 | @end |
| 3846 | 3852 | ||
diff --git a/src/xdisp.c b/src/xdisp.c index 3728228c6de..da6e0afa8e1 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -21,17 +21,17 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 21 | 21 | ||
| 22 | Redisplay. | 22 | Redisplay. |
| 23 | 23 | ||
| 24 | Emacs separates the task of updating the display from code | 24 | Emacs separates the task of updating the display -- which we call |
| 25 | modifying global state, e.g. buffer text. This way functions | 25 | "redisplay" -- from the code modifying global state, e.g. buffer |
| 26 | operating on buffers don't also have to be concerned with updating | 26 | text. This way functions operating on buffers don't also have to |
| 27 | the display. | 27 | be concerned with updating the display as result of their |
| 28 | 28 | operations. | |
| 29 | Updating the display is triggered by the Lisp interpreter when it | 29 | |
| 30 | decides it's time to do it. This is done either automatically for | 30 | Redisplay is triggered by the Lisp interpreter when it decides it's |
| 31 | you as part of the interpreter's command loop or as the result of | 31 | time to do it. This is done either automatically for you as part |
| 32 | calling Lisp functions like `sit-for'. The C function | 32 | of the interpreter's command loop, or as the result of calling Lisp |
| 33 | `redisplay_internal' in xdisp.c is the only entry into the inner | 33 | functions like `sit-for'. The C function `redisplay_internal' in |
| 34 | redisplay code. | 34 | xdisp.c is the only entry into the inner redisplay code. |
| 35 | 35 | ||
| 36 | The following diagram shows how redisplay code is invoked. As you | 36 | The following diagram shows how redisplay code is invoked. As you |
| 37 | can see, Lisp calls redisplay and vice versa. | 37 | can see, Lisp calls redisplay and vice versa. |
| @@ -75,63 +75,97 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 75 | and to make these changes visible. Preferably it would do that in | 75 | and to make these changes visible. Preferably it would do that in |
| 76 | a moderately intelligent way, i.e. fast. | 76 | a moderately intelligent way, i.e. fast. |
| 77 | 77 | ||
| 78 | Changes in buffer text can be deduced from window and buffer | 78 | At its highest level, redisplay can be divided into 3 distinct |
| 79 | steps, all of which are visible in `redisplay_internal': | ||
| 80 | |||
| 81 | . decide which frames need their windows to be considered for redisplay | ||
| 82 | . for each window whose display might need to be updated, compute | ||
| 83 | a structure, called "glyph matrix", which describes how it | ||
| 84 | should look on display | ||
| 85 | . actually update the display of windows on the glass where the | ||
| 86 | newly obtained glyph matrix differs from the one produced by the | ||
| 87 | previous redisplay cycle | ||
| 88 | |||
| 89 | The first of these steps is done by `redisplay_internal' itself, by | ||
| 90 | looping through all the frames and testing their various flags, | ||
| 91 | such as their visibility. The result of this could be that only | ||
| 92 | the selected window on the selected frame must be redisplayed, or | ||
| 93 | it could conclude that other windows need to be considered as well. | ||
| 94 | |||
| 95 | The second step considers each window that might need to be | ||
| 96 | redisplayed. This could be only the selected window, or the window | ||
| 97 | trees of one or more frames. The function which considers a window | ||
| 98 | and decides whether it actually needs redisplay is | ||
| 99 | `redisplay_window'. It does so by looking at the changes in | ||
| 100 | position of point, in buffer text, in text properties, overlays, | ||
| 101 | etc. These changes can be deduced from window and buffer | ||
| 79 | structures, and from some global variables like `beg_unchanged' and | 102 | structures, and from some global variables like `beg_unchanged' and |
| 80 | `end_unchanged'. The contents of the display are additionally | 103 | `end_unchanged'. The current contents of the display are recorded |
| 81 | recorded in a `glyph matrix', a two-dimensional matrix of glyph | 104 | in a `glyph matrix', a two-dimensional matrix of glyph structures. |
| 82 | structures. Each row in such a matrix corresponds to a line on the | 105 | Each row in such a matrix corresponds to a line on the display, and |
| 83 | display, and each glyph in a row corresponds to a column displaying | 106 | each glyph in a row corresponds to a column displaying a character, |
| 84 | a character, an image, or what else. This matrix is called the | 107 | an image, or what else. This matrix is called the `current glyph |
| 85 | `current glyph matrix' or `current matrix' in redisplay | 108 | matrix', or `current matrix', in redisplay terminology. |
| 86 | terminology. | 109 | |
| 87 | 110 | For buffer parts that have been changed since the last redisplay, | |
| 88 | For buffer parts that have been changed since the last update, a | 111 | `redisplay_window' constructs a second glyph matrix, the so called |
| 89 | second glyph matrix is constructed, the so called `desired glyph | 112 | `desired glyph matrix' or short `desired matrix'. It does so in |
| 90 | matrix' or short `desired matrix'. Current and desired matrix are | 113 | the most optimal way possible, avoiding the examination of text |
| 91 | then compared to find a cheap way to update the display, e.g. by | 114 | that didn't change, reusing portions of the current matrix if |
| 92 | reusing part of the display by scrolling lines. The actual update | 115 | possible, etc. It could, in particular, decide that a window |
| 93 | of the display of each window by comparing the desired and the | 116 | doesn't need to be redisplayed at all. |
| 94 | current matrix is done by `update_window', which calls functions | 117 | |
| 95 | which draw to the glass (those functions are specific to the type | 118 | This second step of redisplay also updates the parts of the desired |
| 96 | of the window's frame: X, w32, NS, etc.). | 119 | matrix that correspond to the mode lines, header lines, and |
| 120 | tab-lines of the windows which need that; see `display_mode_lines'. | ||
| 121 | |||
| 122 | In the third and last step, the current and desired matrix are then | ||
| 123 | compared to find a cheap way to update the display, e.g. by reusing | ||
| 124 | part of the display by scrolling lines. The actual update of the | ||
| 125 | display of each window, by comparing the desired and the current | ||
| 126 | matrix, is done by `update_window', which calls functions which | ||
| 127 | draw to the glass (those functions are specific to the type of the | ||
| 128 | window's frame: X, w32, NS, etc.). | ||
| 97 | 129 | ||
| 98 | Once the display of a window on the glass has been updated, its | 130 | Once the display of a window on the glass has been updated, its |
| 99 | desired matrix is used to update the corresponding rows of the | 131 | desired matrix is used to update the corresponding rows of the |
| 100 | current matrix, and then the desired matrix is discarded. | 132 | current matrix, and then the desired matrix is discarded. |
| 101 | 133 | ||
| 102 | You will find a lot of redisplay optimizations when you start | 134 | You will find a lot of redisplay optimizations when you start |
| 103 | looking at the innards of redisplay. The overall goal of all these | 135 | looking at the innards of `redisplay_window'. The overall goal of |
| 104 | optimizations is to make redisplay fast because it is done | 136 | all these optimizations is to make redisplay fast because it is |
| 105 | frequently. Some of these optimizations are implemented by the | 137 | done frequently. Some of these optimizations are implemented by |
| 106 | following functions: | 138 | the following functions: |
| 107 | 139 | ||
| 108 | . try_cursor_movement | 140 | . try_cursor_movement |
| 109 | 141 | ||
| 110 | This function tries to update the display if the text in the | 142 | This optimization is applicable if the text in the window did |
| 111 | window did not change and did not scroll, only point moved, and | 143 | not change and did not scroll, only point moved, and it did not |
| 112 | it did not move off the displayed portion of the text. | 144 | move off the displayed portion of the text. In that case, the |
| 145 | window's glyph matrix is still valid, and only the position of | ||
| 146 | the cursor might need to be updated. | ||
| 113 | 147 | ||
| 114 | . try_window_reusing_current_matrix | 148 | . try_window_reusing_current_matrix |
| 115 | 149 | ||
| 116 | This function reuses the current matrix of a window when text | 150 | This function reuses the current glyph matrix of a window when |
| 117 | has not changed, but the window start changed (e.g., due to | 151 | text has not changed, but the window start changed (e.g., due to |
| 118 | scrolling). | 152 | scrolling). |
| 119 | 153 | ||
| 120 | . try_window_id | 154 | . try_window_id |
| 121 | 155 | ||
| 122 | This function attempts to redisplay a window by reusing parts of | 156 | This function attempts to update a window's glyph matrix by |
| 123 | its existing display. It finds and reuses the part that was not | 157 | reusing parts of its current glyph matrix. It finds and reuses |
| 124 | changed, and redraws the rest. (The "id" part in the function's | 158 | the part that was not changed, and regenerates the rest. (The |
| 125 | name stands for "insert/delete", not for "identification" or | 159 | "id" part in the function's name stands for "insert/delete", not |
| 126 | somesuch.) | 160 | for "identification" or somesuch.) |
| 127 | 161 | ||
| 128 | . try_window | 162 | . try_window |
| 129 | 163 | ||
| 130 | This function performs the full, unoptimized, redisplay of a | 164 | This function performs the full, unoptimized, generation of a |
| 131 | single window assuming that its fonts were not changed and that | 165 | single window's glyph matrix, assuming that its fonts were not |
| 132 | the cursor will not end up in the scroll margins. (Loading | 166 | changed and that the cursor will not end up in the scroll |
| 133 | fonts requires re-adjustment of dimensions of glyph matrices, | 167 | margins. (Loading fonts requires re-adjustment of dimensions of |
| 134 | which makes this method impossible to use.) | 168 | glyph matrices, which makes this method impossible to use.) |
| 135 | 169 | ||
| 136 | The optimizations are tried in sequence (some can be skipped if | 170 | The optimizations are tried in sequence (some can be skipped if |
| 137 | it is known that they are not applicable). If none of the | 171 | it is known that they are not applicable). If none of the |
| @@ -140,16 +174,17 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 140 | 174 | ||
| 141 | Note that there's one more important optimization up Emacs's | 175 | Note that there's one more important optimization up Emacs's |
| 142 | sleeve, but it is related to actually redrawing the potentially | 176 | sleeve, but it is related to actually redrawing the potentially |
| 143 | changed portions of the window/frame, not to reproducing the | 177 | changed portions of the window/frame as part of the third step, not |
| 144 | desired matrices of those potentially changed portions. Namely, | 178 | to generating the desired matrices of those potentially changed |
| 145 | the function update_frame and its subroutines, which you will find | 179 | portions. Namely, the function `update_frame' and its subroutines, |
| 146 | in dispnew.c, compare the desired matrices with the current | 180 | which you will find in dispnew.c, compare the desired matrices with |
| 147 | matrices, and only redraw the portions that changed. So it could | 181 | the current matrices, and only redraw the portions that changed. |
| 148 | happen that the functions in this file for some reason decide that | 182 | So it could happen that the functions in this file for some reason |
| 149 | the entire desired matrix needs to be regenerated from scratch, and | 183 | decide that the entire desired matrix needs to be regenerated from |
| 150 | still only parts of the Emacs display, or even nothing at all, will | 184 | scratch, and still only parts of the Emacs display, or even nothing |
| 151 | be actually delivered to the glass, because update_frame has found | 185 | at all, will be actually delivered to the glass, because |
| 152 | that the new and the old screen contents are similar or identical. | 186 | `update_frame' has found that the new and the old screen contents |
| 187 | are similar or identical. | ||
| 153 | 188 | ||
| 154 | Desired matrices. | 189 | Desired matrices. |
| 155 | 190 | ||
| @@ -159,7 +194,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 159 | redisplay tries to optimize its work, and thus only generates | 194 | redisplay tries to optimize its work, and thus only generates |
| 160 | glyphs for rows that need to be updated on the screen. Rows that | 195 | glyphs for rows that need to be updated on the screen. Rows that |
| 161 | don't need to be updated are left "disabled", and their contents | 196 | don't need to be updated are left "disabled", and their contents |
| 162 | should be ignored. | 197 | in the desired matrix should be ignored. |
| 163 | 198 | ||
| 164 | The function `display_line' is the central function to look at if | 199 | The function `display_line' is the central function to look at if |
| 165 | you are interested in how the rows of the desired matrix are | 200 | you are interested in how the rows of the desired matrix are |