all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Correct use of text properties?
@ 2023-03-02  4:21 Joshua Lambert
  2023-03-02  7:15 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Joshua Lambert @ 2023-03-02  4:21 UTC (permalink / raw)
  To: help-gnu-emacs

[-- 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 --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-03 12:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-02  4:21 Correct use of text properties? Joshua Lambert
2023-03-02  7:15 ` 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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.