Commit | Line | Data |
---|---|---|
67832de1 KS |
1 | ;;; mb-depth.el --- Indicate minibuffer-depth in prompt |
2 | ;; | |
dcb8ac09 | 3 | ;; Copyright (C) 2006, 2007, 2008 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 | ||
10 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 | ;; it under the terms of the GNU General Public License as published by | |
64be3a42 | 12 | ;; the Free Software Foundation; either version 3, or (at your option) |
67832de1 KS |
13 | ;; any later version. |
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 | |
21 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
23 | ;; Boston, MA 02110-1301, USA. | |
24 | ||
25 | ;;; Commentary: | |
26 | ;; | |
27 | ;; Defines the minor mode `minibuffer-indicate-depth-mode'. | |
28 | ;; | |
29 | ;; When active, any recursive use of the minibuffer will show | |
30 | ;; the recursion depth in the minibuffer prompt. This is only | |
31 | ;; useful if `enable-recursive-minibuffers' is non-nil. | |
32 | ||
33 | ;;; Code: | |
34 | ||
3d0910ae JB |
35 | (defvar minibuf-depth-indicator-function nil |
36 | "If non-nil, function to set up the minibuffer depth indicator. | |
37 | It is called with one argument, the minibuffer depth, | |
38 | and must return a string.") | |
39 | ||
67832de1 KS |
40 | ;; An overlay covering the prompt. This is a buffer-local variable in |
41 | ;; each affected minibuffer. | |
42 | ;; | |
43 | (defvar minibuf-depth-overlay) | |
44 | (make-variable-buffer-local 'minibuf-depth-overlay) | |
45 | ||
46 | ;; This function goes on minibuffer-setup-hook | |
47 | (defun minibuf-depth-setup-minibuffer () | |
48 | "Set up a minibuffer for `minibuffer-indicate-depth-mode'. | |
49 | The prompt should already have been inserted." | |
50 | (when (> (minibuffer-depth) 1) | |
51 | (setq minibuf-depth-overlay (make-overlay (point-min) (1+ (point-min)))) | |
52 | (overlay-put minibuf-depth-overlay 'before-string | |
3d0910ae JB |
53 | (if minibuf-depth-indicator-function |
54 | (funcall minibuf-depth-indicator-function (minibuffer-depth)) | |
55 | (propertize (format "[%d]" (minibuffer-depth)) 'face 'highlight))) | |
67832de1 KS |
56 | (overlay-put minibuf-depth-overlay 'evaporate t))) |
57 | ||
58 | ;;;###autoload | |
59 | (define-minor-mode minibuffer-indicate-depth-mode | |
60 | "Toggle Minibuffer Indicate Depth mode. | |
61 | When active, any recursive use of the minibuffer will show | |
62 | the recursion depth in the minibuffer prompt. This is only | |
63 | useful if `enable-recursive-minibuffers' is non-nil. | |
64 | ||
65 | With prefix argument ARG, turn on if positive, otherwise off. | |
66 | Returns non-nil if the new state is enabled." | |
67 | :global t | |
68 | :group 'minibuffer | |
69 | (if minibuffer-indicate-depth-mode | |
70 | ;; Enable the mode | |
71 | (add-hook 'minibuffer-setup-hook 'minibuf-depth-setup-minibuffer) | |
72 | ;; Disable the mode | |
73 | (remove-hook 'minibuffer-setup-hook 'minibuf-depth-setup-minibuffer))) | |
74 | ||
75 | (provide 'mb-depth) | |
76 | ||
c4837415 | 77 | ;; arch-tag: 50224089-5bf5-46f8-803d-18f018c5eacf |
67832de1 | 78 | ;;; mb-depth.el ends here |