[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/android 0eb1f4e5712: Allow starting Emacs --debug-init on Androi
From: |
Po Lu |
Subject: |
feature/android 0eb1f4e5712: Allow starting Emacs --debug-init on Android |
Date: |
Fri, 26 May 2023 03:25:03 -0400 (EDT) |
branch: feature/android
commit 0eb1f4e57125117006f109a5549082008fc9fbb1
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
Allow starting Emacs --debug-init on Android
* doc/emacs/android.texi (Android Troubleshooting): Document
`debug-init' option.
* java/AndroidManifest.xml.in
(EmacsLauncherPreferencesActivity): New activity. Export on
systems older than Android 7.0.
* java/org/gnu/emacs/EmacsActivity.java (onCreate): Adjust for
string startup argument.
* java/org/gnu/emacs/EmacsLauncherPreferencesActivity.java: New
file.
* java/org/gnu/emacs/EmacsPreferencesActivity.java
(EmacsPreferencesActivity): Don't make final.
(startEmacsQ): Give start-up argument as an argument, not as a
boolean.
(startEmacsDebugInit): New function.
(onCreate): Register new listener; make final.
* java/org/gnu/emacs/EmacsService.java (onCreate): Pass
extraStartupArgument.
* java/org/gnu/emacs/EmacsThread.java (EmacsThread): Rename
startDashQ to extraStartupArgument.
(run): Adjust accordingly.
* java/res/values-v24/bool.xml:
* java/res/values/bool.xml:
* java/res/values/strings.xml: New files.
* java/res/xml/preferences.xml: Add new option. Move string
resources around.
---
doc/emacs/android.texi | 14 ++++---
java/AndroidManifest.xml.in | 17 +++++++++
java/org/gnu/emacs/EmacsActivity.java | 8 ++--
.../emacs/EmacsLauncherPreferencesActivity.java} | 23 ++++++++----
java/org/gnu/emacs/EmacsPreferencesActivity.java | 41 +++++++++++++++++----
java/org/gnu/emacs/EmacsService.java | 7 +++-
java/org/gnu/emacs/EmacsThread.java | 19 ++++++----
java/res/drawable/emacs_wrench.png | Bin 0 -> 24996 bytes
java/res/{values => values-v24}/bool.xml | 2 +-
java/res/values/bool.xml | 1 +
java/res/values/strings.xml | 39 ++++++++++++++++++++
java/res/xml/preferences.xml | 12 +++---
12 files changed, 144 insertions(+), 39 deletions(-)
diff --git a/doc/emacs/android.texi b/doc/emacs/android.texi
index d7fadd69e4b..d94b91c7ab7 100644
--- a/doc/emacs/android.texi
+++ b/doc/emacs/android.texi
@@ -608,16 +608,20 @@ to provide that style.
@cindex troubleshooting, android
@cindex emacs -Q, android
+@cindex emacs --debug-init, android
Since Android has no command line, there is normally no way to
specify command-line arguments when starting Emacs. This is very
nasty when you make a mistake in your Emacs initialization files that
prevents Emacs from starting up at all, as the system normally
prevents other programs from accessing Emacs's home directory.
-
- However, Emacs can be started with the equivalent of the
-@code{--quick} option (@pxref{Initial Options}) through a special
-preferences screen, which can be accessed through the Emacs ``app
-info'' page in the system settings application.
+@xref{Initial Options}.
+
+ However, Emacs can be started with the equivalent of either the
+option @code{--quick}, or @code{--debug-init}, through a special
+preferences screen. Under Android 7.0 and later, this can be accessed
+through the Emacs ``app info'' page in the system settings program; on
+older systems, this is displayed as a separate icon on the desktop
+labeled ``Emacs options''.
Consult the manufacturer of your device for more details, as how to
do this varies by device.
diff --git a/java/AndroidManifest.xml.in b/java/AndroidManifest.xml.in
index f7f834e7582..082c4c9373e 100644
--- a/java/AndroidManifest.xml.in
+++ b/java/AndroidManifest.xml.in
@@ -180,6 +180,23 @@ along with GNU Emacs. If not, see
<https://www.gnu.org/licenses/>. -->
</intent-filter>
</activity>
+ <!-- Android 6 and earlier don't display ``application
+ preferences'' activities in Settings, so display the
+ preferences activity as a launcher icon instead. -->
+
+ <activity android:autoRemoveFromRecents="true"
+ android:label="Emacs options"
+ android:enabled="@bool/isBeforeNougat"
+ android:exported="@bool/isBeforeNougat"
+ android:icon="@drawable/emacs_wrench"
+ android:name=".EmacsLauncherPreferencesActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
<provider android:name="org.gnu.emacs.EmacsDocumentsProvider"
android:authorities="org.gnu.emacs"
android:exported="true"
diff --git a/java/org/gnu/emacs/EmacsActivity.java
b/java/org/gnu/emacs/EmacsActivity.java
index b480fc40b2e..7ba268ba42d 100644
--- a/java/org/gnu/emacs/EmacsActivity.java
+++ b/java/org/gnu/emacs/EmacsActivity.java
@@ -193,11 +193,11 @@ public class EmacsActivity extends Activity
ViewTreeObserver observer;
int matchParent;
- /* See if Emacs should be started with -Q. */
+ /* See if Emacs should be started with any extra arguments, such
+ as `--quick'. */
intent = getIntent ();
- EmacsService.needDashQ
- = intent.getBooleanExtra ("org.gnu.emacs.START_DASH_Q",
- false);
+ EmacsService.extraStartupArgument
+ = intent.getStringExtra ("org.gnu.emacs.STARTUP_ARGUMENT");
matchParent = FrameLayout.LayoutParams.MATCH_PARENT;
params
diff --git a/java/res/values/bool.xml
b/java/org/gnu/emacs/EmacsLauncherPreferencesActivity.java
similarity index 57%
copy from java/res/values/bool.xml
copy to java/org/gnu/emacs/EmacsLauncherPreferencesActivity.java
index d37eab745c0..1e1e5d97631 100644
--- a/java/res/values/bool.xml
+++ b/java/org/gnu/emacs/EmacsLauncherPreferencesActivity.java
@@ -1,4 +1,4 @@
-<!-- Boolean resources for GNU Emacs on Android.
+/* Communication module for Android terminals. -*- c-file-style: "GNU" -*-
Copyright (C) 2023 Free Software Foundation, Inc.
@@ -6,8 +6,8 @@ This file is part of GNU Emacs.
GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -15,8 +15,17 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. -->
+along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
-<resources>
- <bool name="isAtLeastKitKat">false</bool>
-</resources>
+package org.gnu.emacs;
+
+/* This class only exists because EmacsPreferencesActivity is already
+ defined as an activity, the system wants a new class in order to
+ define a new activity, and only activities can be enabled or
+ disabled per the API level of the host. */
+
+public final class EmacsLauncherPreferencesActivity
+ extends EmacsPreferencesActivity
+{
+
+}
diff --git a/java/org/gnu/emacs/EmacsPreferencesActivity.java
b/java/org/gnu/emacs/EmacsPreferencesActivity.java
index 70934fa4bd4..7e67cc3679b 100644
--- a/java/org/gnu/emacs/EmacsPreferencesActivity.java
+++ b/java/org/gnu/emacs/EmacsPreferencesActivity.java
@@ -42,10 +42,11 @@ import android.preference.*;
Unfortunately, there is no alternative that looks the same way. */
@SuppressWarnings ("deprecation")
-public final class EmacsPreferencesActivity extends PreferenceActivity
+public class EmacsPreferencesActivity extends PreferenceActivity
{
- /* Restart Emacs with -Q. Call EmacsThread.exit to kill Emacs now, and
- tell the system to EmacsActivity with some parameters later. */
+ /* Restart Emacs with -Q. Call EmacsThread.exit to kill Emacs now,
+ and tell the system to start EmacsActivity with some parameters
+ later. */
private void
startEmacsQ ()
@@ -55,7 +56,24 @@ public final class EmacsPreferencesActivity extends
PreferenceActivity
intent = new Intent (this, EmacsActivity.class);
intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
- intent.putExtra ("org.gnu.emacs.START_DASH_Q", true);
+ intent.putExtra ("org.gnu.emacs.STARTUP_ARGUMENT", "--quick");
+ startActivity (intent);
+ System.exit (0);
+ }
+
+ /* Restart Emacs with `--debug-init'. Call EmacsThread.exit to kill
+ Emacs now, and tell the system to EmacsActivity with some
+ parameters later. */
+
+ private void
+ startEmacsDebugInit ()
+ {
+ Intent intent;
+
+ intent = new Intent (this, EmacsActivity.class);
+ intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK
+ | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ intent.putExtra ("org.gnu.emacs.STARTUP_ARGUMENT", "--debug-init");
startActivity (intent);
System.exit (0);
}
@@ -89,7 +107,7 @@ public final class EmacsPreferencesActivity extends
PreferenceActivity
}
@Override
- public void
+ public final void
onCreate (Bundle savedInstanceState)
{
Preference tem;
@@ -111,7 +129,6 @@ public final class EmacsPreferencesActivity extends
PreferenceActivity
items. */
tem = findPreference ("start_quick");
-
listener = new Preference.OnPreferenceClickListener () {
@Override
public boolean
@@ -123,9 +140,19 @@ public final class EmacsPreferencesActivity extends
PreferenceActivity
};
tem.setOnPreferenceClickListener (listener);
+ tem = findPreference ("start_debug_init");
+ listener = new Preference.OnPreferenceClickListener () {
+ @Override
+ public boolean
+ onPreferenceClick (Preference preference)
+ {
+ startEmacsDebugInit ();
+ return true;
+ }
+ };
+ tem.setOnPreferenceClickListener (listener);
tem = findPreference ("erase_dump");
-
listener = new Preference.OnPreferenceClickListener () {
@Override
public boolean
diff --git a/java/org/gnu/emacs/EmacsService.java
b/java/org/gnu/emacs/EmacsService.java
index 30ef71540a9..bb17d27bcf8 100644
--- a/java/org/gnu/emacs/EmacsService.java
+++ b/java/org/gnu/emacs/EmacsService.java
@@ -79,7 +79,10 @@ public final class EmacsService extends Service
{
public static final String TAG = "EmacsService";
public static volatile EmacsService SERVICE;
- public static boolean needDashQ;
+
+ /* If non-NULL, an extra argument to pass to
+ `android_emacs_init'. */
+ public static String extraStartupArgument;
private EmacsThread thread;
private Handler handler;
@@ -231,7 +234,7 @@ public final class EmacsService extends Service
(float) pixelDensityY,
classPath, EmacsService.this);
}
- }, needDashQ,
+ }, extraStartupArgument,
/* If any file needs to be opened, open it now. */
EmacsOpenActivity.fileToOpen);
thread.start ();
diff --git a/java/org/gnu/emacs/EmacsThread.java
b/java/org/gnu/emacs/EmacsThread.java
index d175fe332b5..468c6530af0 100644
--- a/java/org/gnu/emacs/EmacsThread.java
+++ b/java/org/gnu/emacs/EmacsThread.java
@@ -29,8 +29,9 @@ public class EmacsThread extends Thread
{
private static final String TAG = "EmacsThread";
- /* Whether or not Emacs should be started -Q. */
- private boolean startDashQ;
+ /* Whether or not Emacs should be started with an additional
+ argument, and that additional argument if non-NULL. */
+ private String extraStartupArgument;
/* Runnable run to initialize Emacs. */
private Runnable paramsClosure;
@@ -40,10 +41,10 @@ public class EmacsThread extends Thread
public
EmacsThread (EmacsService service, Runnable paramsClosure,
- boolean startDashQ, String fileToOpen)
+ String extraStartupArgument, String fileToOpen)
{
super ("Emacs main thread");
- this.startDashQ = startDashQ;
+ this.extraStartupArgument = extraStartupArgument;
this.paramsClosure = paramsClosure;
this.fileToOpen = fileToOpen;
}
@@ -56,18 +57,20 @@ public class EmacsThread extends Thread
if (fileToOpen == null)
{
- if (!startDashQ)
+ if (extraStartupArgument == null)
args = new String[] { "libandroid-emacs.so", };
else
- args = new String[] { "libandroid-emacs.so", "-Q", };
+ args = new String[] { "libandroid-emacs.so",
+ extraStartupArgument, };
}
else
{
- if (!startDashQ)
+ if (extraStartupArgument != null)
args = new String[] { "libandroid-emacs.so",
fileToOpen, };
else
- args = new String[] { "libandroid-emacs.so", "-Q",
+ args = new String[] { "libandroid-emacs.so",
+ extraStartupArgument,
fileToOpen, };
}
diff --git a/java/res/drawable/emacs_wrench.png
b/java/res/drawable/emacs_wrench.png
new file mode 100644
index 00000000000..50572d3bed1
Binary files /dev/null and b/java/res/drawable/emacs_wrench.png differ
diff --git a/java/res/values/bool.xml b/java/res/values-v24/bool.xml
similarity index 94%
copy from java/res/values/bool.xml
copy to java/res/values-v24/bool.xml
index d37eab745c0..37f07992995 100644
--- a/java/res/values/bool.xml
+++ b/java/res/values-v24/bool.xml
@@ -18,5 +18,5 @@ You should have received a copy of the GNU General Public
License
along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. -->
<resources>
- <bool name="isAtLeastKitKat">false</bool>
+ <bool name="isBeforeNougat">false</bool>
</resources>
diff --git a/java/res/values/bool.xml b/java/res/values/bool.xml
index d37eab745c0..2b253824e29 100644
--- a/java/res/values/bool.xml
+++ b/java/res/values/bool.xml
@@ -19,4 +19,5 @@ along with GNU Emacs. If not, see
<https://www.gnu.org/licenses/>. -->
<resources>
<bool name="isAtLeastKitKat">false</bool>
+ <bool name="isBeforeNougat">true</bool>
</resources>
diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml
new file mode 100644
index 00000000000..36a47be6c84
--- /dev/null
+++ b/java/res/values/strings.xml
@@ -0,0 +1,39 @@
+<!-- String resources used by GNU Emacs on Android.
+
+Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GNU Emacs.
+
+GNU Emacs is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+GNU Emacs is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. -->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="start_quick_title">
+ Restart Emacs with -Q
+ </string>
+ <string name="start_quick_caption">
+ Restart Emacs, but do not load site lisp or init files.
+ </string>
+ <string name="start_debug_init_title">
+ Restart Emacs with --debug-init
+ </string>
+ <string name="start_debug_init_caption">
+ Restart Emacs, and display the debugger should an error occur while
loading initialization files.
+ </string>
+ <string name="erase_dump_title">
+ Delete dump file
+ </string>
+ <string name="erase_dump_caption">
+ Remove the dumped state created when Emacs was installed.
+ </string>
+</resources>
diff --git a/java/res/xml/preferences.xml b/java/res/xml/preferences.xml
index f0c3abb52e7..d52d28816e5 100644
--- a/java/res/xml/preferences.xml
+++ b/java/res/xml/preferences.xml
@@ -19,10 +19,12 @@ along with GNU Emacs. If not, see
<https://www.gnu.org/licenses/>. -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference android:key="start_quick"
- android:title="Restart Emacs with -Q"
- android:summary="Restart Emacs, but do not load site lisp or
init files."/>
-
+ android:title="@string/start_quick_title"
+ android:summary="@string/start_quick_caption"/>
+ <Preference android:key="start_debug_init"
+ android:title="@string/start_debug_init_title"
+ android:summary="@string/start_debug_init_caption"/>
<Preference android:key="erase_dump"
- android:title="Delete dump file"
- android:summary="Remove the dumped state created when Emacs was
installed"/>
+ android:title="@string/erase_dump_title"
+ android:summary="@string/erase_dump_caption"/>
</PreferenceScreen>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- feature/android 0eb1f4e5712: Allow starting Emacs --debug-init on Android,
Po Lu <=