GNU bug report logs - #26421
25.1; Handling of prefix arg in menus

Previous Next

Package: emacs;

Reported by: Drew Adams <drew.adams <at> oracle.com>

Date: Sun, 9 Apr 2017 18:06:02 UTC

Severity: minor

Found in version 25.1

Full log


View this message in rfc822 format

From: Drew Adams <drew.adams <at> oracle.com>
To: 26421 <at> debbugs.gnu.org
Subject: bug#26421: 25.1; Handling of prefix arg in menus
Date: Sun, 9 Apr 2017 11:04:44 -0700 (PDT)
emacs -Q

Evaluate this code:

(defvar menu-bar-foo-menu (make-sparse-keymap "Foo"))
(define-key global-map [menu-bar foo] (cons "Foo" menu-bar-foo-menu))

(define-key menu-bar-foo-menu [toto]
  '(menu-item "Toto" forward-char
	      :visible
	      (progn
		(message "PP: %S"
			 (and current-prefix-arg
			      (prefix-numeric-value current-prefix-arg)))
		(and current-prefix-arg
		     (prefix-numeric-value current-prefix-arg)))))

(defvar bar-menu (make-sparse-keymap "Bar"))
(define-key menu-bar-foo-menu [bar] (cons "Bar" bar-menu))

(define-key bar-menu [foobar]
  '(menu-item "XXX" forward-char
	      :visible
	      (progn
		(message "PP: %S"
			 (and current-prefix-arg
			      (prefix-numeric-value current-prefix-arg)))
		(and current-prefix-arg
		     (prefix-numeric-value current-prefix-arg)))))

Open *Messages* in another frame, so you can see messages there.

In the original frame, access menu Foo and submenu Bar, using (1) no
prefix arg, (2) a prefix arg introduced using `C-u', and (3) a prefix
arg introduced in another way, such as `M-2'.

The actual prefix arg you give is not employed in the :visible code
(same thing for :enable).  Instead:

* For no prefix arg given, or for any prefix arg given other than by
  using explicit `C-u', the value used by :visible is nil.

* For a prefix arg given using explicit `C-u', the value used by
  :visible is 4.

That is, in the former case you see always "PP: nil" output, and for the
latter you see always "PP: 4" output.

This means that you cannot use the prefix arg in a menu-item test.
This should not be the case.  (This problem is not new.)


In GNU Emacs 25.1.1 (x86_64-w64-mingw32)
 of 2016-11-15
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --without-dbus --without-compress-install 'CFLAGS=-O2
 -static -g3''




This bug report was last modified 8 years and 67 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.