From 4c6afb527bddf9e9f481dd6f6627ffd5407b8803 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 4 Nov 2021 21:46:07 +0200 Subject: [PATCH] ; Comment on the code in a recent commit * lisp/international/mule-cmds.el (highlight-confusing-reorderings): Comment on the strategy of highlighting suspicious text. --- lisp/international/mule-cmds.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el index 8a64d6195cc..c05a99c4d3c 100644 --- a/lisp/international/mule-cmds.el +++ b/lisp/international/mule-cmds.el @@ -3293,6 +3293,22 @@ specify the portion of the buffer to check." (point) end nil (current-bidi-paragraph-direction))) (goto-char next) + ;; We detect the problematic parts by watching directional + ;; properties of strong L2R and R2L characters. But malicious + ;; reordering in source buffers can, and usuually does, + ;; include syntactically-important punctuation characters. + ;; Those have "weak" directionality, so we cannot easily + ;; detect when they are affected in malicious ways. + ;; Therefore, once we find a strong directional character + ;; whose directionality was tweaked, we highlight the text + ;; around it, between the first bidi control character we find + ;; before it that starts an override/embedding/isolate, and + ;; the first control after it that ends these. This could + ;; sometimes highlight only part of the affected text. An + ;; alternative would be to find the first "starter" following + ;; BOL and the last "ender" before EOL, and highlight + ;; everything in between them -- this could sometimes + ;; highlight too much. (let ((start (save-excursion (re-search-backward reorder-starters nil t))) -- 2.39.2