From: Yuan Fu <casouri@gmail.com>
To: Lars Ingebrigtsen <larsi@gnus.org>, Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: Line wrap reconsidered
Date: Mon, 25 May 2020 23:30:36 -0400 [thread overview]
Message-ID: <090B0FA5-2AA6-4134-BB8B-3FD9BFCC5AA0@gmail.com> (raw)
In-Reply-To: <6795D9A1-904E-4C6F-AE86-9EDD52718F01@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 271 bytes --]
The redisplay code now works! Now I need to explore how to apply the text properties. I had a look at category table. IIUC, a category table for all unicode characters would be impractically large and unnecessary. A normal list of ranges would probably work.
Yuan
[-- Attachment #2: wrap.patch --]
[-- Type: application/octet-stream, Size: 6019 bytes --]
diff --git a/src/xdisp.c b/src/xdisp.c
index 01f272033e..7f04c1bc67 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -427,6 +427,28 @@ #define IT_DISPLAYING_WHITESPACE(it) \
&& (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
|| *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t'))))
+/* Return true if the current character allows wrapping before it. */
+static bool char_can_wrap_before (struct it *it)
+{
+ Lisp_Object charpos = make_fixnum (IT_CHARPOS (*it));
+ Lisp_Object prop = Fget_text_property (charpos, Qcan_wrap, Qnil);
+ if (EQ (Qt, prop) || EQ (Qbefore_only, prop))
+ return true;
+ else
+ return false;
+}
+
+/* Return true if the current character allows wrapping after it. */
+static bool char_can_wrap_after (struct it *it)
+{
+ Lisp_Object charpos = make_fixnum (IT_CHARPOS (*it));
+ Lisp_Object prop = Fget_text_property (charpos, Qcan_wrap, Qnil);
+ if (EQ (Qt, prop) || EQ (Qafter_only, prop))
+ return true;
+ else
+ return false;
+}
+
/* If all the conditions needed to print the fill column indicator are
met, return the (nonnegative) column number, else return a negative
value. */
@@ -9098,9 +9120,12 @@ #define IT_RESET_X_ASCENT_DESCENT(IT) \
{
if (it->line_wrap == WORD_WRAP && it->area == TEXT_AREA)
{
- if (IT_DISPLAYING_WHITESPACE (it))
+ /* If this character displays a whitespace or the text
+ property says you can wrap after it, the next one can
+ wrap. */
+ if (IT_DISPLAYING_WHITESPACE (it) || char_can_wrap_after (it))
may_wrap = true;
- else if (may_wrap)
+ if (! IT_DISPLAYING_WHITESPACE (it) && may_wrap)
{
/* We have reached a glyph that follows one or more
whitespace characters. If the position is
@@ -9249,9 +9274,13 @@ #define IT_RESET_X_ASCENT_DESCENT(IT) \
bool can_wrap = true;
/* If we are at a whitespace character
- that barely fits on this screen line,
- but the next character is also
- whitespace, we cannot wrap here. */
+ (or a character that allows wrapping
+ after it) that barely fits on this
+ screen line, but the next character
+ is also whitespace (or a character
+ that forbids wrapping before it), we
+ cannot wrap here.
+ */
if (it->line_wrap == WORD_WRAP
&& wrap_it.sp >= 0
&& may_wrap
@@ -9263,7 +9292,8 @@ #define IT_RESET_X_ASCENT_DESCENT(IT) \
SAVE_IT (tem_it, *it, tem_data);
set_iterator_to_next (it, true);
if (get_next_display_element (it)
- && IT_DISPLAYING_WHITESPACE (it))
+ && (IT_DISPLAYING_WHITESPACE (it)
+ || !char_can_wrap_before (it)))
can_wrap = false;
RESTORE_IT (it, &tem_it, tem_data);
}
@@ -9342,19 +9372,23 @@ #define IT_RESET_X_ASCENT_DESCENT(IT) \
else
IT_RESET_X_ASCENT_DESCENT (it);
- /* If the screen line ends with whitespace, and we
- are under word-wrap, don't use wrap_it: it is no
- longer relevant, but we won't have an opportunity
- to update it, since we are done with this screen
- line. */
+ /* If the screen line ends with whitespace (or
+ wrap-able character), and we are under word-wrap,
+ don't use wrap_it: it is no longer relevant, but
+ we won't have an opportunity to update it, since
+ we are done with this screen line. */
if (may_wrap && IT_OVERFLOW_NEWLINE_INTO_FRINGE (it)
/* If the character after the one which set the
- may_wrap flag is also whitespace, we can't
- wrap here, since the screen line cannot be
- wrapped in the middle of whitespace.
- Therefore, wrap_it _is_ relevant in that
+ may_wrap flag is also whitespace (or is a
+ character that forbids wrapping before it),
+ we can't wrap here, since the screen line
+ cannot be wrapped in the middle of whitespace
+ (or before a character that forbids wrapping
+ before it). Therefore, wrap_it (previously
+ found wrap-point) _is_ relevant in that
case. */
- && !(moved_forward && IT_DISPLAYING_WHITESPACE (it)))
+ && !(moved_forward && (IT_DISPLAYING_WHITESPACE (it)
+ || !char_can_wrap_before (it))))
{
/* If we've found TO_X, go back there, as we now
know the last word fits on this screen line. */
@@ -23180,9 +23214,9 @@ #define RECORD_MAX_MIN_POS(IT) \
if (it->line_wrap == WORD_WRAP && it->area == TEXT_AREA)
{
- if (IT_DISPLAYING_WHITESPACE (it))
+ if (IT_DISPLAYING_WHITESPACE (it) || char_can_wrap_after (it))
may_wrap = true;
- else if (may_wrap)
+ if (! IT_DISPLAYING_WHITESPACE (it) && may_wrap)
{
SAVE_IT (wrap_it, *it, wrap_data);
wrap_x = x;
@@ -23328,7 +23362,8 @@ #define RECORD_MAX_MIN_POS(IT) \
was a space or tab AND (ii) the
current character is not. */
&& (!may_wrap
- || IT_DISPLAYING_WHITESPACE (it)))
+ || IT_DISPLAYING_WHITESPACE (it)
+ || char_can_wrap_after (it)))
goto back_to_wrap;
/* Record the maximum and minimum buffer
@@ -23362,7 +23397,8 @@ #define RECORD_MAX_MIN_POS(IT) \
was a space or tab AND (ii) the
current character is not. */
&& (!may_wrap
- || IT_DISPLAYING_WHITESPACE (it)))
+ || IT_DISPLAYING_WHITESPACE (it)
+ || char_can_wrap_after (it)))
goto back_to_wrap;
}
@@ -34231,6 +34267,9 @@ syms_of_xdisp (void)
DEFSYM (QCfile, ":file");
DEFSYM (Qfontified, "fontified");
DEFSYM (Qfontification_functions, "fontification-functions");
+ DEFSYM (Qcan_wrap, "can-wrap");
+ DEFSYM (Qbefore_only, "before-only");
+ DEFSYM (Qafter_only, "after-only");
/* Name of the symbol which disables Lisp evaluation in 'display'
properties. This is used by enriched.el. */
next prev parent reply other threads:[~2020-05-26 3:30 UTC|newest]
Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-25 18:13 Line wrap reconsidered Yuan Fu
2020-05-25 19:23 ` Eli Zaretskii
2020-05-25 19:31 ` Yuan Fu
2020-05-26 1:55 ` Ihor Radchenko
2020-05-26 12:55 ` Joost Kremers
2020-05-26 13:35 ` Yuan Fu
2020-05-26 14:47 ` Eli Zaretskii
2020-05-26 15:01 ` Ihor Radchenko
2020-05-26 15:29 ` Eli Zaretskii
2020-05-26 15:46 ` Ihor Radchenko
2020-05-26 16:29 ` Eli Zaretskii
2020-05-26 15:59 ` Stefan Monnier
2020-05-26 16:31 ` Eli Zaretskii
2020-05-26 16:43 ` Yuan Fu
2020-05-26 16:43 ` Ihor Radchenko
2020-05-26 18:57 ` Eli Zaretskii
2020-05-26 19:10 ` Yuan Fu
2020-05-26 19:59 ` Eli Zaretskii
2020-05-26 19:12 ` Ihor Radchenko
2020-05-26 20:04 ` Eli Zaretskii
2020-05-26 21:01 ` Stefan Monnier
2020-05-25 19:31 ` Stefan Monnier
2020-05-25 19:51 ` Yuan Fu
2020-05-25 20:43 ` Lars Ingebrigtsen
2020-05-25 23:26 ` Yuan Fu
2020-05-25 23:32 ` Yuan Fu
2020-05-26 2:15 ` Yuan Fu
2020-05-26 3:30 ` Yuan Fu [this message]
2020-05-26 4:46 ` Yuan Fu
2020-05-26 15:14 ` Eli Zaretskii
2020-05-26 15:00 ` Eli Zaretskii
2020-05-26 14:54 ` Eli Zaretskii
2020-05-26 17:34 ` Yuan Fu
2020-05-26 19:50 ` Eli Zaretskii
2020-05-26 20:31 ` Yuan Fu
2020-05-26 22:29 ` Yuan Fu
2020-05-27 17:29 ` Eli Zaretskii
2020-05-28 17:31 ` Yuan Fu
2020-05-28 18:05 ` Eli Zaretskii
2020-05-28 19:34 ` Yuan Fu
2020-05-28 20:42 ` Yuan Fu
2020-05-29 7:17 ` Eli Zaretskii
2020-05-29 6:56 ` Eli Zaretskii
2020-05-29 21:20 ` Yuan Fu
2020-05-30 6:14 ` Eli Zaretskii
2020-05-31 17:39 ` Yuan Fu
2020-05-31 17:55 ` Eli Zaretskii
2020-05-31 18:23 ` Yuan Fu
2020-05-31 18:47 ` Eli Zaretskii
2020-06-18 21:46 ` Yuan Fu
2020-06-19 6:17 ` Eli Zaretskii
2020-06-19 12:04 ` Yuan Fu
2020-06-19 12:38 ` Eli Zaretskii
2020-06-19 17:22 ` Yuan Fu
2020-06-19 17:47 ` Eli Zaretskii
2020-06-19 18:03 ` Yuan Fu
2020-06-19 18:34 ` Eli Zaretskii
2020-07-12 17:25 ` Yuan Fu
2020-07-12 18:27 ` Eli Zaretskii
2020-07-12 19:28 ` Yuan Fu
2020-07-13 19:46 ` Yuan Fu
2020-07-18 8:15 ` Eli Zaretskii
2020-07-18 17:14 ` Yuan Fu
2020-07-18 19:49 ` Yuan Fu
2020-07-18 20:25 ` Stefan Monnier
2020-07-19 14:52 ` Eli Zaretskii
2020-07-19 16:16 ` Yuan Fu
2020-07-19 16:17 ` Yuan Fu
2020-08-13 19:35 ` Yuan Fu
2020-08-14 5:55 ` Eli Zaretskii
2020-08-14 15:08 ` Yuan Fu
2020-08-15 9:10 ` Eli Zaretskii
2020-08-15 13:10 ` Fu Yuan
2020-08-15 14:56 ` Eli Zaretskii
2020-08-15 17:34 ` Yuan Fu
2020-08-15 17:46 ` Eli Zaretskii
2020-08-15 18:00 ` Yuan Fu
2020-08-15 18:47 ` Eli Zaretskii
2020-08-16 3:22 ` Yuan Fu
2020-08-16 14:15 ` Eli Zaretskii
2020-08-16 17:31 ` Yuan Fu
2020-08-22 7:42 ` Eli Zaretskii
2020-08-22 20:58 ` Yuan Fu
2020-08-23 7:12 ` Eli Zaretskii
2020-08-24 14:00 ` Yuan Fu
2020-05-27 15:20 ` Eli Zaretskii
2020-05-26 8:02 ` martin rudalics
2020-05-26 12:38 ` Yuan Fu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=090B0FA5-2AA6-4134-BB8B-3FD9BFCC5AA0@gmail.com \
--to=casouri@gmail.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=larsi@gnus.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).