unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#18268: 24.3.92; Make imenu sort submenus also (fix included)
@ 2014-08-14 23:18 carlosjosepita
  2014-08-14 23:56 ` bug#18268: Carlos Pita
  0 siblings, 1 reply; 5+ messages in thread
From: carlosjosepita @ 2014-08-14 23:18 UTC (permalink / raw)
  To: 18268

When the current major mode provides submenus (say, python-mode, with
methods nested inside classes, classes being top-level), imenu always
shows them at the top of the menu and unsorted. Only sibling leaves of
the menu tree are sorted.

To fix this, just sort the output of imenu--split submenus when a custom
imenu-sort-function was required by the user:

(defun imenu--split-submenus (alist)
  "Split up each long alist that are nested within ALIST into nested alists.
Return a split and sorted copy of ALIST.  The returned alist DOES
NOT share structure with ALIST."
  (let ((menulist (mapcar (lambda (elt)
                            (if (imenu--subalist-p elt)
                                (imenu--split-menu (cdr elt) (car elt))
                              elt))
                          alist)))
    (if imenu-sort-function
	(sort menulist imenu-sort-function)
      menulist)))

Regards
--
Carlos








In GNU Emacs 24.3.92.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.12.2)
 of 2014-08-07 on memeplex
Windowing system distributor `The X.Org Foundation', version 11.0.11600000
Configured using:
 `configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --with-x-toolkit=gtk3 --with-xft
 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong
 --param=ssp-buffer-size=4' CPPFLAGS=-D_FORTIFY_SOURCE=2
 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro'

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  shell-dirtrack-mode: t
  show-paren-mode: t
  winner-mode: t
  yas-global-mode: t
  yas-minor-mode: t
  ido-everywhere: t
  global-auto-complete-mode: t
  auto-complete-mode: t
  tooltip-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  global-prettify-symbols-mode: t
  prettify-symbols-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
<up> <up> <up> <up> <up> <up> <up> <up> <up> C-SPC 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> C-w <return> C-x C-s <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <prior> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <S-left> <down> <down> <down> C-x d <return> <S-right> 
<down> <down> <down> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
C-e ( r e q u i r e SPC ' i m e n u - a n y w h e e 
r <backspace> <backspace> r e ) C-x C-e <up> <up> <down> 
C-e C-x C-e <S-left> <up> <down> <down> <down> d <down> 
x y e s <return> <up> <up> <up> <return> C-x C-s <down> 
<down> <down> <down> <down> C-x b s c <return> <S-right> 
<next> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <return> ( r e q 
u i r e SPC ' f i x e s ) C-x C-e C-g C-x C-s <up> 
<up> <S-left> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> M-x r e p o <tab> 
r t <tab> <return>

Recent messages:
End of buffer [3 times]
imenu-anywhere
imenu--sort-by-name
Deleting...done
(No changes need to be saved)
progn: Required feature `fixes' was not provided
Quit
Saving file /home/carlos/.emacs...
Wrote /home/carlos/.emacs
Making completion list...

Load-path shadows:
~/.emacs.d/lisp/python hides /usr/share/emacs/24.3.92/lisp/progmodes/python
~/.emacs.d/lisp/rmail hides /usr/share/emacs/24.3.92/lisp/mail/rmail

Features:
(shadow sort mail-extr emacsbug message idna rfc822 mml mml-sec
mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils
mailheader sendmail rfc2047 rfc2045 ietf-drums mail-utils debug
mule-util tramp-cache tramp tramp-compat tramp-loaddefs trampver shell
image-file org-rmail org-mhe org-irc org-info org-gnus org-docview
doc-view image-mode dired org-bibtex bibtex org-bbdb org-w3m org-capture
org org-macro org-footnote org-pcomplete pcomplete org-list org-faces
org-entities noutline outline easy-mmode org-version ob-emacs-lisp ob
ob-tangle org-src ob-ref ob-lob ob-table ob-keys ob-exp ob-comint
ob-core ob-eval org-compat org-macs org-loaddefs format-spec cal-menu
calendar cal-loaddefs edebug misearch multi-isearch jka-compr eieio-opt
speedbar sb-image ezimage dframe network-stream auth-source eieio
byte-opt bytecomp byte-compile cconv eieio-core gnus-util mm-util
mail-prsvr password-cache starttls tls warnings vc-git jedi
python-environment epc ctable concurrent deferred python skeleton
derived pcase rx json imenu-anywhere cl-macs imenu thingatpt find-func
flymake compile comint ansi-color paren winner ring windmove advice
help-fns yasnippet help-mode cl gv ido auto-complete-config
auto-complete popup edmacro kmacro cl-loaddefs cl-lib info easymenu
package wombat-theme time-date tooltip electric uniquify ediff-hook
vc-hooks lisp-float-type mwheel x-win x-dnd tool-bar dnd fontset image
regexp-opt fringe tabulated-list newcomment lisp-mode prog-mode register
page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock
font-lock syntax facemenu font-core frame cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew
greek romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process dbusbind
gfilenotify dynamic-setting system-font-setting font-render-setting
move-toolbar gtk x-toolkit x multi-tty emacs)

Memory information:
((conses 16 361814 22370)
 (symbols 48 36390 0)
 (miscs 40 1153 1328)
 (strings 32 103033 9931)
 (string-bytes 1 2189271)
 (vectors 16 35814)
 (vector-slots 8 1446654 27798)
 (floats 8 665 911)
 (intervals 56 9261 0)
 (buffers 960 26)
 (heap 1024 67756 2517))





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#18268:
  2014-08-14 23:18 bug#18268: 24.3.92; Make imenu sort submenus also (fix included) carlosjosepita
@ 2014-08-14 23:56 ` Carlos Pita
  2014-08-15 15:18   ` bug#18268: Carlos Pita
  0 siblings, 1 reply; 5+ messages in thread
From: Carlos Pita @ 2014-08-14 23:56 UTC (permalink / raw)
  To: 18268

Besides that, I see no point in the keep-at-top behaviour of
imenu--split-menu, which pushes every submenu to the top of its parent
menu. The user is looking for a name in a list sorted according to
some required criterion. Splitting this list in two sorted lists in
virtue of a totally different criterion will only bring confusion.
It's ok to make this the default behaviour, in case the user isn't
interested in any particular ordering (that is, imenu-sort-function is
nil). But if a particular ordering is required, then it should be
honoured. Or, at least, an option should be provided to turn off
keep-at-top.

If you agree I will gladly provide a patch.

Regards
--
Carlos





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#18268:
  2014-08-14 23:56 ` bug#18268: Carlos Pita
@ 2014-08-15 15:18   ` Carlos Pita
  2016-02-23 12:21     ` bug#18268: Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Carlos Pita @ 2014-08-15 15:18 UTC (permalink / raw)
  To: 18268

The following is a simpler and more correct patch that also lets the
user (final user or major mode developer) control whether the submenus
are sorted or kept on top. The guiding idea is that there is two major
ways to offer an imenu, according to the mode:

1) Some modes show a hierarchy of language objects. For example:
python-mode will show class/method, function/nested function, etc.
relationships; org-mode will show section/subsection/subsubsection/...
hierarchies. In these cases keeping the submenus on top is not
adequate since it creates an artificial split of the list.

2) Some modes show top level submenus with fixed categories
(Functions, Classes, Variables, etc). These modes will presumably want
to keep the submenus on top and sorted in the order they were given.

3) Other modes would not fit either (1) or (2). Then, there is always
the possibility of turning off sorting and provide the menu structure
as is.

Regards
--
Carlos

156a157,161
> (defcustom imenu-sort-submenus nil
>   "Non-nil means Imenu should sort submenus also (using imenu-sort-function)."
>   :type 'boolean
>   :group 'imenu)
>
541c546,547
<       (when (imenu--subalist-p item)
---
>       (when (and (not imenu-sort-submenus)
>                  (imenu--subalist-p item))

On Thu, Aug 14, 2014 at 8:56 PM, Carlos Pita <carlosjosepita@gmail.com> wrote:
> Besides that, I see no point in the keep-at-top behaviour of
> imenu--split-menu, which pushes every submenu to the top of its parent
> menu. The user is looking for a name in a list sorted according to
> some required criterion. Splitting this list in two sorted lists in
> virtue of a totally different criterion will only bring confusion.
> It's ok to make this the default behaviour, in case the user isn't
> interested in any particular ordering (that is, imenu-sort-function is
> nil). But if a particular ordering is required, then it should be
> honoured. Or, at least, an option should be provided to turn off
> keep-at-top.
>
> If you agree I will gladly provide a patch.
>
> Regards
> --
> Carlos





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#18268:
  2014-08-15 15:18   ` bug#18268: Carlos Pita
@ 2016-02-23 12:21     ` Lars Ingebrigtsen
  2019-06-25 21:45       ` bug#18268: Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-23 12:21 UTC (permalink / raw)
  To: Carlos Pita; +Cc: 18268

Carlos Pita <carlosjosepita@gmail.com> writes:

> The following is a simpler and more correct patch that also lets the
> user (final user or major mode developer) control whether the submenus
> are sorted or kept on top. The guiding idea is that there is two major
> ways to offer an imenu, according to the mode:
>
> 1) Some modes show a hierarchy of language objects. For example:
> python-mode will show class/method, function/nested function, etc.
> relationships; org-mode will show section/subsection/subsubsection/...
> hierarchies. In these cases keeping the submenus on top is not
> adequate since it creates an artificial split of the list.
>
> 2) Some modes show top level submenus with fixed categories
> (Functions, Classes, Variables, etc). These modes will presumably want
> to keep the submenus on top and sorted in the order they were given.
>
> 3) Other modes would not fit either (1) or (2). Then, there is always
> the possibility of turning off sorting and provide the menu structure
> as is.
>
> Regards
> --
> Carlos
>
> 156a157,161
>> (defcustom imenu-sort-submenus nil
>>   "Non-nil means Imenu should sort submenus also (using imenu-sort-function)."
>>   :type 'boolean
>>   :group 'imenu)

Could you resubmit this as a context patch instead of a "raw" patch?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#18268:
  2016-02-23 12:21     ` bug#18268: Lars Ingebrigtsen
@ 2019-06-25 21:45       ` Lars Ingebrigtsen
  0 siblings, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-25 21:45 UTC (permalink / raw)
  To: Carlos Pita; +Cc: 18268

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Could you resubmit this as a context patch instead of a "raw" patch?

That was three years ago, so I'm closing this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-06-25 21:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-14 23:18 bug#18268: 24.3.92; Make imenu sort submenus also (fix included) carlosjosepita
2014-08-14 23:56 ` bug#18268: Carlos Pita
2014-08-15 15:18   ` bug#18268: Carlos Pita
2016-02-23 12:21     ` bug#18268: Lars Ingebrigtsen
2019-06-25 21:45       ` bug#18268: Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).