Sunday, July 19, 2009

Emacs - Menus and CLISP

Here's an example of creating menus in Emacs, and combining it to do something useful in CLISP:


;; Creating a new menu pane in the menu bar to the right of “Tools” menu
(define-key-after
global-map
[menu-bar mymenu]
(cons "MyMenu" (make-sparse-keymap "hoot hoot"))
'tools )

;; Creating a menu item, under the menu by the id [menu-bar mymenu]
(define-key
global-map
[menu-bar mymenu nl]
'("Next Line" . next-line))

;; creating another menu item
(define-key
global-map
[menu-bar mymenu pl]
'("Previous Line" . previous-line))


(defun lisp-eval-buffer ()
"Send the current region to the inferior Lisp process.
Prefix argument means switch to the Lisp buffer afterwards."
(interactive)
;;(interactive "r\nP")
(comint-send-region (inferior-lisp-proc)
(point-min) (point-max))
(comint-send-string (inferior-lisp-proc) "\n"))
;; (switch-to-lisp t))

(define-key
global-map
[menu-bar mymenu pl]
'("Eval buffer" . lisp-eval-buffer))


;; code to remove the whole menu panel
;; (global-unset-key [menu-bar mymenu])


(lisp-mode)
(split-window-vertically)
(other-window 1)
(setq inferior-lisp-program "clisp -K full")
(run-lisp inferior-lisp-program)
(other-window 1)

No comments: