help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Correct use of text properties?


From: Joshua Lambert
Subject: Correct use of text properties?
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?

(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: sample-marc.mrc
Description: application/marc


reply via email to

[Prev in Thread] Current Thread [Next in Thread]