Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

define-key OK; defiune-key-after won't evaluate

13 views
Skip to first unread message

RD.

unread,
Feb 19, 2006, 7:16:46 PM2/19/06
to help-gn...@gnu.org
I can define a menu button in the menu bar, placed to the left of the
File button, thus:

(define-key global-map [menu-bar rsave] '("Save" . save-buffer))

But I don't know how to use define-key-after. I get a Lisp error:

(define-key-after global-map [menu-bar rsave]
'("Save" . save-buffer) 'tools)
Debugger entered--Lisp error: (error "multi-event key specified in
`define-key-after'")

Is it obvious what's wrong?

[Aside: I posted a related question yesterday, but I couldn't see how
to post this follow-on question as a response to that question, i.e. in
the same thread.]

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


Kevin Rodgers

unread,
Feb 21, 2006, 11:18:41 AM2/21/06
to help-gn...@gnu.org
RD. wrote:
> I can define a menu button in the menu bar, placed to the left of the
> File button, thus:
>
> (define-key global-map [menu-bar rsave] '("Save" . save-buffer))
>
> But I don't know how to use define-key-after. I get a Lisp error:
>
> (define-key-after global-map [menu-bar rsave]
> '("Save" . save-buffer) 'tools)
> Debugger entered--Lisp error: (error "multi-event key specified in
> `define-key-after'")
>
> Is it obvious what's wrong?

,----[ C-h f define-key-after RET ]
| define-key-after is a compiled Lisp function in `subr'.
| (define-key-after KEYMAP KEY DEFINITION &optional AFTER)
|
| Add binding in KEYMAP for KEY => DEFINITION, right after AFTER's binding.
| This is like `define-key' except that the binding for KEY is placed
| just after the binding for the event AFTER, instead of at the beginning
| of the map. Note that AFTER must be an event type (like KEY), NOT a
command
| (like DEFINITION).
|
| If AFTER is t or omitted, the new binding goes at the end of the keymap.
|
| KEY must contain just one event type--that is to say, it must be a
| string or vector of length 1, but AFTER should be a single event
| type--a symbol or a character, not a sequence.
|
| Bindings are always added before any inherited map.
|
| The order of bindings in a keymap matters when it is used as a menu.
`----

Does this work?

(define-key-after (lookup-key global-map [menu-bar]) [rsave]


'("Save" . save-buffer) 'tools)

--
Kevin Rodgers

RD

unread,
Feb 24, 2006, 9:43:43 PM2/24/06
to

Yes. That does work.
Thanks very much.

(I'm figuring out how to get my ISP and Thunderbird to handle these
USENET groups. I hope this reply shows up in the right place.)

Bob

RD

unread,
Mar 3, 2006, 11:48:47 PM3/3/06
to
;I gathered some menu code to show an example of
;placing buttons in the menu bar.

;This code places buttons "Files" and "Save" in menu-bar.
;"Files" is a pulldown; "Save" is a button.

;"Files" has a button for opening a file ("ISP"),
;and buttons for setting the directory before displaying
;the file-open window ("Languages..." and "C:/").
;The "Languages..." button opens a submenu, which in
;turn contains a button for setting the directory before
;displaying the file-open window.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; "Files" button for pulldown menu in menu bar ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Keymap for pull-down menu
(defvar menu-x (make-sparse-keymap))

(define-key menu-x [b] ;Button for opening a file
`(menu-item "ISP"
(lambda () (interactive) (opf "C:/ISP/notebook.txt"))
)
)

(define-key menu-x [c] '(menu-item "Open:")) ;A label
(define-key menu-x [sep] '(menu-item "--")) ;A separator

(define-key menu-x [d] ;Button for opening directory
`(menu-item "C:/"
(lambda () (interactive) (op "C:/"))
)
)

;-----------
;Cascaded submenu in "Files" pulldown

(defvar submenu (make-sparse-keymap))
;"button" in menu-bar is actually a keymap
(define-key menu-x [e] (cons "Languages..." submenu))


(define-key submenu [g] ;Button in submenu
`(menu-item "FORTRAN"
(lambda () (interactive) (op "C:/courses/FORTRAN"))
)
)
;-----------


(define-key menu-x [h] '(menu-item "Directories:")) ;A label

;Define the "Files" menu-bar button.
(define-key-after
(lookup-key global-map [menu-bar]) ;keymap is "key" menu-bar
[ff] ;key name
(cons "Files" menu-x) ;label. "key" is menu-x
'buffer ;After buffer button
)

;Functions for the menu buttons that use find-file

(defun op (path) ;cd to path
(cd path)
(call-interactively 'find-file) ;open find-file window
)

(defun opf (file) ;find named file
(find-file file)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; "Save" button in menu bar ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define-key-after
(lookup-key global-map [menu-bar]) ;map is "key" menu-bar
[save1] ;key name
'(menu-item "Save" save-buffer) ;label, function
'ff ;after "Files" button
)

0 new messages