Fix (+ bignum float) bug
[emacs.git] / lisp / mb-depth.el
blob84c73cadfa5e2bdc3877675780ebda84a9a6610e
1 ;;; mb-depth.el --- Indicate minibuffer-depth in prompt -*- lexical-binding: t -*-
2 ;;
3 ;; Copyright (C) 2006-2018 Free Software Foundation, Inc.
4 ;;
5 ;; Author: Miles Bader <miles@gnu.org>
6 ;; Keywords: convenience
8 ;; This file is part of GNU Emacs.
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
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; Defines the minor mode `minibuffer-depth-indicate-mode'.
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.
31 ;;; Code:
33 (defvar minibuffer-depth-indicator-function nil
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.")
38 ;; An overlay covering the prompt. This is a buffer-local variable in
39 ;; each affected minibuffer.
41 (defvar minibuffer-depth-overlay)
42 (make-variable-buffer-local 'minibuffer-depth-overlay)
44 ;; This function goes on minibuffer-setup-hook
45 (defun minibuffer-depth-setup ()
46 "Set up a minibuffer for `minibuffer-depth-indicate-mode'.
47 The prompt should already have been inserted."
48 (let ((depth (minibuffer-depth)))
49 (when (> depth 1)
50 (let ((pos (point-min)))
51 (setq minibuffer-depth-overlay (make-overlay pos (1+ pos))))
52 (overlay-put minibuffer-depth-overlay 'before-string
53 (if minibuffer-depth-indicator-function
54 (funcall minibuffer-depth-indicator-function depth)
55 (propertize (format "[%d]" depth) 'face 'highlight)))
56 (overlay-put minibuffer-depth-overlay 'evaporate t))))
58 ;;;###autoload
59 (define-minor-mode minibuffer-depth-indicate-mode
60 "Toggle Minibuffer Depth Indication mode.
62 Minibuffer Depth Indication mode is a global minor mode. When
63 enabled, any recursive use of the minibuffer will show the
64 recursion depth in the minibuffer prompt. This is only useful if
65 `enable-recursive-minibuffers' is non-nil."
66 :global t
67 :group 'minibuffer
68 (if minibuffer-depth-indicate-mode
69 ;; Enable the mode
70 (add-hook 'minibuffer-setup-hook 'minibuffer-depth-setup)
71 ;; Disable the mode
72 (remove-hook 'minibuffer-setup-hook 'minibuffer-depth-setup)))
74 (provide 'mb-depth)
76 ;;; mb-depth.el ends here