Skip to content

Commit

Permalink
Add a display-dwim command
Browse files Browse the repository at this point in the history
`imenu-list-display-dwim' is the `imenu-list-display-entry' equivalent of
`imenu-list-ret-dwim'.

Use the new function as keybinding instead of `imenu-list-display-entry', since
it is more flexible.

Document `imenu-list-ret-dwim'.
  • Loading branch information
nbfalcon authored and bmag committed Mar 25, 2021
1 parent 33f29c5 commit a20bf16
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion imenu-list.el
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 309,19 @@ buffer, or in other words: this hook is ran by both
(imenu-list-goto-entry)))

(defun imenu-list-ret-dwim ()
"Jump to or toggle the entry at `point'."
(interactive)
(let ((entry (imenu-list--find-entry)))
(if (imenu--subalist-p entry)
(hs-toggle-hiding)
(imenu-list--goto-entry entry))))

(defun imenu-list-display-dwim ()
"Display or toggle the entry at `point'."
(interactive)
(save-selected-window
(imenu-list-ret-dwim)))

(defalias 'imenu-list-<=
(if (ignore-errors (<= 1 2 3))
#'<=
Expand Down Expand Up @@ -575,7 582,7 @@ If `imenu-list-minor-mode' is already disabled, just call `quit-window'."
(defvar imenu-list-major-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "RET") #'imenu-list-ret-dwim)
(define-key map (kbd "SPC") #'imenu-list-display-entry)
(define-key map (kbd "SPC") #'imenu-list-display-dwim)
(define-key map (kbd "n") #'next-line)
(define-key map (kbd "p") #'previous-line)
(define-key map (kbd "TAB") #'hs-toggle-hiding)
Expand Down

0 comments on commit a20bf16

Please sign in to comment.