From: Joshua Lambert <jlambert.lis.tech@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Correct use of text properties?
Date: Wed, 1 Mar 2023 22:21:14 -0600 [thread overview]
Message-ID: <CAGGu9j2YnAnqXLqX9VsSWAUpJFJ3Whv_XxgLAt60PE=crW3_qg@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2480 bytes --]
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?
(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
Following is what a sample MARC record looks like, though MARC files
don't have newlines. So, if you test this, use the attached file.
#+begin_example MARC transmission record
00608nam 22001817a
45000010012000000050017000120080041000290490009000700400013000790740014
00092086002300106245009400129260002600223500003300249500003500282710006
900317949004000386 tmp97483713 20221114095123.0 221114s2022
xxu f000 0 eng d aMOUE aMvI cMvI a1017-A-07 0 aY 4.F
76/1:117-105 04 aThe Burma Crisis, One Year After the Coup, Hearing,
Serial No. 117-105, February 17, 2022 a[S.l : bs.n., c2022?]
aShipping List #: 2023-0021-P aShipping List Date: 11/02/2022 1
aUnited States. bCongress. bHouse. bCommittee on Foreign
Affairs. 1 aY 4.F 76/1:117-105 lSMVUS s- t1 h60
#+end_example
Following is the visual result after executing the function above.
#+begin_example
00608nam 22001817a
45000010012000000050017000120080041000290490009000700400013000790740014
00092086002300106245009400129260002600223500003300249500003500282710006
900317949004000386
tmp97483713
20221114095123.0
221114s2022
xxu f000 0 eng d
aMOUE
aMvI cMvI
a1017-A-07
0 aY 4.F 76/1:117-105
04 aThe Burma Crisis, One Year After the Coup, Hearing, Serial No.
117-105, February 17, 2022
a[S.l : bs.n., c2022?]
aShipping List #: 2023-0021-P
aShipping List Date: 11/02/2022
1 aUnited States. bCongress. bHouse. bCommittee on Foreign Affairs.
1 aY 4.F 76/1:117-105 lSMVUS s- t1 h60
#+end_example
I'm relatively new to Emacs, elisp, and programming in general so
thanks for your help.
J. Lambert
[-- Attachment #2: sample-marc.mrc --]
[-- Type: application/marc, Size: 582 bytes --]
next reply other threads:[~2023-03-02 4:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-02 4:21 Joshua Lambert [this message]
2023-03-02 7:15 ` Correct use of text properties? Eli Zaretskii
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='CAGGu9j2YnAnqXLqX9VsSWAUpJFJ3Whv_XxgLAt60PE=crW3_qg@mail.gmail.com' \
--to=jlambert.lis.tech@gmail.com \
--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).