123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- (cl-defun al/add-to-imenu (regexp &key (index 1) title append)
- "Add REGEXP with INDEX and TITLE to `imenu-generic-expression'.
- If APPEND is nil, add the new element at the end."
- (add-to-list 'imenu-generic-expression
- (list title regexp index)
- append))
- (defvar al/imenu-sections-re "^;;; \\(.+\\)$"
- "Regexp used for \"Sections\" imenu entries.")
- (defvar al/imenu-sections-group "Sections"
- "Group name in imenu index of \"Sections\" entries.
- If nil, put the entries in a top level. See MENU-TITLE in
- `imenu-generic-expression' variable for details.")
- (defun al/imenu-add-sections (&optional regexp)
- "Add REGEXP as a \"Sections\" element to `imenu-generic-expression'.
- If REGEXP is nil, use `al/imenu-sections-re'."
- (al/add-to-imenu (or regexp al/imenu-sections-re)
- :title al/imenu-sections-group
- :append t))
- (defvar al/imenu-js-sections-re "^/// \\(.+\\)$"
- "Regexp used for \"Sections\" imenu entries in `js-mode'.")
- (defun al/imenu-add-js-sections (&optional regexp)
- "Add REGEXP as a \"Sections\" element to `imenu-generic-expression'.
- If REGEXP is nil, use `al/imenu-sections-re'."
- (al/imenu-add-sections al/imenu-js-sections-re)
- (setq-local imenu-create-index-function 'al/js-imenu-create-index))
- (declare-function js--imenu-create-index "js" nil)
- (declare-function imenu--generic-function "imenu" (patterns))
- (defun al/js-imenu-create-index ()
- "Create an index alist for the current js buffer.
- The function is suitable for `imenu-create-index-function'
- variable and intended to be used instead of
- `js--imenu-create-index' in js buffers. It adds the same entries
- as the latter function and also create elements for
- `imenu-generic-expression'."
- (let ((js-index (js--imenu-create-index))
- (generic-index
- (save-excursion
- (save-restriction
- (widen)
- (imenu--generic-function imenu-generic-expression)))))
- (append js-index generic-index)))
- (defvar al/imenu-use-package-re
- (rx bol "(use-package" (+ whitespace)
- (? ?\")
- (group (+ (or (syntax word) (syntax symbol))))
- (? ?\"))
- "Regexp used for `use-package' entries in imenu.")
- (defvar al/imenu-use-package-group "use-package"
- "Group name in imenu index of use-package entries.
- If nil, put the entries in a top level. See MENU-TITLE in
- `imenu-generic-expression' variable for details.")
- ;;;###autoload
- (defun al/imenu-add-use-package ()
- "Add `al/imenu-use-package-re' to `imenu-generic-expression'."
- (al/add-to-imenu al/imenu-use-package-re
- :title al/imenu-use-package-group))
- ;;; (with-)eval-after-load entries
- (defvar al/imenu-eval-after-load-re
- (rx bol "(" (zero-or-one "with-") "eval-after-load" (+ whitespace)
- (zero-or-one (or ?\" ?'))
- (group (+ (or (syntax word) (syntax symbol))))
- (zero-or-one ?\"))
- "Regexp used for `eval-after-load' and `with-eval-after-load'
- entries in imenu.")
- (defvar al/imenu-eval-after-load-group "(with-)eval-after-load")
- ;;;###autoload
- (defun al/imenu-add-eval-after-load ()
- "Add `al/imenu-eval-after-load-re' to `imenu-generic-expression'."
- (al/add-to-imenu al/imenu-eval-after-load-re
- :title al/imenu-eval-after-load-group))
- (provide 'al-imenu)
- ;;; al-imenu.el ends here
|