unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Correct use of text properties?
Date: Thu, 02 Mar 2023 09:15:45 +0200	[thread overview]
Message-ID: <83sfenei8u.fsf@gnu.org> (raw)
In-Reply-To: <CAGGu9j2YnAnqXLqX9VsSWAUpJFJ3Whv_XxgLAt60PE=crW3_qg@mail.gmail.com> (message from Joshua Lambert on Wed, 1 Mar 2023 22:21:14 -0600)

> From: Joshua Lambert <jlambert.lis.tech@gmail.com>
> Date: Wed, 1 Mar 2023 22:21:14 -0600
> 
> I am trying to use text properties to make library MARC records more
> readable in Emacs. Is the function below correctly written? It is meant to
> simply replace codepoints 29 and 30 with newlines, using text properties.
> It seems to visually accomplish what I want, but line numbers and some
> cursor motions don't treat the newlines like true newlines. Is that
> expected behavior?

Probably.  But you don't describe the behavior you found surprising,
so it is hard to tell whether what you see is expected.  Please tell
more about the behavior you observe that surprised you.

> (The files use codepoints 29-31 in ASCII or UTF8 so they may not display
> properly.)
> 
> #+begin_src emacs-lisp
> (defun marc-add-newlines ()
>   "Replace the display text property of all   with newline."
>   (interactive)
>   (save-excursion
>     (goto-char (point-min))
>     (while (re-search-forward " " nil 1)
>       (put-text-property (- (point) 1) (point) 'display "\n")))
>   (save-excursion
>     (goto-char (point-min))
>     (while (re-search-forward " " nil 1)
>       (put-text-property (- (point) 1) (point) 'display "\n"))))
> #+end_src

If all you want is to break long lines on space characters, I suggest
to try visual-line-mode instead: it does that automatically in
low-level display code.  Did you try that?



  reply	other threads:[~2023-03-02  7:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-02  4:21 Correct use of text properties? Joshua Lambert
2023-03-02  7:15 ` Eli Zaretskii [this message]
2023-03-02 15:25   ` Joshua Lambert
2023-03-02 15:47     ` Eli Zaretskii
2023-03-02 17:20       ` Joshua Lambert
2023-03-03 12:36     ` Michael Heerdegen

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=83sfenei8u.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=help-gnu-emacs@gnu.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.
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).