]> git.notmuchmail.org Git - notmuch/blob - devel/try-emacs-mua
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / devel / try-emacs-mua
1 #!/bin/sh
2 :; set -x; exec "${EMACS:-emacs}" --debug-init --load "$0" "$@"; exit
3 ;;
4 ;; Try the notmuch emacs client located in ../emacs/ directory
5 ;;
6 ;; Run this without arguments; emacs window opens with some usage information
7 ;;
8 ;; Authors: Tomi Ollila <tomi.ollila@iki.fi>
9 ;;
10 ;; https://www.emacswiki.org/emacs/EmacsScripts was a useful starting point...
11 ;;
12 ;; Licence: GPLv3+
13 ;;
14
15 (message "Starting '%s'" load-file-name)
16
17 (set-buffer "*scratch*")
18
19 (setq initial-buffer-choice nil
20       inhibit-startup-screen t)
21
22 (when (featurep 'notmuch)
23   (insert "
24 Notmuch has been loaded to this emacs (during processing of the init file)
25 which means it is (most probably) loaded from different source than expected.
26
27 Please run \"" (file-name-nondirectory load-file-name)
28 "\" with '-q' (or '-Q') as an argument, to disable
29 processing of the init file -- you can load it after emacs has started\n
30 exit emacs (y or n)? ")
31   (if (y-or-n-p "exit emacs")
32       (kill-emacs)
33     (error "Stopped reading %s" load-file-name)))
34
35 (let ((pdir (file-name-directory
36              (directory-file-name (file-name-directory load-file-name)))))
37   (unless (file-exists-p (concat pdir "emacs/notmuch-lib.el"))
38     (insert "Cannot find notmuch-emacs source directory
39 while looking at: " pdir "emacs\n\nexit emacs (y or n)? ")
40     (if (y-or-n-p "exit emacs")
41         (kill-emacs)
42       (error "Stopped reading %s" load-file-name)))
43   (setq try-notmuch-source-directory (directory-file-name pdir)
44         try-notmuch-emacs-directory (concat pdir "emacs/")
45         load-path (cons try-notmuch-emacs-directory load-path)))
46
47 (define-advice require
48     (:before (feature &optional _filename _noerror) notmuch)
49   (unless (featurep feature)
50     (message "require: %s" feature)))
51
52 (insert "Found notmuch emacs client in " try-notmuch-emacs-directory "\n")
53
54 (let ((notmuch-path (executable-find "notmuch")))
55   (insert "Notmuch CLI executable "
56           (if notmuch-path (concat "is " notmuch-path) "not found!") "\n"))
57
58 (condition-case err
59 ;; "opportunistic" load-prefer-newer -- will be effective since emacs 24.4
60     (let ((load-prefer-newer t)
61           (force-load-messages t))
62       (require 'notmuch))
63   ;; specifying `debug' here lets the debugger run
64   ;; if `debug-on-error' is non-nil.
65   ((debug error)
66    (let ((error-message-string (error-message-string err)))
67      (insert "\nLoading notmuch failed: " error-message-string "\n")
68      (message "Loading notmuch failed: %s" error-message-string)
69      (insert "See *Messages* buffer for more information.\n")
70      (if init-file-user
71          (message "Hint: %s -q (or -Q) may help" load-file-name))
72      (pop-to-buffer "*Messages*")
73      (error "Stopped reading %s" load-file-name))))
74
75 (insert "
76 Go to the end of the following lines and type C-x C-e to evaluate
77 (or C-j which is shorter but inserts evaluation results into buffer)
78
79 To \"disable\" mail sending, evaluate
80 * (setq message-send-mail-function (lambda () t))
81 ")
82
83 (if (file-exists-p (concat try-notmuch-source-directory "/notmuch"))
84     (insert "
85 To use accompanied notmuch binary from the same source, evaluate
86 * (setq exec-path (cons \"" try-notmuch-source-directory  "\" exec-path))
87 Note: Evaluating the above may be followed by unintended database
88 upgrade and getting back to old version may require dump & restore.
89 "))
90
91 (if init-file-user ;; nil, if '-q' or '-Q' is given, but no '-u' 'USER'
92     (insert "
93 Your init file was processed during emacs startup. If you want to test
94 notmuch emacs mail client without your emacs init file interfering, Run\n\""
95 (file-name-nondirectory load-file-name) "\" with '-q' (or '-Q') as an argument.
96 ")
97   (let ((emacs-init-file-name) (notmuch-init-file-name))
98     ;; determining init file name in startup.el/command-line is too complicated
99     ;; to be duplicated here; these 3 file names covers most of the users
100     (mapc (lambda (fn) (if (file-exists-p fn) (setq emacs-init-file-name fn)))
101           '("~/.emacs.d/init.el" "~/.emacs" "~/.emacs.el"))
102     (setq notmuch-init-file-name "~/.emacs.d/notmuch-config.el")
103     (unless (file-exists-p notmuch-init-file-name)
104         (setq notmuch-init-file-name nil))
105     (if (and emacs-init-file-name notmuch-init-file-name)
106         (insert "
107 If you want to load your initialization files now, evaluate\n* (progn")
108       (if (or emacs-init-file-name notmuch-init-file-name)
109           (insert "
110 If you want to load your initialization file now, evaluate\n*")))
111     (if emacs-init-file-name
112         (insert " (load \"" emacs-init-file-name "\")"))
113     (if notmuch-init-file-name
114         (insert " (load \"" notmuch-init-file-name "\")"))
115     (if (and emacs-init-file-name notmuch-init-file-name)
116         (insert ")"))
117     (if (or emacs-init-file-name notmuch-init-file-name)
118         (insert "\n")))
119   (if (>= emacs-major-version 24)
120       (insert "
121 If you want to use packages (e.g. company from elpa) evaluate
122 * (progn (require 'package) (package-initialize))
123 ")))
124
125 (insert "
126 To start notmuch (hello) screen, evaluate
127 * (notmuch-hello)")
128
129 (add-hook 'emacs-startup-hook
130           (lambda ()
131             (with-current-buffer "*scratch*"
132               (lisp-interaction-mode)
133               (goto-char (point-min))
134               (forward-line 2)
135               (set-buffer-modified-p nil))))
136
137 ;; Local Variables:
138 ;; mode: emacs-lisp
139 ;; End: