[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gentoo-dev
Subject:    [gentoo-dev] [PATCH] elisp-common.eclass: Document sed script in elisp-site-file-install
From:       Ulrich Müller <ulm () gentoo ! org>
Date:       2023-08-22 11:21:21
Message-ID: 20230822112131.32032-1-ulm () gentoo ! org
[Download RAW message or body]

Even though it is a simple one-liner, some people find it difficult
to read.

Signed-off-by: Ulrich Müller <ulm@gentoo.org>
---
 eclass/elisp-common.eclass | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/eclass/elisp-common.eclass b/eclass/elisp-common.eclass
index 1958b4a07e18..03e47d931f44 100644
--- a/eclass/elisp-common.eclass
+++ b/eclass/elisp-common.eclass
@@ -590,7 +590,13 @@ elisp-modules-install() {
 
 elisp-site-file-install() {
 	local sf="${1##*/}" my_pn="${2:-${PN}}" modules ret
-	local header=";;; ${PN} site-lisp configuration"
+	local add_header="1 {
+		# Find first non-empty line
+		:x; /^\$/ { n; bx; }
+		# Insert a header, unless we already look at one
+		/^;.*${PN}/I! s/^/;;; ${PN} site-lisp configuration\n\n/
+		1 s/^/\n/
+	}"
 
 	[[ ${sf} == [0-9][0-9]*-gentoo*.el ]] \
 		|| ewarn "elisp-site-file-install: bad name of site-init file"
@@ -599,7 +605,7 @@ elisp-site-file-install() {
 	ebegin "Installing site initialisation file for GNU Emacs"
 	[[ $1 == "${sf}" ]] || cp "$1" "${sf}"
 	modules=${EMACSMODULES//@libdir@/$(get_libdir)}
-	sed -i -e "1{:x;/^\$/{n;bx;};/^;.*${PN}/I!s:^:${header}\n\n:;1s:^:\n:;}" \
+	sed -i -e "${add_header}" \
 		-e "s:@SITELISP@:${EPREFIX}${SITELISP}/${my_pn}:g" \
 		-e "s:@SITEETC@:${EPREFIX}${SITEETC}/${my_pn}:g" \
 		-e "s:@EMACSMODULES@:${EPREFIX}${modules}/${my_pn}:g;\$q" "${sf}"
-- 
2.41.0


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic