* Code example [Re: define-key OK; defiune-key-after won't evaluate]
[not found] <mailman.843.1140419511.2856.help-gnu-emacs@gnu.org>
@ 2006-03-04 4:48 ` RD
0 siblings, 0 replies; only message in thread
From: RD @ 2006-03-04 4:48 UTC (permalink / raw)
;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
)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-03-04 4:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.843.1140419511.2856.help-gnu-emacs@gnu.org>
2006-03-04 4:48 ` Code example [Re: define-key OK; defiune-key-after won't evaluate] RD
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).