summaryrefslogtreecommitdiff
path: root/x11-misc/emacs-desktop-mail/emacs-desktop-mail-1.2.ebuild
blob: aa83394f20326505286e67d230c1e6907bacd34d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8
NEED_EMACS=28

inherit elisp desktop xdg-utils

DESCRIPTION="Desktop entries for handling mailto URIs with GNU Emacs"
HOMEPAGE="https://wiki.gentoo.org/wiki/Project:Emacs"
S="${WORKDIR}"

LICENSE="GPL-2+"
SLOT="0"
KEYWORDS="~amd64 ~x86"

src_compile() { :; }

src_install() {
	newmenu - emacs-mail.desktop <<-EOF
		[Desktop Entry]
		Type=Application
		Name=GNU Emacs (mail)
		NoDisplay=true
		Exec=${EPREXIX}/usr/bin/emacs -f message-mailto %u
		Terminal=false
		MimeType=x-scheme-handler/mailto;
	EOF

	# The Desktop Entry Specification does not allow field codes like %u
	# inside a quoted argument, therefore we need a shell wrapper.
	# We pass the following commands to it, in order to backslash-escape
	# any special characters '\' and '"' that occur in %u:
	#   u=${1//\\/\\\\}
	#   u=${u//\"/\\\"}
	#   exec emacsclient --eval "(message-mailto \"$u\")"
	# However, in the desktop entry '"', '\', and '$' must be escaped
	# as '\\"', '\\\\', and '\\$', respectively. Yet another level of
	# backslash escapes is needed for '\' and '$' in the here-document.
	newmenu - emacsclient-mail.desktop <<-EOF
		[Desktop Entry]
		Type=Application
		Name=Emacsclient (mail)
		NoDisplay=true
		Exec=${EPREFIX}/bin/bash -c \
"u=\\\\\${1//\\\\\\\\\\\\\\\\/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\}; \
u=\\\\\${u//\\\\\\\\\\\\"/\\\\\\\\\\\\\\\\\\\\\\\\\\\\"}; \
exec ${EPREFIX}/usr/bin/emacsclient \
--eval \\\\"(message-mailto \\\\\\\\\\\\"\\\\\$u\\\\\\\\\\\\")\\\\"" bash %u
		Terminal=false
		MimeType=x-scheme-handler/mailto;
	EOF
}

pkg_postinst() {
	xdg_desktop_database_update
}

pkg_postrm() {
	xdg_desktop_database_update
}