-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathge
More file actions
executable file
·157 lines (138 loc) · 6.52 KB
/
Copy pathge
File metadata and controls
executable file
·157 lines (138 loc) · 6.52 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/sh
# SH FILE: ge
#
# Purpose : Launch an independent, detached, GUI Emacs process. Supports macOS and Linux.
# Created : Tuesday, August 3 2021.
# Author : Pierre Rouleau <prouleau001@gmail.com>
# Time-stamp: <2026-03-13 14:18:46 EDT, updated by Pierre Rouleau>
# ----------------------------------------------------------------------------
# Description
# -----------
#
# Launch an independent GUI Emacs that is detached from the terminal shell
# executing the command. The current directory of the GUI Emacs process is
# set to the current directory of the terminal shell from which the 'ge'
# command was issued.
#
# ----------------------------------------------------------------------------
# Code
# ----
#
print_usage()
{
printf -- "\
ge : Open an independent, detached, graphical-mode instance of Emacs.
Usage: ge [-h|--help]
ge [FILE..]
Note: All command line arguments are passed to the Emacs application
unchanged. See Emacs man page for more options.
Emacs is launched inside an independent OS window, but
that process inherit the current directory.
Control is returned right away to the terminal shell.
On macOS the graphics version of Emacs is taken from one of
the following locations:
- If PEL_GE_DIR environment variable is defined, it must identify
the path of an emacs executable file that launches in graphics
mode by default. If the environment variable is set and
%s/emacs is valid then that is used.
Use this, for example, if you have built Emacs yourself
and want to use this version of Emacs without activating it
by default in your shells or in the system.
- If /Applications/Emacs.app/Contents/MacOS exists and holds
an appropriate Emacs executable file, that is used.
" "$PEL_GE_DIR"
if [ "$(uname)" = "Darwin" ]; then
printf -- "\
BUGS: On macOS Sonoma, the started Emacs application window is
buried under the window of the current terminal shell.
This problem does not occur on macOS Mojave.
"
fi
}
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
print_usage
exit 0
fi
# Pass to emacs:
# - --chdir to the current working directory so we open the same files
# as what is specified on the command line. If we don't do that the GUI
# based Emacs might use a different directory (most often the home directory)
# and if you specify files that are not in that directory they
# will not be opened, another file file open which will most likely be
# in an empty buffer (if the file does not exist in the home directory).
#
# Emacs 27+ support for PEL:
# - To allow Emacs early-init.el code to distinguish whether Emacs is
# running in terminal mode or in graphics mode. When running
# early-init.el Emacs does not know and the function
# display-graphic-p does not work at that moment. The only way I
# have found is to use an environment variable. So the following
# code sets one up: PEL_EMACS_IN_GRAPHICS
# See: https://emacs.stackexchange.com/questions/66268/how-to-set-package-user-dir-with-emacs-27-with-package-quickstart-and-distinguis
#
case $(uname) in
Darwin)
if [ -n "$PEL_GE_DIR" ] && [ -x "$PEL_GE_DIR/emacs" ]; then
export PEL_EMACS_IN_GRAPHICS=1
"$PEL_GE_DIR/emacs" --chdir="$(pwd)" "$@" &
elif [ -d /Applications/Emacs.app/Contents ]; then
# Under macOS use the open application to launch the GUI Emacs application.
# -n : open a new instance on each invocation
# -a application: identify the path of the application
# --env : allows passing environment variable definitions to the launched application
#
# The macOS GUI build packs multiple binaries.
# The umbrella/dispatcher binary is: /Applications/Emacs.app/Contents/MacOS/Emacs
# There are other architecture specific binaries.
# Invoke them if they can be identified. The value of the arch variable is not set,
# so the `arch' command must be used.
case "$(arch)" in
arm64)
# Running on Apple Silicon: use the arm64 specific binary if present
if [ -x /Applications/Emacs.app/Contents/MacOS/Emacs-arm64-11 ]; then
open -n -a /Applications/Emacs.app/Contents/MacOS/Emacs-arm64-11 --env PEL_EMACS_IN_GRAPHICS=1 --args --chdir="$(pwd)" "$@"
else
# since it's likely an older macOS system where open did not have the --env option, don't use it.
export PEL_EMACS_IN_GRAPHICS=1
open -n -a /Applications/Emacs.app/Contents/MacOS/Emacs --args --chdir="$(pwd)" "$@"
fi
;;
*)
# Use the general dispatcher for all others
# It will check what version of macOS and use the appropriate one.
# since it's likely an older macOS system where open did not have the --env option, don't use it.
export PEL_EMACS_IN_GRAPHICS=1
open -n -a /Applications/Emacs.app/Contents/MacOS/Emacs --args --chdir="$(pwd)" "$@"
;;
esac
else
echo "*** ge: ERROR ***"
echo "The required /Applications/Emacs.app is missing."
echo "Please install Emacs from https://emacsformacosx.com/ "
echo "*****************"
exit 1
fi
;;
Linux)
# Under Linux, invoke emacs passing the current working directory
# setting the PEL_EMACS_IN_GRAPHICS environment variable to inform
# PEL about the graphics mode and ensure it runs detached.
export PEL_EMACS_IN_GRAPHICS=1
# On some Linux distros, emacs-lucid is the X-Windows capable
# GUI version of Emacs. If available use it.
# At this point I don't see a reason to provide an overriding
# mechanism using an environment variable.
# If someone sees one please let me know.
if command -v emacs-lucid > /dev/null ; then
emacs-lucid --chdir="$(pwd)" "$@" &
else
emacs --chdir="$(pwd)" "$@" &
fi
;;
*)
echo "Sorry, the $(uname) Operating System is not supported yet."
echo "Please create a bug report in the PEL project to request it."
exit 1
;;
esac
# ----------------------------------------------------------------------------