* [PATCH v3] devel/emacs: add devel/try-emacs-mua.sh
@ 2015-11-13 23:29 Tomi Ollila
2015-11-15 10:07 ` Tomi Ollila
0 siblings, 1 reply; 2+ messages in thread
From: Tomi Ollila @ 2015-11-13 23:29 UTC (permalink / raw)
To: notmuch; +Cc: tomi.ollila
devel/try-emacs-mua.sh provides an easy way to try and experiment with
the notmuch emacs client provided in emacs subdirectory of notmuch
source tree.
User is required to choose whether to run emacs with -q, -Q or neither
-- and experienced ones may add other command line options, like
'-f notmuch'.
With emaces older than 24.4 it is checked that none of the .elc files
in notmuch/emacs directory is older than their corresponding .el files
before running emacs. With newer emaces variable `load-prefer-newer'
is effective so having old .elcs do not matter.
Last possibility for "error" is when emacs starts and loads notmuch
(by init file) before there is change to have notmuch/emacs directory
in load-path. This time the message is written to emacs' *scratch* buffer.
If everything is OK, the *scratch* buffer is filled with some lisp code
which user can evaluate before running notmuch functions.
---
Version 3 (I guess) -- the discovery Mark made in
id:87si4bwrsu.fsf@qmul.ac.uk has been fixed (originally to perl code,
but now converted to shell) -- and changed to just recognize that there
are old .elc files -- and the check is done only for emacses < 24.4.
Now loading of "notmuch" is wrapped in (let ((load-prefer-newer t)) ...).
I tried tricks to ensure that notmuch*.el files are (always) loaded, but
it either got too complicated (hacky, potentially fragile defadvices), or
I saw plenty of *.el.gz uncompressions happening (and recursion loop in
jka-compr before that)...
There is one notably change to the previous one -- before loading notmuch
there is check whether it is already loaded; if it is there is no point
going further here. Thanks for this discovery goes to IRC debugging
section with (mark and) "pseudomyne".
devel/try-emacs-mua.sh | 117 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 117 insertions(+)
create mode 100755 devel/try-emacs-mua.sh
diff --git a/devel/try-emacs-mua.sh b/devel/try-emacs-mua.sh
new file mode 100755
index 000000000000..e8406e3cb143
--- /dev/null
+++ b/devel/try-emacs-mua.sh
@@ -0,0 +1,117 @@
+#!/bin/sh
+
+# This script offers an easy way to try and experiment with the
+# notmuch emacs client provided in notmuch/emacs directory.
+
+set -eu
+
+test $# -gt 0 || {
+ exec >&2
+ echo
+ echo "Usage: $0 '' | q | Q [other-emacs-args]"
+ echo
+ printf " $0 %s\n" "'' starts emacs without either -q or -Q option" \
+ "q starts emacs with -q" \
+ "Q starts emacs with -Q"
+ echo
+ exit 1
+}
+
+case $1 in '') opt=
+ ;; q | -q) opt=-q
+ ;; Q | -Q) opt=-Q
+ ;; *) echo "option '$1' not '', 'q' nor 'Q'" >&2; exit 1
+esac
+shift
+
+case $0 in
+ *\"*) echo "'$0' contain one or more '\"'s" >&2; exit 1 ;;
+ *\\*) echo "'$0' contain one or more '\\'s" >&2; exit 1 ;;
+ */*) d0=${0%/*} ;;
+ *) d0=.
+esac
+
+pwd=$PWD
+cd "$d0"/..
+nmd=$PWD
+emd=$PWD/emacs
+
+test -f "$emd"/notmuch-lib.el || {
+ echo "Cannot find notmuch-emacs source directory" >&2
+ exit 1
+}
+
+case `exec 2>&1 "${EMACS:-emacs}" -Q --batch -eval \
+ '(message (if (boundp '\''load-prefer-newer) "<-yes->" "<-no->"))'`
+in (*'<-no->'*)
+ allnew=true
+ for elc in "$emd"/*.elc
+ do
+ test -f "$elc" || continue
+ if test "$elc" -ot "${elc%c}"
+ then
+ echo "'$elc' is older than '${elc%c}'" >&2
+ allnew=false
+ fi
+ done
+ $allnew || {
+ exec >&2
+ echo
+ echo "In directory '$emd' there are .elc files that are"
+ echo "older than their corresponding .el files."
+ echo "Please remove (or recompile) these older files and try again."
+ echo
+ exit 1
+ }
+ unset allnew
+esac
+
+if test -x "$nmd"/notmuch
+then
+ nmin='
+To use accompanied notmuch binary from the same source, evaluate
+(setq exec-path (cons \"'"$nmd"'\" exec-path))
+Note: Evaluating the above may be followed by unintended database
+upgrade and getting back to old version may require dump & restore.
+'
+else
+ nmin=
+fi
+
+if test "$opt" = '-q' || test "$opt" = '-Q'
+then
+ qin='
+If you want to load your .emacs startup file now, evaluate
+(load \"~/.emacs\")
+
+If you want to use packages (e.g. company from elpa) evaluate
+(progn (require '\''package) (package-initialize))
+'
+else
+ qin='
+To view initialization time messages, evaluate
+(pop-to-buffer \"*Messages*\")
+'
+fi
+
+cd "$pwd"
+
+exec "${EMACS:-emacs}" $opt --debug-init -L "$emd" --eval '
+(with-current-buffer "*scratch*"
+ (if (featurep '\''notmuch)
+ (insert "
+Notmuch has been loaded to this emacs (during processing of the init file)
+which means it is (most probably) loaded from different source than expected.
+
+Please rerun \"'"$0"'\" with '"'q'"' to disable
+processing of the init file -- you can load it after emacs has started.\n\n")
+ (let ((load-prefer-newer t)) (load "notmuch" t))
+ (insert "
+Go to the end of the following lines and type C-x C-e to evaluate
+(or C-j which is shorter but inserts evaluation results into buffer)
+
+To \"disable\" mail sending, evaluate
+(setq message-send-mail-function (lambda () t))
+'"$nmin$qin"'
+To start notmuch (hello) screen, evaluate
+(notmuch-hello)")) (set-buffer-modified-p nil))' "$@"
--
2.0.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] devel/emacs: add devel/try-emacs-mua.sh
2015-11-13 23:29 [PATCH v3] devel/emacs: add devel/try-emacs-mua.sh Tomi Ollila
@ 2015-11-15 10:07 ` Tomi Ollila
0 siblings, 0 replies; 2+ messages in thread
From: Tomi Ollila @ 2015-11-15 10:07 UTC (permalink / raw)
To: notmuch
I am marking this obsolete as I got and idea if works is going to
be pretty cool... But if it doesn't work then we'll come back
to this version.
Tomi
On Sat, Nov 14 2015, Tomi Ollila <tomi.ollila@iki.fi> wrote:
> devel/try-emacs-mua.sh provides an easy way to try and experiment with
> the notmuch emacs client provided in emacs subdirectory of notmuch
> source tree.
>
> User is required to choose whether to run emacs with -q, -Q or neither
> -- and experienced ones may add other command line options, like
> '-f notmuch'.
>
> With emaces older than 24.4 it is checked that none of the .elc files
> in notmuch/emacs directory is older than their corresponding .el files
> before running emacs. With newer emaces variable `load-prefer-newer'
> is effective so having old .elcs do not matter.
>
> Last possibility for "error" is when emacs starts and loads notmuch
> (by init file) before there is change to have notmuch/emacs directory
> in load-path. This time the message is written to emacs' *scratch* buffer.
>
> If everything is OK, the *scratch* buffer is filled with some lisp code
> which user can evaluate before running notmuch functions.
> ---
>
> Version 3 (I guess) -- the discovery Mark made in
> id:87si4bwrsu.fsf@qmul.ac.uk has been fixed (originally to perl code,
> but now converted to shell) -- and changed to just recognize that there
> are old .elc files -- and the check is done only for emacses < 24.4.
> Now loading of "notmuch" is wrapped in (let ((load-prefer-newer t)) ...).
>
> I tried tricks to ensure that notmuch*.el files are (always) loaded, but
> it either got too complicated (hacky, potentially fragile defadvices), or
> I saw plenty of *.el.gz uncompressions happening (and recursion loop in
> jka-compr before that)...
>
> There is one notably change to the previous one -- before loading notmuch
> there is check whether it is already loaded; if it is there is no point
> going further here. Thanks for this discovery goes to IRC debugging
> section with (mark and) "pseudomyne".
>
> devel/try-emacs-mua.sh | 117 +++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 117 insertions(+)
> create mode 100755 devel/try-emacs-mua.sh
>
> diff --git a/devel/try-emacs-mua.sh b/devel/try-emacs-mua.sh
> new file mode 100755
> index 000000000000..e8406e3cb143
> --- /dev/null
> +++ b/devel/try-emacs-mua.sh
> @@ -0,0 +1,117 @@
> +#!/bin/sh
> +
> +# This script offers an easy way to try and experiment with the
> +# notmuch emacs client provided in notmuch/emacs directory.
> +
> +set -eu
> +
> +test $# -gt 0 || {
> + exec >&2
> + echo
> + echo "Usage: $0 '' | q | Q [other-emacs-args]"
> + echo
> + printf " $0 %s\n" "'' starts emacs without either -q or -Q option" \
> + "q starts emacs with -q" \
> + "Q starts emacs with -Q"
> + echo
> + exit 1
> +}
> +
> +case $1 in '') opt=
> + ;; q | -q) opt=-q
> + ;; Q | -Q) opt=-Q
> + ;; *) echo "option '$1' not '', 'q' nor 'Q'" >&2; exit 1
> +esac
> +shift
> +
> +case $0 in
> + *\"*) echo "'$0' contain one or more '\"'s" >&2; exit 1 ;;
> + *\\*) echo "'$0' contain one or more '\\'s" >&2; exit 1 ;;
> + */*) d0=${0%/*} ;;
> + *) d0=.
> +esac
> +
> +pwd=$PWD
> +cd "$d0"/..
> +nmd=$PWD
> +emd=$PWD/emacs
> +
> +test -f "$emd"/notmuch-lib.el || {
> + echo "Cannot find notmuch-emacs source directory" >&2
> + exit 1
> +}
> +
> +case `exec 2>&1 "${EMACS:-emacs}" -Q --batch -eval \
> + '(message (if (boundp '\''load-prefer-newer) "<-yes->" "<-no->"))'`
> +in (*'<-no->'*)
> + allnew=true
> + for elc in "$emd"/*.elc
> + do
> + test -f "$elc" || continue
> + if test "$elc" -ot "${elc%c}"
> + then
> + echo "'$elc' is older than '${elc%c}'" >&2
> + allnew=false
> + fi
> + done
> + $allnew || {
> + exec >&2
> + echo
> + echo "In directory '$emd' there are .elc files that are"
> + echo "older than their corresponding .el files."
> + echo "Please remove (or recompile) these older files and try again."
> + echo
> + exit 1
> + }
> + unset allnew
> +esac
> +
> +if test -x "$nmd"/notmuch
> +then
> + nmin='
> +To use accompanied notmuch binary from the same source, evaluate
> +(setq exec-path (cons \"'"$nmd"'\" exec-path))
> +Note: Evaluating the above may be followed by unintended database
> +upgrade and getting back to old version may require dump & restore.
> +'
> +else
> + nmin=
> +fi
> +
> +if test "$opt" = '-q' || test "$opt" = '-Q'
> +then
> + qin='
> +If you want to load your .emacs startup file now, evaluate
> +(load \"~/.emacs\")
> +
> +If you want to use packages (e.g. company from elpa) evaluate
> +(progn (require '\''package) (package-initialize))
> +'
> +else
> + qin='
> +To view initialization time messages, evaluate
> +(pop-to-buffer \"*Messages*\")
> +'
> +fi
> +
> +cd "$pwd"
> +
> +exec "${EMACS:-emacs}" $opt --debug-init -L "$emd" --eval '
> +(with-current-buffer "*scratch*"
> + (if (featurep '\''notmuch)
> + (insert "
> +Notmuch has been loaded to this emacs (during processing of the init file)
> +which means it is (most probably) loaded from different source than expected.
> +
> +Please rerun \"'"$0"'\" with '"'q'"' to disable
> +processing of the init file -- you can load it after emacs has started.\n\n")
> + (let ((load-prefer-newer t)) (load "notmuch" t))
> + (insert "
> +Go to the end of the following lines and type C-x C-e to evaluate
> +(or C-j which is shorter but inserts evaluation results into buffer)
> +
> +To \"disable\" mail sending, evaluate
> +(setq message-send-mail-function (lambda () t))
> +'"$nmin$qin"'
> +To start notmuch (hello) screen, evaluate
> +(notmuch-hello)")) (set-buffer-modified-p nil))' "$@"
> --
> 2.0.0
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-11-15 10:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-13 23:29 [PATCH v3] devel/emacs: add devel/try-emacs-mua.sh Tomi Ollila
2015-11-15 10:07 ` Tomi Ollila
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).