]> git.notmuchmail.org Git - notmuch/blob - emacs/notmuch-compat.el
emacs/desktop: update to use notmuch-emacs-mua and handle mailto
[notmuch] / emacs / notmuch-compat.el
1 ;; Compatibility functions for emacs 23 and 24 pre 24.4
2
3 ;; The functions in this file are copied from eamcs 24.4 and are
4 ;; Copyright (C) 1985-1986, 1992, 1994-1995, 1999-2014 Free Software
5 ;; Foundation, Inc.
6
7 (if (fboundp 'setq-local)
8     (defalias 'notmuch-setq-local 'setq-local)
9   (defmacro notmuch-setq-local (var val)
10     "Set variable VAR to value VAL in current buffer.
11
12 Backport of setq-local for emacs without setq-local (pre 24.3)."
13     `(set (make-local-variable ',var) ,val)))
14
15 (if (fboundp 'read-char-choice)
16     (defalias 'notmuch-read-char-choice 'read-char-choice)
17   (defun notmuch-read-char-choice (prompt chars &optional inhibit-keyboard-quit)
18   "Read and return one of CHARS, prompting for PROMPT.
19 Any input that is not one of CHARS is ignored.
20
21 If optional argument INHIBIT-KEYBOARD-QUIT is non-nil, ignore
22 keyboard-quit events while waiting for a valid input.
23
24 This is an exact copy of this function from emacs 24 for use on
25 emacs 23, except with the one emacs 24 only function it calls
26 inlined."
27   (unless (consp chars)
28     (error "Called `read-char-choice' without valid char choices"))
29   (let (char done show-help (helpbuf " *Char Help*"))
30     (let ((cursor-in-echo-area t)
31           (executing-kbd-macro executing-kbd-macro)
32           (esc-flag nil))
33       (save-window-excursion          ; in case we call help-form-show
34         (while (not done)
35           (unless (get-text-property 0 'face prompt)
36             (setq prompt (propertize prompt 'face 'minibuffer-prompt)))
37           (setq char (let ((inhibit-quit inhibit-keyboard-quit))
38                        (read-key prompt)))
39           (and show-help (buffer-live-p (get-buffer helpbuf))
40                (kill-buffer helpbuf))
41           (cond
42            ((not (numberp char)))
43            ;; If caller has set help-form, that's enough.
44            ;; They don't explicitly have to add help-char to chars.
45            ((and help-form
46                  (eq char help-char)
47                  (setq show-help t)
48                  ;; This is an inlined copy of help-form-show as that
49                  ;; was introduced in emacs 24 too.
50                  (let ((msg (eval help-form)))
51                    (if (stringp msg)
52                        (with-output-to-temp-buffer " *Char Help*"
53                          (princ msg))))))
54            ((memq char chars)
55             (setq done t))
56            ((and executing-kbd-macro (= char -1))
57             ;; read-event returns -1 if we are in a kbd macro and
58             ;; there are no more events in the macro.  Attempt to
59             ;; get an event interactively.
60             (setq executing-kbd-macro nil))
61            ((not inhibit-keyboard-quit)
62             (cond
63              ((and (null esc-flag) (eq char ?\e))
64               (setq esc-flag t))
65              ((memq char '(?\C-g ?\e))
66               (keyboard-quit))))))))
67     ;; Display the question with the answer.  But without cursor-in-echo-area.
68     (message "%s%s" prompt (char-to-string char))
69     char)))
70
71 ;; End of compatibility functions
72
73 (provide 'notmuch-compat)