2 :; set -x; exec "${EMACS:-emacs}" --debug-init --load "$0" "$@"; exit
4 ;; Try the notmuch emacs client located in ../emacs/ directory
6 ;; Run this without arguments; emacs window opens with some usage information
8 ;; Authors: Tomi Ollila <tomi.ollila@iki.fi>
10 ;; https://www.emacswiki.org/emacs/EmacsScripts was a useful starting point...
15 (message "Starting '%s'" load-file-name)
17 (set-buffer "*scratch*")
19 (setq initial-buffer-choice nil
20 inhibit-startup-screen t)
22 (when (featurep 'notmuch)
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.
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")
33 (error "Stopped reading %s" load-file-name)))
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")
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)))
47 ;; they say advice doesn't work for primitives (functions from c source)
48 ;; well, these 'before' advice works for emacs 23.1 - 24.5 (at least)
49 ;; ...and for our purposes 24.3 is enough (there is no load-prefer-newer there)
50 ;; note also that the old, "obsolete" defadvice mechanism was used, but that
51 ;; is the only one available for emacs 23 and 24 up to 24.3.
53 (if (boundp 'load-prefer-newer)
54 (defadvice require (before before-require activate)
55 (unless (featurep feature)
56 (message "require: %s" feature)))
57 ;; else: special require "short-circuit"; after load feature is provided...
58 ;; ... in notmuch sources we always use require and there are no loops
59 (defadvice require (before before-require activate)
60 (unless (featurep feature)
61 (message "require: %s" feature)
62 (let ((name (symbol-name feature)))
63 (if (and (string-match "^notmuch" name)
64 (file-newer-than-file-p
65 (concat try-notmuch-emacs-directory name ".el")
66 (concat try-notmuch-emacs-directory name ".elc")))
67 (load (concat try-notmuch-emacs-directory name ".el") nil nil t t)
70 (insert "Found notmuch emacs client in " try-notmuch-emacs-directory "\n")
72 (let ((notmuch-path (executable-find "notmuch")))
73 (insert "Notmuch CLI executable "
74 (if notmuch-path (concat "is " notmuch-path) "not found!") "\n"))
77 ;; "opportunistic" load-prefer-newer -- will be effective since emacs 24.4
78 (let ((load-prefer-newer t)
79 (force-load-messages t))
81 ;; specifying `debug' here lets the debugger run
82 ;; if `debug-on-error' is non-nil.
84 (let ((error-message-string (error-message-string err)))
85 (insert "\nLoading notmuch failed: " error-message-string "\n")
86 (message "Loading notmuch failed: %s" error-message-string)
87 (insert "See *Messages* buffer for more information.\n")
89 (message "Hint: %s -q (or -Q) may help" load-file-name))
90 (pop-to-buffer "*Messages*")
91 (error "Stopped reading %s" load-file-name))))
94 Go to the end of the following lines and type C-x C-e to evaluate
95 (or C-j which is shorter but inserts evaluation results into buffer)
97 To \"disable\" mail sending, evaluate
98 * (setq message-send-mail-function (lambda () t))
101 (if (file-exists-p (concat try-notmuch-source-directory "/notmuch"))
103 To use accompanied notmuch binary from the same source, evaluate
104 * (setq exec-path (cons \"" try-notmuch-source-directory "\" exec-path))
105 Note: Evaluating the above may be followed by unintended database
106 upgrade and getting back to old version may require dump & restore.
109 (if init-file-user ;; nil, if '-q' or '-Q' is given, but no '-u' 'USER'
111 Your init file was processed during emacs startup. If you want to test
112 notmuch emacs mail client without your emacs init file interfering, Run\n\""
113 (file-name-nondirectory load-file-name) "\" with '-q' (or '-Q') as an argument.
115 (let ((emacs-init-file-name) (notmuch-init-file-name))
116 ;; determining init file name in startup.el/command-line is too complicated
117 ;; to be duplicated here; these 3 file names covers most of the users
118 (mapc (lambda (fn) (if (file-exists-p fn) (setq emacs-init-file-name fn)))
119 '("~/.emacs.d/init.el" "~/.emacs" "~/.emacs.el"))
120 (setq notmuch-init-file-name "~/.emacs.d/notmuch-config.el")
121 (unless (file-exists-p notmuch-init-file-name)
122 (setq notmuch-init-file-name nil))
123 (if (and emacs-init-file-name notmuch-init-file-name)
125 If you want to load your initialization files now, evaluate\n* (progn")
126 (if (or emacs-init-file-name notmuch-init-file-name)
128 If you want to load your initialization file now, evaluate\n*")))
129 (if emacs-init-file-name
130 (insert " (load \"" emacs-init-file-name "\")"))
131 (if notmuch-init-file-name
132 (insert " (load \"" notmuch-init-file-name "\")"))
133 (if (and emacs-init-file-name notmuch-init-file-name)
135 (if (or emacs-init-file-name notmuch-init-file-name)
137 (if (>= emacs-major-version 24)
139 If you want to use packages (e.g. company from elpa) evaluate
140 * (progn (require 'package) (package-initialize))
144 To start notmuch (hello) screen, evaluate
147 (add-hook 'emacs-startup-hook
149 (with-current-buffer "*scratch*"
150 (lisp-interaction-mode)
151 (goto-char (point-min))
153 (set-buffer-modified-p nil))))