unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'Stefan Monnier'" <monnier@iro.umontreal.ca>
Cc: 12717@debbugs.gnu.org
Subject: bug#12717: 24.2.50; [PATCH] `imenu--split-submenus' incorrectly distinguishes submenus
Date: Mon, 29 Oct 2012 23:18:30 -0700	[thread overview]
Message-ID: <00BA7268CCD34A4CA7D11B7F83CE61E8@us.oracle.com> (raw)
In-Reply-To: <jwvr4ogvf83.fsf-monnier+emacs@gnu.org>

> This looks eminently reasonable, except that I don't 
> understand the code enough to be sure (e.g. the current test
> includes (consp elt) whereas imenu--split-menu starts right
> off by calling cdr).  Do you happen to have some kind of test
> case?

I ran into the bug when trying to make use of so-called "special" menu items.

I add two general toggle items to the menus, along with the general item
*Rescan*.  In doing that I discovered the bug.

This is the redefinition of `imenu--make-index-alist' that I use.  It is here
that I add two menu items: one to toggle sorting on/off, and one to toggle
case-sensitivity of sorting when sorting by name.

;; REPLACE ORIGINAL in `imenu.el'.
;;
;; 1. Respect `ignore-comments-flag', if defined:
;;    use `with-comments-hidden'.
;; 2. Add Imenu+ toggle commands to menu.
;;
(defun imenu--make-index-alist (&optional noerror)
  "Create an index alist for the definitions in the current buffer.
This works by using the hook function `imenu-create-index-function'.
Report an error if the list is empty unless NOERROR is supplied and
non-nil.

If `ignore-comments-flag' is defined and non-nil, then respect it,
ignoring hidden comments.

See `imenu--index-alist' for the format of the index alist."
  (or (and imenu--index-alist
           (or (not imenu-auto-rescan)
               (and imenu-auto-rescan
                    (> (buffer-size) imenu-auto-rescan-maxout))))
      ;; Get the index; truncate if necessary
      (progn (setq imenu--index-alist
                   (save-excursion
                     (save-restriction
                       (widen)
                       (if (and (> emacs-major-version 20)
                                (require 'hide-comnt nil t))
                           (let ((search-invisible  nil))
                             (with-comments-hidden
                                 (point-min) (point-max)
                                 (funcall imenu-create-index-function)))
                         (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"))
  (or imenu--index-alist  (setq imenu--index-alist  (list nil)))
  (cons imenu--rescan-item              ; `*Rescan*'.
        (cons '("Toggle Case-Sensitive Name-Sort"
                IGNORE
                (lambda (&rest _ignore)
                  (imenup-toggle-case-sensitive-sorting)))
              (cons '("Toggle Sorting"
                      IGNORE
                      (lambda (&rest _ignore)
                        (imenup-toggle-sort)))
                    imenu--index-alist))))

Clearly, adding general menu items this way is a make-do hack.  I don't use the
POSITION, and the functions invoked don't use any of the args.

And I don't know how, using this kind of menu creation, to, for example, make
the case-sensitivity toggle item inactive when the sort method is not by name.
But I didn't find a better way to add ordinary, non-indexing menu items.

Anyway, that's how I ran into the bug.

The full code is here, FWIW:
http://www.emacswiki.org/emacs-en/download/imenu%2b.el







  reply	other threads:[~2012-10-30  6:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-24  0:07 bug#12717: 24.2.50; [PATCH] `imenu--split-submenus' incorrectly distinguishes submenus Drew Adams
2012-10-30  3:05 ` Stefan Monnier
2012-10-30  6:18   ` Drew Adams [this message]
2012-10-30  6:33     ` Drew Adams
2012-11-15  2:03   ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=00BA7268CCD34A4CA7D11B7F83CE61E8@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=12717@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).