unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Damien Cassou <damien@cassou.me>
To: 26457@debbugs.gnu.org
Subject: bug#26457: 25.2; Cannot pass a function to imenu-generic-expression
Date: Wed, 12 Apr 2017 09:32:08 +0200	[thread overview]
Message-ID: <87bms26pzb.fsf@cassou.me> (raw)
In-Reply-To: <87a87mz14q.fsf@cassou.me> (Damien Cassou's message of "Wed, 12 Apr 2017 06:43:49 +0200")

[-- Attachment #1: Type: text/plain, Size: 351 bytes --]

Damien Cassou <damien@cassou.me> writes:
>  sort: Wrong type argument: number-or-marker-p, (#<marker at 72 
>  in 
> *scratch*> (lambda (item pos) (message "%s" item)))

here is a patch 

-- 
Damien Cassou
http://damiencassou.seasidehosting.st

"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-imenu-sort-by-position-for-non-pairs-parameters-.patch --]
[-- Type: text/x-patch, Size: 1907 bytes --]

From ae61937fd0ed634c3f63645f76c4e6b681d499be Mon Sep 17 00:00:00 2001
From: Damien Cassou <damien@cassou.me>
Date: Wed, 12 Apr 2017 07:35:56 +0200
Subject: [PATCH] Fix imenu--sort-by-position for non-pairs parameters
 (bug#26457)

* lisp/imenu.el (imenu--sort-by-position): Fix to accept lists beyond
  pairs.
* test/lisp/imenu-tests.el: Add 2 tests for `imenu--sort-by-position`.
---
 lisp/imenu.el            |  7 ++++++-
 test/lisp/imenu-tests.el | 10 ++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/lisp/imenu.el b/lisp/imenu.el
index 0f47a92..7606593 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -499,7 +499,12 @@ imenu--sort-by-name
   (string-lessp (car item1) (car item2)))
 
 (defun imenu--sort-by-position (item1 item2)
-  (< (cdr item1) (cdr item2)))
+  "Comparison function to sort items depending on their position.
+Return t if and only if ITEM1's position is lower than ITEM2's
+position."
+  (if (listp (cdr item1))
+      (< (cadr item1) (cadr item2))
+    (< (cdr item1) (cdr item2))))
 
 (defun imenu--relative-position (&optional reverse)
   "Support function to calculate relative position in buffer.
diff --git a/test/lisp/imenu-tests.el b/test/lisp/imenu-tests.el
index 480368f..9309094 100644
--- a/test/lisp/imenu-tests.el
+++ b/test/lisp/imenu-tests.el
@@ -83,6 +83,16 @@ imenu-simple-scan-deftest
 }
 " '("a" "b" "c" "ABC_D"))
 
+(ert-deftest imenu--sort-by-position-pairs ()
+  (should (imenu--sort-by-position '("a" . 2) '("a" . 3)))
+  (should-not (imenu--sort-by-position '("a" . 3) '("a" . 2))))
+
+;; Regression test for bug#26457: 25.2; Cannot pass a function to
+;; imenu-generic-expression
+(ert-deftest imenu--sort-by-position-list ()
+  (should (imenu--sort-by-position '("a" 2 nil) '("a" 3 nil)))
+  (should-not (imenu--sort-by-position '("a" 3 nil) '("a" 2 nil))))
+
 (provide 'imenu-tests)
 
 ;;; imenu-tests.el ends here
-- 
2.9.3


  reply	other threads:[~2017-04-12  7:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-12  4:43 bug#26457: 25.2; Cannot pass a function to imenu-generic-expression Damien Cassou
2017-04-12  7:32 ` Damien Cassou [this message]
2017-04-12  8:03   ` Nicolas Petton
2017-04-12  8:24   ` Nicolas Petton
2017-04-12  8:42     ` Damien Cassou
2017-04-12 12:42       ` Nicolas Petton
2017-04-13  9:45       ` Nicolas Petton
2017-04-13 10:35         ` Damien Cassou
2017-04-13 10:42           ` Eli Zaretskii
2017-04-13 11:09             ` Damien Cassou
2017-04-13  9:47 ` bug#26457: [Nicolas Petton] " Nicolas Petton

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=87bms26pzb.fsf@cassou.me \
    --to=damien@cassou.me \
    --cc=26457@debbugs.gnu.org \
    /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).