unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#26457: 25.2; Cannot pass a function to imenu-generic-expression
@ 2017-04-12  4:43 Damien Cassou
  2017-04-12  7:32 ` Damien Cassou
  2017-04-13  9:47 ` bug#26457: [Nicolas Petton] " Nicolas Petton
  0 siblings, 2 replies; 11+ messages in thread
From: Damien Cassou @ 2017-04-12  4:43 UTC (permalink / raw)
  To: 26457

 
$ emacs -Q

M-:
(setq-local imenu-generic-expression `(("Foo" "^;; .*$" 0 ,(lambda 
(item pos) (message "%s" item)))))

M-x imenu
 
This results in

  sort: Wrong type argument: number-or-marker-p, (#<marker at 72 
  in *scratch*> (lambda (item pos) (message "%s" item)))
 
In GNU Emacs 25.2.3 (x86_64-unknown-linux-gnu, GTK+ Version 
3.22.9) 
 of 2017-03-09 built on x230
Repository revision: aceac954ed29c2653e2a0eb71b899be5c916edda
Windowing system distributor 'Fedora Project', version 
11.0.11903000
Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GCONF 
GSETTINGS NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT 
LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11
Important settings:
  value of $LANG: fr_FR.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

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

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





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

* bug#26457: 25.2; Cannot pass a function to imenu-generic-expression
  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
  2017-04-12  8:03   ` Nicolas Petton
  2017-04-12  8:24   ` Nicolas Petton
  2017-04-13  9:47 ` bug#26457: [Nicolas Petton] " Nicolas Petton
  1 sibling, 2 replies; 11+ messages in thread
From: Damien Cassou @ 2017-04-12  7:32 UTC (permalink / raw)
  To: 26457

[-- 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


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

* bug#26457: 25.2; Cannot pass a function to imenu-generic-expression
  2017-04-12  7:32 ` Damien Cassou
@ 2017-04-12  8:03   ` Nicolas Petton
  2017-04-12  8:24   ` Nicolas Petton
  1 sibling, 0 replies; 11+ messages in thread
From: Nicolas Petton @ 2017-04-12  8:03 UTC (permalink / raw)
  To: Damien Cassou; +Cc: 26457

tags 26457 patch
thanks





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

* bug#26457: 25.2; Cannot pass a function to imenu-generic-expression
  2017-04-12  7:32 ` Damien Cassou
  2017-04-12  8:03   ` Nicolas Petton
@ 2017-04-12  8:24   ` Nicolas Petton
  2017-04-12  8:42     ` Damien Cassou
  1 sibling, 1 reply; 11+ messages in thread
From: Nicolas Petton @ 2017-04-12  8:24 UTC (permalink / raw)
  To: Damien Cassou; +Cc: 26457

Damien Cassou <damien@cassou.me> writes:

>  (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
          ^^        
          We usually say "non-nil".

> +(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))))

Thanks for the regression test!

Cheers,
Nico





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

* bug#26457: 25.2; Cannot pass a function to imenu-generic-expression
  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
  0 siblings, 2 replies; 11+ messages in thread
From: Damien Cassou @ 2017-04-12  8:42 UTC (permalink / raw)
  To: Nicolas Petton; +Cc: 26457

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

Nicolas Petton <nicolas@petton.fr> writes:
>We usually say "non-nil".

 
done 

-- 
Damien Cassou
Företagsplatsen AB
Phone/Fax: +46 (0)8 774 63 00
Mobile: +33 (0)6 80 50 18 91
Address: Skeppsbron 26, 4tr, SE-111 30 Stockholm
Web: www.foretagsplatsen.se

[-- 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: 1913 bytes --]

From e4af13e6f9c811d91a4b4da648d4c4f79118e828 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..c1fd400 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 non-nil 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


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

* bug#26457: 25.2; Cannot pass a function to imenu-generic-expression
  2017-04-12  8:42     ` Damien Cassou
@ 2017-04-12 12:42       ` Nicolas Petton
  2017-04-13  9:45       ` Nicolas Petton
  1 sibling, 0 replies; 11+ messages in thread
From: Nicolas Petton @ 2017-04-12 12:42 UTC (permalink / raw)
  To: Damien Cassou; +Cc: 26457

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

Damien Cassou <damien@cassou.me> writes:

>>We usually say "non-nil".
>  
> done

Thanks, it looks good to me.
If nobody says anything I'll apply the patch to master tomorrow.

Cheers,
Nico

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* bug#26457: 25.2; Cannot pass a function to imenu-generic-expression
  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
  1 sibling, 1 reply; 11+ messages in thread
From: Nicolas Petton @ 2017-04-13  9:45 UTC (permalink / raw)
  To: Damien Cassou; +Cc: 26457

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


Damien Cassou <damien@cassou.me> writes:

> done

Thanks, I just applied the patch on master.

Cheers,
Nico

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* bug#26457: [Nicolas Petton] Re: bug#26457: 25.2; Cannot pass a function to imenu-generic-expression
  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
@ 2017-04-13  9:47 ` Nicolas Petton
  1 sibling, 0 replies; 11+ messages in thread
From: Nicolas Petton @ 2017-04-13  9:47 UTC (permalink / raw)
  To: 26457-done

[-- Attachment #1: Type: message/rfc822, Size: 1246 bytes --]

[-- Attachment #1.1.1: Type: text/plain, Size: 109 bytes --]


Damien Cassou <damien@cassou.me> writes:

> done

Thanks, I just applied the patch on master.

Cheers,
Nico

[-- Attachment #1.1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

[-- Attachment #2.1: Type: text/plain, Size: 0 bytes --]



[-- Attachment #2.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* bug#26457: 25.2; Cannot pass a function to imenu-generic-expression
  2017-04-13  9:45       ` Nicolas Petton
@ 2017-04-13 10:35         ` Damien Cassou
  2017-04-13 10:42           ` Eli Zaretskii
  0 siblings, 1 reply; 11+ messages in thread
From: Damien Cassou @ 2017-04-13 10:35 UTC (permalink / raw)
  To: Nicolas Petton; +Cc: 26457

Nicolas Petton <nicolas@petton.fr> writes:
> Thanks, I just applied the patch on master. 

thank you very much. Does it make sense to put it in 25 branch as 
well?  I'm building a mode which needs this bug fix. 

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

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





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

* bug#26457: 25.2; Cannot pass a function to imenu-generic-expression
  2017-04-13 10:35         ` Damien Cassou
@ 2017-04-13 10:42           ` Eli Zaretskii
  2017-04-13 11:09             ` Damien Cassou
  0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2017-04-13 10:42 UTC (permalink / raw)
  To: Damien Cassou; +Cc: nicolas, 26457

> From: Damien Cassou <damien@cassou.me>
> Date: Thu, 13 Apr 2017 12:35:31 +0200
> Cc: 26457@debbugs.gnu.org
> 
> Nicolas Petton <nicolas@petton.fr> writes:
> > Thanks, I just applied the patch on master. 
> 
> thank you very much. Does it make sense to put it in 25 branch as 
> well?

Not before Emacs 25.2 is released, no.  And maybe not afterwards as
well, depending on what, if anything we would like to release from
that branch after 25.2.





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

* bug#26457: 25.2; Cannot pass a function to imenu-generic-expression
  2017-04-13 10:42           ` Eli Zaretskii
@ 2017-04-13 11:09             ` Damien Cassou
  0 siblings, 0 replies; 11+ messages in thread
From: Damien Cassou @ 2017-04-13 11:09 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: nicolas, 26457

Eli Zaretskii <eliz@gnu.org> writes:
> Not before Emacs 25.2 is released, no.  And maybe not afterwards 
> as well, depending on what, if anything we would like to release 
> from that branch after 25.2. 

I understand. Thanks for the explanation.

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

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





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

end of thread, other threads:[~2017-04-13 11:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).