]> code.delx.au - gnu-emacs/blobdiff - lisp/imenu.el
Fix w32 memory-management problem when extending buffer text
[gnu-emacs] / lisp / imenu.el
index bad3dd11734a3a9aad2ce2bd9a440094ce97dc50..44bae2dd3b455f04040377c311edea7fee61707e 100644 (file)
@@ -1,6 +1,6 @@
 ;;; imenu.el --- framework for mode-specific buffer indexes  -*- lexical-binding: t -*-
 
-;; Copyright (C) 1994-1998, 2001-2014 Free Software Foundation, Inc.
+;; Copyright (C) 1994-1998, 2001-2016 Free Software Foundation, Inc.
 
 ;; Author: Ake Stenhoff <etxaksf@aom.ericsson.se>
 ;;         Lars Lindberg <lli@sypro.cap.se>
@@ -348,6 +348,12 @@ Don't move point."
 ;;; Lisp
 ;;;
 
+(define-error 'imenu-unavailable "imenu unavailable")
+
+(defun imenu-unavailable-error (format &rest args)
+  (signal 'imenu-unavailable
+          (list (apply #'format-message format args))))
+
 (defun imenu-example--lisp-extract-index-name ()
   ;; Example of a candidate for `imenu-extract-index-name-function'.
   ;; This will generate a flat index of definitions in a lisp file.
@@ -476,7 +482,7 @@ element recalculates the buffer's index alist.")
 
 (defvar imenu--history-list nil
   ;; Making this buffer local caused it not to work!
-  "History list for 'jump-to-function-in-buffer'.")
+  "History list for `jump-to-function-in-buffer'.")
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;
@@ -499,14 +505,11 @@ If REVERSE is non-nil then the beginning is 100 and the end is 0."
   (let ((pos (point))
        (total (buffer-size)))
     (and reverse (setq pos (- total pos)))
-    (if (> total 50000)
-       ;; Avoid overflow from multiplying by 100!
-       (/ (1- pos) (max (/ total 100) 1))
-      (/ (* 100 (1- pos)) (max total 1)))))
+    (floor (* 100.0 (1- pos)) (max total 1))))
 
 (defun imenu--split (list n)
   "Split LIST into sublists of max length N.
-Example (imenu--split '(1 2 3 4 5 6 7 8) 3)-> '((1 2 3) (4 5 6) (7 8))
+Example (imenu--split \\='(1 2 3 4 5 6 7 8) 3) => ((1 2 3) (4 5 6) (7 8))
 The returned list DOES NOT share structure with LIST."
   (let ((remain list)
        (result '())
@@ -593,7 +596,8 @@ See `imenu--index-alist' for the format of the index alist."
                  (funcall imenu-create-index-function))))
        (imenu--truncate-items imenu--index-alist)))
   (or imenu--index-alist noerror
-      (user-error "No items suitable for an index found in this buffer"))
+      (imenu-unavailable-error
+       "No items suitable for an index found in this buffer"))
   (or imenu--index-alist
       (setq imenu--index-alist (list nil)))
   ;; Add a rescan option to the index.
@@ -707,7 +711,7 @@ The alternate method, which is the one most often used, is to call
        ((and imenu-generic-expression)
         (imenu--generic-function imenu-generic-expression))
        (t
-        (user-error "This buffer cannot use `imenu-default-create-index-function'"))))
+         (imenu-unavailable-error "This buffer cannot use `imenu-default-create-index-function'"))))
 
 ;;;
 ;;; Generic index gathering function.
@@ -959,8 +963,8 @@ See the command `imenu' for more information."
            `(menu-item ,name ,imenu--menubar-keymap))
          (use-local-map newmap)
          (add-hook 'menu-bar-update-hook 'imenu-update-menubar)))
-    (user-error "The mode `%s' does not support Imenu"
-                (format-mode-line mode-name))))
+    (imenu-unavailable-error "The mode `%s' does not support Imenu"
+                             (format-mode-line mode-name))))
 
 ;;;###autoload
 (defun imenu-add-menubar-index ()