home *** CD-ROM | disk | FTP | other *** search
-
- Help!
-
- Okay. I give up! I am trying to set up a submenu which lists the files
- in a given directory which can be inserted at point when the file name is
- selected from the menu. The following code kind-of works, but the
- templates menu is updated only _after_ I leave and reenter the buffer.
- I have tried 'set-menubar-dirty-flag; that doesn't help.
-
- PS: I am definitely not an elisp hacker; constructive comments on how to
- improve the following code are welcome!
-
- PPS: *Please* email replies to chan@jpmorgan.com as well as posting
- because our netnews server is currently hosed. Thanks!
-
- --------------------------------------------------
- ;; template-files-menu.el - Include files menu.
- ;;
- ;; Mostly snarfed from menubar.el
- ;; Last modified: 5/28/1993 M A Chan.
-
- (defvar template-files-dir (concat (getenv "TEMPLATES") "/C++/")
- "*Directory in which C++ template files are located.
- Must end with a slash!")
-
- (defvar template-files-menu
- '(["Reread template dir" build-template-menu t]))
-
- (defvar template-menu-function 'insert-file
- "*Function to insert TEMPLATE file into current buffer.
- 'insert-file is a good choice.")
-
- (defvar template-menu-path (list "Language" "Templates")
- "*Path list to templates submenu.")
-
- (defsubst build-template-menu-internal (files)
- (mapcar
- (function (lambda (file)
- (vector file
- (list template-menu-function
- (concat template-files-dir file))
- t)))
- files))
-
- (defun build-template-menu ()
- "This function changes the contents of the \"Templates\" menu to correspond
- to the files in template-files-dir."
- (interactive)
- (let ((template-menu (car (find-menu-item current-menubar template-menu-path)))
- files)
- (if (not template-menu)
- (error "template menu \"%s\" not found" template-menu-path)
- (setq files (directory-files template-files-dir nil nil t t))
- (setq files (build-template-menu-internal files))
- (setq files (nconc (delq nil files)))
- (setq files (nconc (delq nil files)
- '("----" ["Reread template dir" build-template-menu t])))
- ;; Update menu iff changed.
- (if (equal files (cdr template-menu))
- (message "no need to update template menu")
- (setq template-files-menu files)
- (setcdr template-menu files)
- (set-menubar current-menubar)))))
-
- (defun set-template-menu-hook ()
- (let ((template-menu (car (find-menu-item current-menubar template-menu-path))))
- (if template-menu
- (setcdr template-menu template-files-menu)
- (error "template menu \"%s\" not found" template-menu-path))))
-
- (add-hook 'c++-mode-hook 'set-template-menu-hook t)
- --------------------------------------------------
-
- -Milo
- --
- Milo Chan, Vice President J.P. Morgan Securities, Inc.
- email: chan@jpmorgan.com ...or... chan@fractl.tn.cornell.edu
- phone: 212.648.4483 ...or... 212.648.4486 (sec'y)
-
-