Commit | Line | Data |
---|---|---|
67832de1 KS |
1 | ;;; mb-depth.el --- Indicate minibuffer-depth in prompt |
2 | ;; | |
5df4f04c | 3 | ;; Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
67832de1 KS |
4 | ;; |
5 | ;; Author: Miles Bader <miles@gnu.org> | |
6 | ;; Keywords: convenience | |
7 | ||
8 | ;; This file is part of GNU Emacs. | |
9 | ||
eb3fa2cf | 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
67832de1 | 11 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
12 | ;; the Free Software Foundation, either version 3 of the License, or |
13 | ;; (at your option) any later version. | |
67832de1 KS |
14 | |
15 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;; GNU General Public License for more details. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 21 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
67832de1 KS |
22 | |
23 | ;;; Commentary: | |
24 | ;; | |
e94d0645 | 25 | ;; Defines the minor mode `minibuffer-depth-indicate-mode'. |
67832de1 KS |
26 | ;; |
27 | ;; When active, any recursive use of the minibuffer will show | |
28 | ;; the recursion depth in the minibuffer prompt. This is only | |
29 | ;; useful if `enable-recursive-minibuffers' is non-nil. | |
30 | ||
31 | ;;; Code: | |
32 | ||
e94d0645 | 33 | (defvar minibuffer-depth-indicator-function nil |
3d0910ae JB |
34 | "If non-nil, function to set up the minibuffer depth indicator. |
35 | It is called with one argument, the minibuffer depth, | |
36 | and must return a string.") | |
37 | ||
67832de1 KS |
38 | ;; An overlay covering the prompt. This is a buffer-local variable in |
39 | ;; each affected minibuffer. | |
40 | ;; | |
e94d0645 JL |
41 | (defvar minibuffer-depth-overlay) |
42 | (make-variable-buffer-local 'minibuffer-depth-overlay) | |
67832de1 KS |
43 | |
44 | ;; This function goes on minibuffer-setup-hook | |
e94d0645 JL |
45 | (defun minibuffer-depth-setup () |
46 | "Set up a minibuffer for `minibuffer-depth-indicate-mode'. | |
67832de1 KS |
47 | The prompt should already have been inserted." |
48 | (when (> (minibuffer-depth) 1) | |
e94d0645 JL |
49 | (setq minibuffer-depth-overlay (make-overlay (point-min) (1+ (point-min)))) |
50 | (overlay-put minibuffer-depth-overlay 'before-string | |
51 | (if minibuffer-depth-indicator-function | |
52 | (funcall minibuffer-depth-indicator-function (minibuffer-depth)) | |
3d0910ae | 53 | (propertize (format "[%d]" (minibuffer-depth)) 'face 'highlight))) |
e94d0645 | 54 | (overlay-put minibuffer-depth-overlay 'evaporate t))) |
67832de1 KS |
55 | |
56 | ;;;###autoload | |
e94d0645 JL |
57 | (define-minor-mode minibuffer-depth-indicate-mode |
58 | "Toggle Minibuffer Depth Indication mode. | |
67832de1 KS |
59 | When active, any recursive use of the minibuffer will show |
60 | the recursion depth in the minibuffer prompt. This is only | |
61 | useful if `enable-recursive-minibuffers' is non-nil. | |
62 | ||
63 | With prefix argument ARG, turn on if positive, otherwise off. | |
64 | Returns non-nil if the new state is enabled." | |
65 | :global t | |
66 | :group 'minibuffer | |
e94d0645 | 67 | (if minibuffer-depth-indicate-mode |
67832de1 | 68 | ;; Enable the mode |
e94d0645 | 69 | (add-hook 'minibuffer-setup-hook 'minibuffer-depth-setup) |
67832de1 | 70 | ;; Disable the mode |
e94d0645 | 71 | (remove-hook 'minibuffer-setup-hook 'minibuffer-depth-setup))) |
67832de1 KS |
72 | |
73 | (provide 'mb-depth) | |
74 | ||
75 | ;;; mb-depth.el ends here |