From: Juri Linkov <juri@linkov.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: bpeeluk@yahoo.co.uk, larsi@gnus.org, 44236@debbugs.gnu.org
Subject: bug#44236: [PATCH] xdisp: Apply nobreak-char-display also to NARROW NO-BREAK SPACE U+202F
Date: Tue, 03 Nov 2020 20:44:18 +0200 [thread overview]
Message-ID: <87y2ji2yd1.fsf@mail.linkov.net> (raw)
In-Reply-To: <87h7q8x2em.fsf@mail.linkov.net> (Juri Linkov's message of "Sun, 01 Nov 2020 22:12:01 +0200")
[-- Attachment #1: Type: text/plain, Size: 838 bytes --]
>> But that's not what I meant. I meant that if we want to base this on
>> text properties, we should do this via hi-lock or similar, not in the
>> display engine which treats all characters the same.
>
> Or markchars.el, or uni-confusables.el. Like these packages maybe better
> to create another package e.g. nobreak.el, based on font-lock-mode?
Now I extended markchars.el to highlight exactly the same characters
as highlighted by nobreak-char-display, and additionally highlight them
only in files names in Dired. This is configurable with such hook:
(add-hook 'dired-mode-hook
(lambda ()
(setq-local nobreak-char-display nil)
(setq-local markchars-what '(markchars-nobreak-space
markchars-nobreak-hyphen))
(markchars-mode 1)))
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: markchars-nobreak.patch --]
[-- Type: text/x-diff, Size: 4898 bytes --]
diff --git a/packages/markchars/markchars.el b/packages/markchars/markchars.el
index 7d7fe2982..bd902f7c7 100644
--- a/packages/markchars/markchars.el
+++ b/packages/markchars/markchars.el
@@ -31,6 +31,12 @@
;; `markchars-face-confusable' or `markchars-face-pattern'
;; respectively.
;;
+;; You can set `nobreak-char-display' to nil, and use
+;; `markchars-nobreak-space' and `markchars-nobreak-hyphen'
+;; in Dired buffers to highlight `nobreak-space' and `nobreak-hyphen'
+;; only in file names, not `nobreak-space' used by thousands separators
+;; in file sizes (bug#44236).
+;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Change log:
@@ -79,6 +85,16 @@ markchars-white
"White face for `markchars-mode' char marking."
:group 'markchars)
+(defface markchars-nobreak-space
+ '((t (:inherit nobreak-space)))
+ "Face for displaying nobreak space."
+ :group 'markchars)
+
+(defface markchars-nobreak-hyphen
+ '((t (:inherit nobreak-hyphen)))
+ "Face for displaying nobreak hyphens."
+ :group 'markchars)
+
(defcustom markchars-face-pattern 'markchars-heavy
"Pointer to face used for marking matched patterns."
:type 'face
@@ -101,12 +117,40 @@ markchars-simple-pattern
:type 'regexp
:group 'markchars)
+(defvar markchars-nobreak-space-pattern
+ (rx (any ;; ?\N{SPACE}
+ ?\N{NO-BREAK SPACE}
+ ?\N{OGHAM SPACE MARK}
+ ?\N{EN QUAD}
+ ?\N{EM QUAD}
+ ?\N{EN SPACE}
+ ?\N{EM SPACE}
+ ?\N{THREE-PER-EM SPACE}
+ ?\N{FOUR-PER-EM SPACE}
+ ?\N{SIX-PER-EM SPACE}
+ ?\N{FIGURE SPACE}
+ ?\N{PUNCTUATION SPACE}
+ ?\N{THIN SPACE}
+ ?\N{HAIR SPACE}
+ ?\N{NARROW NO-BREAK SPACE}
+ ?\N{MEDIUM MATHEMATICAL SPACE}
+ ?\N{IDEOGRAPHIC SPACE}))
+ "A list of characters with general-category `Zs' (Separator, Space).")
+
+(defvar markchars-nobreak-hyphen-pattern
+ (rx (any ?\N{SOFT HYPHEN} ?\N{HYPHEN} ?\N{NON-BREAKING HYPHEN}))
+ "A list of hyphen characters.")
+
(defcustom markchars-what
`(markchars-simple-pattern
markchars-confusables
,@(when (fboundp 'idn-is-recommended) '(markchars-nonidn-fun)))
"Things to mark, a list of regular expressions or symbols."
:type `(repeat (choice :tag "Marking choices"
+ (const :tag "Non-ASCII space chars"
+ markchars-nobreak-space)
+ (const :tag "Non-ASCII hyphen chars"
+ markchars-nobreak-hyphen)
(const
:tag "Non IDN chars (Unicode.org tr39 suggestions)"
markchars-nonidn-fun)
@@ -129,6 +173,18 @@ markchars-set-keywords
(when (eq what 'markchars-simple-pattern)
(setq what markchars-simple-pattern))
(cond
+ ((eq what 'markchars-nobreak-space)
+ (list
+ markchars-nobreak-space-pattern
+ (list 0 '(markchars--render-nobreak-space
+ (match-beginning 0)
+ (match-end 0)))))
+ ((eq what 'markchars-nobreak-hyphen)
+ (list
+ markchars-nobreak-hyphen-pattern
+ (list 0 '(markchars--render-nobreak-hyphen
+ (match-beginning 0)
+ (match-end 0)))))
((eq what 'markchars-nonidn-fun)
(list
"\\<\\w+\\>"
@@ -184,6 +240,22 @@ markchars--render-nonidn
(put-text-property (point) (1+ (point)) 'face markchars-face-nonidn)))
(forward-char))))
+(defun markchars--render-nobreak-space (beg end)
+ "Assign markchars pattern properties between BEG and END.
+In Dired/WDired buffers, highlight nobreak-space characters
+only in file names, not anywhere else, so it doesn't highlight
+nobreak-space characters used by thousands separators in file sizes."
+ (when (or (not (derived-mode-p 'dired-mode 'wdired-mode))
+ (or (get-text-property beg 'dired-filename)
+ (get-text-property end 'dired-filename)))
+ (put-text-property beg end 'face 'markchars-nobreak-space)
+ (put-text-property beg end 'markchars 'nobreak-space)))
+
+(defun markchars--render-nobreak-hyphen (beg end)
+ "Assign markchars pattern properties between BEG and END."
+ (put-text-property beg end 'face 'markchars-nobreak-hyphen)
+ (put-text-property beg end 'markchars 'nobreak-hyphen))
+
;;;###autoload
(define-minor-mode markchars-mode
"Mark special characters.
next prev parent reply other threads:[~2020-11-03 18:44 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20201026111348.773761-1-bpeeluk.ref@yahoo.co.uk>
2020-10-26 11:13 ` bug#44236: [PATCH] xdisp: Apply nobreak-char-display also to NARROW NO-BREAK SPACE U+202F Neil Roberts via Bug reports for GNU Emacs, the Swiss army knife of text editors
2020-10-26 16:29 ` Eli Zaretskii
2020-10-26 16:55 ` Drew Adams
2020-10-27 9:17 ` Neil Roberts via Bug reports for GNU Emacs, the Swiss army knife of text editors
2020-10-27 15:24 ` Eli Zaretskii
2020-10-28 11:37 ` bug#44236: [PATCH] xdisp: Apply nobreak-char-display to all characters of blankp Neil Roberts via Bug reports for GNU Emacs, the Swiss army knife of text editors
2020-10-30 12:14 ` bug#44236: (no subject) Lars Ingebrigtsen
2020-11-01 8:20 ` bug#44236: [PATCH] xdisp: Apply nobreak-char-display also to NARROW NO-BREAK SPACE U+202F Juri Linkov
2020-11-01 8:30 ` Juri Linkov
2020-11-01 13:12 ` Lars Ingebrigtsen
2020-11-01 15:16 ` Eli Zaretskii
2020-11-01 18:51 ` Juri Linkov
2020-11-01 19:29 ` Eli Zaretskii
2020-11-01 19:40 ` Juri Linkov
2020-11-01 19:52 ` Eli Zaretskii
2020-11-01 20:12 ` Juri Linkov
2020-11-03 18:44 ` Juri Linkov [this message]
2020-11-03 21:07 ` Basil L. Contovounesios
2020-11-04 19:54 ` Juri Linkov
2020-11-01 18:53 ` Juri Linkov
2020-11-01 19:30 ` Eli Zaretskii
2020-11-01 19:41 ` Juri Linkov
2020-11-01 19:59 ` Eli Zaretskii
2020-11-01 19:41 ` Neil Roberts via Bug reports for GNU Emacs, the Swiss army knife of text editors
2020-11-01 20:00 ` Juri Linkov
[not found] <<20201026111348.773761-1-bpeeluk.ref@yahoo.co.uk>
[not found] ` <<20201026111348.773761-1-bpeeluk@yahoo.co.uk>
[not found] ` <<837drdeyss.fsf@gnu.org>
[not found] ` <<87h7q98p4q.fsf@mail.linkov.net>
[not found] ` <<87imapcjam.fsf@gnus.org>
[not found] ` <<87wnz4zz5k.fsf@mail.linkov.net>
[not found] ` <<83wnz4euxk.fsf@gnu.org>
[not found] ` <<87r1pcyib0.fsf@mail.linkov.net>
[not found] ` <<83lffketlt.fsf@gnu.org>
2020-11-01 22:43 ` Drew Adams
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=87y2ji2yd1.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=44236@debbugs.gnu.org \
--cc=bpeeluk@yahoo.co.uk \
--cc=eliz@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).