Function: python-imenu-create-flat-index

python-imenu-create-flat-index is a byte-compiled function defined in python.el.gz.

Signature

(python-imenu-create-flat-index &optional ALIST PREFIX)

Documentation

Return flat outline of the current Python buffer for Imenu.

Optional argument ALIST is the tree to be flattened; when nil python-imenu-create-index is used with python-imenu-format-parent-item-jump-label-function python-imenu-format-parent-item-label-function python-imenu-format-item-label-function set to
  (lambda (type name) name)
Optional argument PREFIX is used in recursive calls and should not be passed explicitly.

Converts this:

    (("Foo" . 103)
     ("Bar" . 138)
     ("decorator"
      ("decorator" . 173)
      ("wrap"
       ("wrap" . 353)
       ("wrapped_f" . 393))))

To this:

    (("Foo" . 103)
     ("Bar" . 138)
     ("decorator" . 173)
     ("decorator.wrap" . 353)
     ("decorator.wrapped_f" . 393))

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
(defun python-imenu-create-flat-index (&optional alist prefix)
  "Return flat outline of the current Python buffer for Imenu.
Optional argument ALIST is the tree to be flattened; when nil
`python-imenu-create-index' is used with
`python-imenu-format-parent-item-jump-label-function'
`python-imenu-format-parent-item-label-function'
`python-imenu-format-item-label-function' set to
  (lambda (type name) name)
Optional argument PREFIX is used in recursive calls and should
not be passed explicitly.

Converts this:

    ((\"Foo\" . 103)
     (\"Bar\" . 138)
     (\"decorator\"
      (\"decorator\" . 173)
      (\"wrap\"
       (\"wrap\" . 353)
       (\"wrapped_f\" . 393))))

To this:

    ((\"Foo\" . 103)
     (\"Bar\" . 138)
     (\"decorator\" . 173)
     (\"decorator.wrap\" . 353)
     (\"decorator.wrapped_f\" . 393))"
  ;; Inspired by imenu--flatten-index-alist removed in revno 21853.
  (apply
   'nconc
   (mapcar
    (lambda (item)
      (let ((name (if prefix
                      (concat prefix "." (car item))
                    (car item)))
            (pos (cdr item)))
        (cond ((or (numberp pos) (markerp pos))
               (list (cons name pos)))
              ((listp pos)
               (cons
                (cons name (cdar pos))
                (python-imenu-create-flat-index (cddr item) name))))))
    (or alist
        (let* ((fn (lambda (_type name) name))
               (python-imenu-format-item-label-function fn)
              (python-imenu-format-parent-item-label-function fn)
              (python-imenu-format-parent-item-jump-label-function fn))
          (python-imenu-create-index))))))